Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic varnish 2 #759

Merged
merged 13 commits into from
Jan 3, 2019
11 changes: 10 additions & 1 deletion images/varnish-drupal/drupal.vcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
vcl 4.0;

import std;
import dynamic;

# set backend default
backend default {
Expand All @@ -19,14 +20,22 @@ acl purge {
"192.168.0.0"/16;
}

sub vcl_init {
new www_dir = dynamic.director(
port = "${VARNISH_BACKEND_PORT:-8080}",
first_byte_timeout = 90s,
between_bytes_timeout = 90s,
ttl = 60s);
}

# This configuration is optimized for Drupal hosting:
# Respond to incoming requests.
sub vcl_recv {
if (req.url ~ "^/varnish_status$") {
return (synth(200,"OK"));
}
# set the backend, which should be used:
set req.backend_hint = default;
set req.backend_hint = www_dir.backend("${VARNISH_BACKEND_HOST:-nginx}");

# Always set the forward ip.
if (req.restarts == 0) {
Expand Down
20 changes: 19 additions & 1 deletion images/varnish/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
ARG IMAGE_REPO
FROM ${IMAGE_REPO:-lagoon}/commons as commons
FROM alpine:3.7


FROM alpine:3.7 as vmod
ENV LIBVMOD_DYNAMIC_VERSION=5.2
ENV LIBVMOD_BODYACCESS_VERSION=5.0
RUN apk --no-cache add varnish varnish-dev automake autoconf libtool python py-docutils make

RUN cd /tmp && wget https://github.com/nigoroll/libvmod-dynamic/archive/${LIBVMOD_DYNAMIC_VERSION}.zip && \
unzip ${LIBVMOD_DYNAMIC_VERSION}.zip && cd libvmod-dynamic-${LIBVMOD_DYNAMIC_VERSION} && \
./autogen.sh && ./configure && make && make install

RUN cd /tmp && wget https://github.com/aondio/libvmod-bodyaccess/archive/${LIBVMOD_BODYACCESS_VERSION}.zip && \
unzip ${LIBVMOD_BODYACCESS_VERSION}.zip && cd libvmod-bodyaccess-${LIBVMOD_BODYACCESS_VERSION} && \
./autogen.sh && ./configure && make && make install

FROM alpine:3.7
LABEL maintainer="amazee.io"
ENV LAGOON=varnish

Expand All @@ -21,6 +35,10 @@ ENV TMPDIR=/tmp \

RUN apk --no-cache add varnish

# Add varnish mod after the varnish package creates the directory.
COPY --from=vmod /usr/lib/varnish/vmods/libvmod_dynamic.* /usr/lib/varnish/vmods/
COPY --from=vmod /usr/lib/varnish/vmods/libvmod_bodyaccess.* /usr/lib/varnish/vmods/

RUN echo "${VARNISH_SECRET:-lagoon_default_secret}" >> /etc/varnish/secret

COPY default.vcl /etc/varnish/default.vcl
Expand Down
11 changes: 10 additions & 1 deletion images/varnish/default.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
vcl 4.0;

import std;
import dynamic;

# set backend default
backend default {
Expand All @@ -20,14 +21,22 @@ backend default {
.between_bytes_timeout = 10m;
}

sub vcl_init {
new www_dir = dynamic.director(
port = "${VARNISH_BACKEND_PORT:-8080}",
first_byte_timeout = 90s,
between_bytes_timeout = 90s,
ttl = 60s);
}

sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.

# set the backend, which should be used:
set req.backend_hint = default;
set req.backend_hint = www_dir.backend("${VARNISH_BACKEND_HOST:-nginx}");

# Needed for Readyness and Liveness checks - do not remove
if (req.url ~ "^/varnish_status$") {
Expand Down