Dduvall has uploaded a new change for review.

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

Change subject: Varnish config for thumbor
......................................................................

Varnish config for thumbor

Alternative to I6feefea0d130d6495a4c3b08199fdc20d1662bd1 that uses
`varnish::config`.

Change-Id: I530d9f1229e2d687e5837a983d398d227aef2ab5
---
M puppet/modules/role/manifests/thumbor.pp
A puppet/modules/thumbor/files/varnish.vcl
2 files changed, 40 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/03/239503/1

diff --git a/puppet/modules/role/manifests/thumbor.pp 
b/puppet/modules/role/manifests/thumbor.pp
index 27d3e9c..1e31240 100644
--- a/puppet/modules/role/manifests/thumbor.pp
+++ b/puppet/modules/role/manifests/thumbor.pp
@@ -16,5 +16,16 @@
         site    => $::mediawiki::wiki_name,
         content => template('role/thumbor/apache2.conf.erb'),
     }
+
+    if defined(Class['role::varnish']) {
+        varnish::backend { 'thumbor':
+            host => '127.0.0.1',
+            port => '8888',
+        }
+
+        varnish::config { 'thumbor':
+            source => 'puppet:///modules/thumbor/varnish.vcl',
+        }
+    }
 }
 
diff --git a/puppet/modules/thumbor/files/varnish.vcl 
b/puppet/modules/thumbor/files/varnish.vcl
new file mode 100644
index 0000000..a0db65e
--- /dev/null
+++ b/puppet/modules/thumbor/files/varnish.vcl
@@ -0,0 +1,29 @@
+# vcl_recv is called whenever a request is received
+sub vcl_recv {
+    # Pass any requests with the "If-None-Match" header directly.
+    if (req.http.If-None-Match && !req.url ~ "^/images/thumb/.*\.(jpg|png)") {
+        return(pass);
+    }
+}
+
+# Called if the cache does not have a copy of the page.
+sub vcl_miss {
+    # 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");
+    }
+}
+
+sub vcl_deliver {
+    # 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;
+    }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I530d9f1229e2d687e5837a983d398d227aef2ab5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: master
Gerrit-Owner: Dduvall <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to