From 15c217537d960a2a57036d7c604c3f18b54b0b4f Mon Sep 17 00:00:00 2001 From: Hugo Gomes Date: Thu, 13 Apr 2023 18:27:59 +0100 Subject: [PATCH 1/4] feat: adding proxy cached image --- proxy_cached/Dockerfile | 62 +++++++++++++++++++++++++++++++ proxy_cached/default.conf | 12 ++++++ proxy_cached/docker-entrypoint.sh | 14 +++++++ 3 files changed, 88 insertions(+) create mode 100644 proxy_cached/Dockerfile create mode 100644 proxy_cached/default.conf create mode 100755 proxy_cached/docker-entrypoint.sh diff --git a/proxy_cached/Dockerfile b/proxy_cached/Dockerfile new file mode 100644 index 0000000..444304b --- /dev/null +++ b/proxy_cached/Dockerfile @@ -0,0 +1,62 @@ +FROM debian:stable-slim + +LABEL version="1.0" +LABEL maintainer="Platforme " + +ARG VARNISH_MODULES_VERSION=0.17.1 +ARG VARNISH_MODULES_SHA512SUM=c05c3e9d560b319b1eb1ca03bb3626989ed92c7d8d8eeb3f895b0a8f69639e9497403c1797a7936c4a7819c08f36e9cbf32b7e60661bfd584aeed174822a6565 +ARG VARNISH_MODULES_QUERYFILTER_VERSION=1.0.1 +ARG VARNISH_MODULES_QUERYFILTER_SHA512SUM=6c3178d656dfffa7f515afc5d01e00d86b4149e9e61e8024b524e04a427cf3875a918f03999a9bbf4e762ec684d8d193aa03b8d36c1291a825834905802ecc32 +ARG TOOLBOX_COMMIT=96bab07cf58b6e04824ffec608199f1780ff0d04 + +ENV VARNISH_HTTP_PORT 80 +ENV VARNISH_SIZE 1G + +RUN apt-get -y update && apt-get -y upgrade &&\ + apt-get -y --no-install-recommends install gettext nginx varnish varnish-modules &&\ + apt-get -y clean && rm -rf /var/lib/apt/lists/* + +RUN set -e; \ + apt-get -y update; apt-get -y install \ + automake \ + build-essential \ + ca-certificates \ + curl \ + git \ + libgetdns10 \ + libgetdns-dev \ + libtool \ + libvarnishapi-dev \ + pkg-config \ + python3-docutils; \ + export DEBIAN_FRONTEND=noninteractive; \ + export DEBCONF_NONINTERACTIVE_SEEN=true; \ + \ + cd /tmp; \ + git clone https://github.com/varnish/toolbox.git; cd toolbox; \ + git checkout $TOOLBOX_COMMIT; \ + cp install-vmod/install-vmod /usr/local/bin/; \ + \ + install-vmod https://github.com/varnish/varnish-modules/archive/refs/tags/varnish-modules-$VARNISH_MODULES_VERSION.tar.gz $VARNISH_MODULES_SHA512SUM; \ + \ + chown varnish /var/lib/varnish; \ + apt-get -y purge --auto-remove \ + automake \ + build-essential \ + ca-certificates \ + curl \ + git \ + libgetdns-dev \ + libtool \ + libvarnishapi-dev \ + pkg-config \ + python3-docutils; \ + apt-get -y clean; \ + rm -rf /var/lib/apt/lists/* /tmp/toolbox /usr/lib/varnish/vmods/libvmod_*.la; + +COPY ./docker-entrypoint.sh / +COPY ./default / + +ENTRYPOINT ["./docker-entrypoint.sh"] + +CMD [] diff --git a/proxy_cached/default.conf b/proxy_cached/default.conf new file mode 100644 index 0000000..2626be1 --- /dev/null +++ b/proxy_cached/default.conf @@ -0,0 +1,12 @@ +server { + listen 8080 default_server; + server_name $SERVER_NAME; + + location / { + proxy_pass $PROXY_PROTO$PROXY_HOST; + proxy_set_header Host $PROXY_HOST; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/proxy_cached/docker-entrypoint.sh b/proxy_cached/docker-entrypoint.sh new file mode 100755 index 0000000..c535654 --- /dev/null +++ b/proxy_cached/docker-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then + set -- varnishd \ + -F \ + -f /etc/varnish/default.vcl \ + -a http=:${VARNISH_HTTP_PORT:-80},HTTP \ + -p feature=+http2 \ + -s malloc,$VARNISH_SIZE \ + "$@" +fi + +exec "$@" From 2f6df742ace7e54457804ec25af65213a2a4e8fb Mon Sep 17 00:00:00 2001 From: Hugo Gomes Date: Mon, 17 Apr 2023 18:37:00 +0100 Subject: [PATCH 2/4] feat: review dockerfile --- proxy_cached/Dockerfile | 24 +++++++++++++++++------- proxy_cached/default.conf | 6 +++--- proxy_cached/docker-entrypoint.sh | 13 +++++++++---- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/proxy_cached/Dockerfile b/proxy_cached/Dockerfile index 444304b..3d32633 100644 --- a/proxy_cached/Dockerfile +++ b/proxy_cached/Dockerfile @@ -1,27 +1,38 @@ -FROM debian:stable-slim +FROM debian:bullseye-slim LABEL version="1.0" LABEL maintainer="Platforme " +EXPOSE 80 +EXPOSE 443 + +ARG SERVER_NAME=localhost +ARG PROXY_PROTO=https:// +ARG PROXY_HOST=app.platforme.com ARG VARNISH_MODULES_VERSION=0.17.1 ARG VARNISH_MODULES_SHA512SUM=c05c3e9d560b319b1eb1ca03bb3626989ed92c7d8d8eeb3f895b0a8f69639e9497403c1797a7936c4a7819c08f36e9cbf32b7e60661bfd584aeed174822a6565 ARG VARNISH_MODULES_QUERYFILTER_VERSION=1.0.1 ARG VARNISH_MODULES_QUERYFILTER_SHA512SUM=6c3178d656dfffa7f515afc5d01e00d86b4149e9e61e8024b524e04a427cf3875a918f03999a9bbf4e762ec684d8d193aa03b8d36c1291a825834905802ecc32 ARG TOOLBOX_COMMIT=96bab07cf58b6e04824ffec608199f1780ff0d04 -ENV VARNISH_HTTP_PORT 80 ENV VARNISH_SIZE 1G RUN apt-get -y update && apt-get -y upgrade &&\ apt-get -y --no-install-recommends install gettext nginx varnish varnish-modules &&\ apt-get -y clean && rm -rf /var/lib/apt/lists/* +COPY docker-entrypoint.sh / +COPY default.conf /etc/nginx/default.conf + RUN set -e; \ + export DEBIAN_FRONTEND=noninteractive; \ + export DEBCONF_NONINTERACTIVE_SEEN=true; \ apt-get -y update; apt-get -y install \ automake \ build-essential \ ca-certificates \ curl \ + gettext \ git \ libgetdns10 \ libgetdns-dev \ @@ -29,8 +40,8 @@ RUN set -e; \ libvarnishapi-dev \ pkg-config \ python3-docutils; \ - export DEBIAN_FRONTEND=noninteractive; \ - export DEBCONF_NONINTERACTIVE_SEEN=true; \ + \ + sed -i '/sites-enabled.*$/i \\tinclude \/etc\/nginx\/default\.conf;' /etc/nginx/nginx.conf; \ \ cd /tmp; \ git clone https://github.com/varnish/toolbox.git; cd toolbox; \ @@ -45,7 +56,9 @@ RUN set -e; \ build-essential \ ca-certificates \ curl \ + gettext \ git \ + libgetdns10 \ libgetdns-dev \ libtool \ libvarnishapi-dev \ @@ -54,9 +67,6 @@ RUN set -e; \ apt-get -y clean; \ rm -rf /var/lib/apt/lists/* /tmp/toolbox /usr/lib/varnish/vmods/libvmod_*.la; -COPY ./docker-entrypoint.sh / -COPY ./default / - ENTRYPOINT ["./docker-entrypoint.sh"] CMD [] diff --git a/proxy_cached/default.conf b/proxy_cached/default.conf index 2626be1..df0a345 100644 --- a/proxy_cached/default.conf +++ b/proxy_cached/default.conf @@ -1,10 +1,10 @@ server { listen 8080 default_server; - server_name $SERVER_NAME; + server_name ${SERVER_NAME}; location / { - proxy_pass $PROXY_PROTO$PROXY_HOST; - proxy_set_header Host $PROXY_HOST; + proxy_pass ${PROXY_PROTO}${PROXY_HOST}; + proxy_set_header Host ${PROXY_HOST}; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/proxy_cached/docker-entrypoint.sh b/proxy_cached/docker-entrypoint.sh index c535654..6b84095 100755 --- a/proxy_cached/docker-entrypoint.sh +++ b/proxy_cached/docker-entrypoint.sh @@ -1,13 +1,18 @@ -#!/bin/sh +#!/bin/bash + set -e +envsubst < /etc/nginx/default.conf > /etc/nginx/default.conf; + if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then - set -- varnishd \ + set -- \ + nginx /etc/nginx.conf; \ + varnishd \ -F \ -f /etc/varnish/default.vcl \ - -a http=:${VARNISH_HTTP_PORT:-80},HTTP \ + -a http=:80,HTTP \ -p feature=+http2 \ - -s malloc,$VARNISH_SIZE \ + -s malloc,$VARNISH_SIZE; \ "$@" fi From 17c17e76f1829a3169acc35913e29e16c1cf3536 Mon Sep 17 00:00:00 2001 From: Hugo Gomes Date: Wed, 19 Apr 2023 17:05:37 +0100 Subject: [PATCH 3/4] feat: add nginx setup --- proxy_cached/Dockerfile | 15 ++++++------ proxy_cached/docker-entrypoint.sh | 9 ++++--- .../{default.conf => nginx.default.template} | 24 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) rename proxy_cached/{default.conf => nginx.default.template} (63%) diff --git a/proxy_cached/Dockerfile b/proxy_cached/Dockerfile index 3d32633..7960741 100644 --- a/proxy_cached/Dockerfile +++ b/proxy_cached/Dockerfile @@ -6,23 +6,23 @@ LABEL maintainer="Platforme " EXPOSE 80 EXPOSE 443 -ARG SERVER_NAME=localhost -ARG PROXY_PROTO=https:// -ARG PROXY_HOST=app.platforme.com ARG VARNISH_MODULES_VERSION=0.17.1 ARG VARNISH_MODULES_SHA512SUM=c05c3e9d560b319b1eb1ca03bb3626989ed92c7d8d8eeb3f895b0a8f69639e9497403c1797a7936c4a7819c08f36e9cbf32b7e60661bfd584aeed174822a6565 ARG VARNISH_MODULES_QUERYFILTER_VERSION=1.0.1 ARG VARNISH_MODULES_QUERYFILTER_SHA512SUM=6c3178d656dfffa7f515afc5d01e00d86b4149e9e61e8024b524e04a427cf3875a918f03999a9bbf4e762ec684d8d193aa03b8d36c1291a825834905802ecc32 ARG TOOLBOX_COMMIT=96bab07cf58b6e04824ffec608199f1780ff0d04 -ENV VARNISH_SIZE 1G +ENV SERVER_NAME=localhost +ENV PROXY_PROTO=https:// +ENV PROXY_HOST=app.platforme.com +ENV VARNISH_SIZE=1G RUN apt-get -y update && apt-get -y upgrade &&\ apt-get -y --no-install-recommends install gettext nginx varnish varnish-modules &&\ apt-get -y clean && rm -rf /var/lib/apt/lists/* COPY docker-entrypoint.sh / -COPY default.conf /etc/nginx/default.conf +COPY nginx.default.template / RUN set -e; \ export DEBIAN_FRONTEND=noninteractive; \ @@ -32,7 +32,6 @@ RUN set -e; \ build-essential \ ca-certificates \ curl \ - gettext \ git \ libgetdns10 \ libgetdns-dev \ @@ -41,7 +40,10 @@ RUN set -e; \ pkg-config \ python3-docutils; \ \ + rm /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default; \ + touch /etc/nginx/default.conf; \ sed -i '/sites-enabled.*$/i \\tinclude \/etc\/nginx\/default\.conf;' /etc/nginx/nginx.conf; \ + nginx -t -c /etc/nginx/nginx.conf; \ \ cd /tmp; \ git clone https://github.com/varnish/toolbox.git; cd toolbox; \ @@ -56,7 +58,6 @@ RUN set -e; \ build-essential \ ca-certificates \ curl \ - gettext \ git \ libgetdns10 \ libgetdns-dev \ diff --git a/proxy_cached/docker-entrypoint.sh b/proxy_cached/docker-entrypoint.sh index 6b84095..cc0a1bf 100755 --- a/proxy_cached/docker-entrypoint.sh +++ b/proxy_cached/docker-entrypoint.sh @@ -2,12 +2,11 @@ set -e -envsubst < /etc/nginx/default.conf > /etc/nginx/default.conf; +envsubst '$SERVER_NAME$PROXY_PROTO$PROXY_HOST' < /nginx.default.template > /etc/nginx/default.conf; -if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then - set -- \ - nginx /etc/nginx.conf; \ - varnishd \ +if [ "$#" -eq 0 ] ; then + nginx -c /etc/nginx/nginx.conf; + set -- varnishd \ -F \ -f /etc/varnish/default.vcl \ -a http=:80,HTTP \ diff --git a/proxy_cached/default.conf b/proxy_cached/nginx.default.template similarity index 63% rename from proxy_cached/default.conf rename to proxy_cached/nginx.default.template index df0a345..49384f6 100644 --- a/proxy_cached/default.conf +++ b/proxy_cached/nginx.default.template @@ -1,12 +1,12 @@ -server { - listen 8080 default_server; - server_name ${SERVER_NAME}; - - location / { - proxy_pass ${PROXY_PROTO}${PROXY_HOST}; - proxy_set_header Host ${PROXY_HOST}; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } -} +server { + listen 8080 default_server; + server_name $SERVER_NAME; + + location / { + proxy_pass $PROXY_PROTO$PROXY_HOST; + proxy_set_header Host $PROXY_HOST; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} From faff6c21ee17837c3318d2fd6a4b80433d819ab8 Mon Sep 17 00:00:00 2001 From: Hugo Gomes Date: Wed, 19 Apr 2023 17:05:51 +0100 Subject: [PATCH 4/4] feat: add varnish default vcl --- proxy_cached/Dockerfile | 1 + proxy_cached/docker-entrypoint.sh | 1 + proxy_cached/varnish.default.template | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 proxy_cached/varnish.default.template diff --git a/proxy_cached/Dockerfile b/proxy_cached/Dockerfile index 7960741..4431658 100644 --- a/proxy_cached/Dockerfile +++ b/proxy_cached/Dockerfile @@ -23,6 +23,7 @@ RUN apt-get -y update && apt-get -y upgrade &&\ COPY docker-entrypoint.sh / COPY nginx.default.template / +COPY varnish.default.template / RUN set -e; \ export DEBIAN_FRONTEND=noninteractive; \ diff --git a/proxy_cached/docker-entrypoint.sh b/proxy_cached/docker-entrypoint.sh index cc0a1bf..bcae3da 100755 --- a/proxy_cached/docker-entrypoint.sh +++ b/proxy_cached/docker-entrypoint.sh @@ -2,6 +2,7 @@ set -e +cp /varnish.default.template /etc/varnish/default.vcl envsubst '$SERVER_NAME$PROXY_PROTO$PROXY_HOST' < /nginx.default.template > /etc/nginx/default.conf; if [ "$#" -eq 0 ] ; then diff --git a/proxy_cached/varnish.default.template b/proxy_cached/varnish.default.template new file mode 100644 index 0000000..92340d1 --- /dev/null +++ b/proxy_cached/varnish.default.template @@ -0,0 +1,14 @@ +vcl 4.1; + +backend default { + .host = "127.0.0.1"; + .port = "8080"; +} + +sub vcl_recv { + if (req.method != "GET" && req.method != "HEAD") { + return (pass); + } + + return (hash); +}