Skip to content

Commit

Permalink
feat: introduce SHOPWARE_ALLOWED_PURGER_IP
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Sep 10, 2024
1 parent a503601 commit 259ec5e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ RUN set -e; \
apk upgrade --no-cache; \
apk add --no-cache $VMOD_DEPS; \
\
# install one, possibly multiple vmods
# install one, possibly multiple vmods
install-vmod https://github.com/varnish/varnish-modules/releases/download/0.24.0/varnish-modules-0.24.0.tar.gz; \
\
# clean up
# clean up
apk del --no-network $VMOD_DEPS
USER varnish
ENV SHOPWARE_BACKEND_HOST=localhost \
SHOPWARE_BACKEND_PORT=8000
SHOPWARE_BACKEND_PORT=8000 \
SHOPWARE_ALLOWED_PURGER_IP='"127.0.0.1"'

COPY --chown=1000 rootfs /
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ docker run \
- `SHOPWARE_BACKEND_HOST` - The host of the Shopware backend. Default: `localhost`
- `SHOPWARE_BACKEND_PORT` - The port of the Shopware backend. Default: `8000`
- `SHOPWARE_SOFT_PURGE` - If set to `1`, the soft purge feature is enabled. Default: `0`
- `SHOPWARE_ALLOWED_PURGER_IP` - The IP address of the allowed purger. Default: `"127.0.0.1"`

The `SHOPWARE_ALLOWED_PURGER_IP` can be a single IP like `"172.17.0.1"` or a subnet like `"172.17.0.0"/24`. Take care that the ip address inside the environment variable needs to be double quoted.

## Further information

Expand Down
1 change: 1 addition & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
build: .
environment:
SHOPWARE_BACKEND_HOST: host.docker.internal
SHOPWARE_ALLOWED_PURGER_IP: '"172.17.0.0"/24'
ports:
- "80:80"
develop:
Expand Down
3 changes: 1 addition & 2 deletions rootfs/etc/varnish/default.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ acl purgers {
"127.0.0.1";
"localhost";
"::1";
"172.17.0.1";
__SHOPWARE_ALLOWED_PURGER_IP__;
}

sub vcl_recv {
Expand Down Expand Up @@ -133,7 +133,6 @@ sub vcl_backend_fetch {
sub vcl_backend_response {
# Serve stale content for three days after object expiration
# Perform asynchronous revalidation while stale content is served
set beresp.grace = 3d;
unset beresp.http.X-Powered-By;
Expand Down
1 change: 1 addition & 0 deletions rootfs/usr/local/bin/docker-varnish-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -eo pipefail

sed -i "s|__SHOPWARE_BACKEND_HOST__|${SHOPWARE_BACKEND_HOST}|g" /etc/varnish/default.vcl
sed -i "s|__SHOPWARE_BACKEND_PORT__|${SHOPWARE_BACKEND_PORT}|g" /etc/varnish/default.vcl
sed -i 's|__SHOPWARE_ALLOWED_PURGER_IP__|'"${SHOPWARE_ALLOWED_PURGER_IP}"'|g' /etc/varnish/default.vcl

if [[ "${SHOPWARE_SOFT_PURGE}" ]]; then
sed -i "s|xkey.purge|xkey.softpurge|g" /etc/varnish/default.vcl
Expand Down

0 comments on commit 259ec5e

Please sign in to comment.