Gilles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/237278

Change subject: Hook thumbor into varnish role when thumbor role is enabled
......................................................................

Hook thumbor into varnish role when thumbor role is enabled

Bug: T111726
Change-Id: I6feefea0d130d6495a4c3b08199fdc20d1662bd1
---
M puppet/modules/varnish/manifests/init.pp
R puppet/modules/varnish/templates/default.vcl.erb
2 files changed, 36 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/78/237278/1

diff --git a/puppet/modules/varnish/manifests/init.pp 
b/puppet/modules/varnish/manifests/init.pp
index e29a629..c5e255d 100644
--- a/puppet/modules/varnish/manifests/init.pp
+++ b/puppet/modules/varnish/manifests/init.pp
@@ -7,8 +7,10 @@
         ensure => 'present'
     }
 
+    $thumbor = defined( Class["role::thumbor"] )
+
     file { '/etc/varnish/default.vcl':
-        source  => 'puppet:///modules/varnish/default.vcl',
+        content => template('varnish/default.vcl.erb'),
         mode    => '0644',
         require => Package['varnish'],
     }
diff --git a/puppet/modules/varnish/files/default.vcl 
b/puppet/modules/varnish/templates/default.vcl.erb
similarity index 72%
rename from puppet/modules/varnish/files/default.vcl
rename to puppet/modules/varnish/templates/default.vcl.erb
index b6f6304..0ba42a6 100755
--- a/puppet/modules/varnish/files/default.vcl
+++ b/puppet/modules/varnish/templates/default.vcl.erb
@@ -4,6 +4,11 @@
     .port = "8080";
 }
 
+backend thumbor {
+    .host = "127.0.0.1";
+    .port = "8888";
+}
+
 # access control list for "purge": open to only localhost and other local nodes
 acl purge {
     "127.0.0.1";
@@ -16,6 +21,12 @@
     set req.grace = 120s;
     set req.http.X-Forwarded-For = client.ip;
     set req.backend = default;
+
+<% if @thumbor -%>
+    if (req.url ~ "^/images/thumb/.*\.(jpg|png)") {
+        set req.backend = thumbor;
+    }
+<% end -%>
 
     # This uses the ACL action called "purge". Basically if a request to
     # PURGE the cache comes from anywhere other than localhost, ignore it.
@@ -51,7 +62,7 @@
     }
 
     # Pass any requests with the "If-None-Match" header directly.
-    if (req.http.If-None-Match) {
+    if (req.http.If-None-Match<% if @thumbor -%> && !req.url ~ 
"^/images/thumb/.*\.(jpg|png)"<% end -%>) {
         return(pass);
     }
 
@@ -109,6 +120,19 @@
     if (req.request == "PURGE") {
         error 200 "Not in cache";
     }
+
+<% if @thumbor -%>
+    # qlow jpg thumbs
+    if (req.url ~ "^/images/thumb/(.*)/qlow-(\d+)px-.*\.jpg") {
+        set bereq.url = "/unsafe/" + regsub(req.url, 
"^/images/thumb/(.*)/qlow-(\d+)px-.*\.jpg", "\2") + 
"x/filters:quality(40):sharpen(0.6,0.01,false)/http://127.0.0.1:8080/images/"; + 
regsub(req.url, "^/images/thumb/(.*)/qlow-(\d+)px-.*\.jpg", "\1");
+    # regular jpg thumbs
+    } else if (req.url ~ "^/images/thumb/(.*)/(\d+)px-.*\.jpg") {
+        set bereq.url = "/unsafe/" + regsub(req.url, 
"^/images/thumb/(.*)/(\d+)px-.*\.jpg", "\2") + 
"x/filters:quality(87):sharpen(0.6,0.01,false)/http://127.0.0.1:8080/images/"; + 
regsub(req.url, "^/images/thumb/(.*)/(\d+)px-.*\.jpg", "\1");
+    # png thumbs
+    } else if (req.url ~ "^/images/thumb/(.*)/(\d+)px-.*\.png") {
+        set bereq.url = "/unsafe/" + regsub(req.url, 
"^/images/thumb/(.*)/(\d+)px-.*\.png", "\2") + 
"x/http://127.0.0.1:8080/images/"; + regsub(req.url, 
"^/images/thumb/(.*)/(\d+)px-.*\.png", "\1");
+    }
+<% end -%>
 }
 
 sub vcl_deliver {
@@ -117,6 +141,14 @@
     } else {
         set resp.http.X-Cache = "miss (0)";
     }
+
+<% if @thumbor -%>
+    # Thumbor doesn't even fine-grained config for the headers it returns
+    if (req.url ~ "^/images/thumb/.*\.(jpg|png)") {
+        unset resp.http.Cache-Control;
+        unset resp.http.Expires;
+    }
+<% end -%>
 }
 
 # Called after a document has been successfully retrieved from the backend.

-- 
To view, visit https://gerrit.wikimedia.org/r/237278
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6feefea0d130d6495a4c3b08199fdc20d1662bd1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Gilles <gdu...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to