From 29a76c5a7d3afe18249eef5d7ccb189326712340 Mon Sep 17 00:00:00 2001 From: Dorian Boulc'h Date: Thu, 8 Aug 2024 09:54:51 +0200 Subject: [PATCH] feat: add ability to customize proxy's docker images --- docs/docs.md | 10 +++++++++- .../proxy/assets/templates/shared-config.sh | 18 +++++++++++++++++- src/plugins/proxy/assets/templates/start.sh | 18 ++++++++++-------- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index 0bc98ce8..a3867c02 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -785,7 +785,15 @@ module.exports = { // Add an nginx config that is used proxy-wide. // This config can add additional upstream and server blocks if needed. nginxConfig: './path/to/config', - // Environment variables for nginx proxy + + // Customize the base image running Nginx proxy + nginxProxyImage: 'zodern/nginx-proxy', + nginxProxyVersion: 'v1.1.0', + // Customize the base image running letsencrypt nginx proxy companion + letsencryptCompanionImage: 'jrcs/letsencrypt-nginx-proxy-companion', + letsencryptCompanionVersion: 'v1.13.1', + + // Environment variables for nginx proxy env: { DEFAULT_HOST: 'foo.bar.com' }, diff --git a/src/plugins/proxy/assets/templates/shared-config.sh b/src/plugins/proxy/assets/templates/shared-config.sh index e441fc10..d2255210 100644 --- a/src/plugins/proxy/assets/templates/shared-config.sh +++ b/src/plugins/proxy/assets/templates/shared-config.sh @@ -10,4 +10,20 @@ export HTTPS_PORT=<%= httpsPort %> <% if (clientUploadLimit) { %> export CLIENT_UPLOAD_LIMIT=<%= clientUploadLimit %> -<% } %> \ No newline at end of file +<% } %> + +<% if (nginxProxyImage) { %> +export NGINX_PROXY_IMAGE=<%= nginxProxyImage %> +<% } %> + +<% if (nginxProxyVersion) { %> +export NGINX_PROXY_VERSION=<%= nginxProxyVersion %> +<% } %> + +<% if (letsencryptCompanionImage) { %> +export LETSENCRYPT_COMPANION_IMAGE=<%= letsencryptCompanionImage %> +<% } %> + +<% if (letsencryptCompanionVersion) { %> +export LETSENCRYPT_COMPANION_VERSION=<%= letsencryptCompanionVersion %> +<% } %> diff --git a/src/plugins/proxy/assets/templates/start.sh b/src/plugins/proxy/assets/templates/start.sh index 7480ddb2..aa4d543b 100644 --- a/src/plugins/proxy/assets/templates/start.sh +++ b/src/plugins/proxy/assets/templates/start.sh @@ -2,14 +2,16 @@ APPNAME=<%= appName %> APP_PATH=/opt/$APPNAME -NGINX_PROXY_VERSION="v1.1.0" -LETSENCRYPT_COMPANION_VERSION="v1.13.1" # Shared settings source $APP_PATH/config/shared-config.sh : ${HTTP_PORT:=80} : ${HTTPS_PORT:=443} : ${CLIENT_UPLOAD_LIMIT="10M"} +: ${NGINX_PROXY_IMAGE="zodern/nginx-proxy"} +: ${NGINX_PROXY_VERSION="v1.1.0"} +: ${LETSENCRYPT_COMPANION_IMAGE="jrcs/letsencrypt-nginx-proxy-companion"} +: ${LETSENCRYPT_COMPANION_VERSION="v1.13.1"} ENV_FILE=$APP_PATH/config/env.list ENV_FILE_LETSENCRYPT=$APP_PATH/config/env_letsencrypt.list @@ -18,10 +20,10 @@ ENV_FILE_LETSENCRYPT=$APP_PATH/config/env_letsencrypt.list # We don't need to fail the deployment because of a docker hub downtime set +e -sudo docker pull jrcs/letsencrypt-nginx-proxy-companion:$LETSENCRYPT_COMPANION_VERSION -sudo docker pull zodern/nginx-proxy:$NGINX_PROXY_VERSION +sudo docker pull $LETSENCRYPT_COMPANION_IMAGE:$LETSENCRYPT_COMPANION_VERSION +sudo docker pull $NGINX_PROXY_IMAGE:$NGINX_PROXY_VERSION set -e -echo "Pulled zodern/nginx-proxy and jrcs/letsencrypt-nginx-proxy-companion" +echo "Pulled $NGINX_PROXY_IMAGE and $LETSENCRYPT_COMPANION_IMAGE" # This updates nginx for all vhosts NGINX_CONFIG="client_max_body_size $CLIENT_UPLOAD_LIMIT;"; @@ -60,7 +62,7 @@ sudo docker run \ -v /opt/$APPNAME/config/nginx-default.conf:/etc/nginx/conf.d/my_proxy.conf:ro \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ -v /opt/$APPNAME/upstream:/etc/nginx/upstream \ - zodern/nginx-proxy:$NGINX_PROXY_VERSION + $NGINX_PROXY_IMAGE:$NGINX_PROXY_VERSION echo "Ran nginx-proxy as $APPNAME" sleep 2s @@ -78,8 +80,8 @@ sudo docker run \ --log-opt max-size=100m \ --log-opt max-file=3 \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ - jrcs/letsencrypt-nginx-proxy-companion:$LETSENCRYPT_COMPANION_VERSION -echo "Ran jrcs/letsencrypt-nginx-proxy-companion" + $LETSENCRYPT_COMPANION_IMAGE:$LETSENCRYPT_COMPANION_VERSION +echo "Ran $LETSENCRYPT_COMPANION_IMAGE" <% if (swarmEnabled) { %> docker rm -f $APPNAME-swarm-upstream || true