From a08c64b07019c319b7a92b81c40f7a13df4ade87 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Thu, 8 Oct 2026 23:47:57 +0200 Subject: [PATCH] IBX-12173: Added Varnish 9 Docker build (#64) For more details see https://ibexa.atlassian.net/browse/IBX-12173 and https://github.com/ibexa/docker/pull/64 Key changes: * Added `Dockerfile-varnish9`, building Varnish 9.0 with varnish-modules 0.28.0 and the `varnish9.vcl` shipped by `ibexa/http-cache` * Pinned `varnish-dev` to the installed Varnish runtime version to avoid build-time version mismatches * Ran the Varnish container as the non-root `varnish` user * Added the `varnish9.yml` Docker Compose override wiring the app to the Varnish 9 service --- docker/Dockerfile-varnish9 | 24 ++++++++++++++++++++++ docker/varnish9.yml | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 docker/Dockerfile-varnish9 create mode 100644 docker/varnish9.yml diff --git a/docker/Dockerfile-varnish9 b/docker/Dockerfile-varnish9 new file mode 100644 index 0000000..834f070 --- /dev/null +++ b/docker/Dockerfile-varnish9 @@ -0,0 +1,24 @@ +FROM varnish:9.0 + +SHELL ["/bin/bash", "-c"] + +# set the user to root, and install build dependencies +USER root +RUN set -e && \ + read -ra vmod_deps <<< "$VMOD_DEPS" && \ + varnish_version=$(dpkg-query -W -f='${Version}' varnish) && \ + apt-get update && \ + apt-get -y --no-install-recommends install "${vmod_deps[@]/varnish-dev/varnish-dev=$varnish_version}" && \ + install-vmod https://github.com/varnish/varnish-modules/releases/download/0.28.0/varnish-modules-0.28.0.tar.gz && \ + rm -rf /var/lib/apt/lists/* + +COPY vendor/ibexa/http-cache/docs/varnish/vcl/varnish9.vcl /etc/varnish/default.vcl +COPY doc/docker/entrypoint/varnish/parameters.vcl /etc/varnish/parameters.vcl +COPY doc/docker/entrypoint/varnish/entrypoint.sh /entrypoint.sh + +# entrypoint.sh writes into /etc/varnish at runtime (parameters.vcl.template), so hand the +# directory to the non-root "varnish" user the base image already runs as by default +RUN chown -R varnish:varnish /etc/varnish +USER varnish + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/varnish9.yml b/docker/varnish9.yml new file mode 100644 index 0000000..42016bb --- /dev/null +++ b/docker/varnish9.yml @@ -0,0 +1,42 @@ + +## WARNING! +# This service is currently work in progress, is not tested by CI, and thus not guaranteed to work. +# You are however more then welcome to try it out and help make it stable. + +services: + app: + environment: + - APP_HTTP_CACHE=0 + # Never do this in production if the app container is accesible for the public as well + # See https://developers.ibexa.co/security-advisories/ezsa-2020-002-unauthorised-cache-purge-with-misconfigured-fastly for more details about how it could be abused + - TRUSTED_PROXIES=REMOTE_ADDR + - HTTPCACHE_PURGE_SERVER=http://varnish + - HTTPCACHE_PURGE_TYPE=varnish + + varnish: + build: + context: ../../ + dockerfile: doc/docker/Dockerfile-varnish9 + ports: + - "8081:80" + environment: + - VARNISH_MALLOC_SIZE=256m + depends_on: + - web + - app + networks: + - frontend + - backend +# command: ["--acl-add", "app", "--debug-acl-add", "app"] + stdin_open: true + tty: true + +## DEBUG?? +# In need of debugging all request going to Varnish, use varnishlog, example: +# docker compose exec varnish varnishlog -c -i ReqURL,ReqMethod -I ReqHeader:xkey +# Or more relevant only PURGE's with all info: +# docker compose exec varnish varnishlog -g request -q "ReqMethod eq 'PURGE'" +# +# But before doing that check that http and not local purge client is set: +# docker compose exec app bin/console --env=dev debug:container ibexa.http_cache.purge_client_internal +#