From ebd47a4bb5b69714b065b60a029d16482f69a908 Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Tue, 21 Dec 2021 12:11:40 +0200 Subject: [PATCH] Support STACK_NAME / PHP_SERVICE.. ..so it continues to work on both local and remote --- Dockerfile | 15 ++++++++++++++- README.md | 2 +- entrypoint.sh | 5 +++++ nginx.conf | 6 +++++- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 0e81731..50b8ea5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,17 @@ FROM nginx:1.21.4 # TODO: use renovate-bot to send pull requests on upstream image updates -COPY nginx.conf /etc/nginx/templates/default.conf.template +RUN mkdir /etc/nginx/templates.override +COPY nginx.conf /etc/nginx/templates.override/default.conf.template + +# goenvtemplator2 for config file updates, working around msmtp's inability to +# configure itself from environment variables. +# nginx includes gettext's envsubst, which is generall is more common, but it +# doesn't support conditionals, or even the "default" syntax ${FOO:+default} +ADD https://github.com/seznam/goenvtemplator/releases/download/v2.0.0/goenvtemplator2-amd64 /usr/local/bin/goenvtemplator2 +RUN chmod +x /usr/local/bin/goenvtemplator2 + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh +ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ] +CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index d1418fe..1d01edb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A very lightly-customised `nginx` Docker image, featuring: -* A Wordpress / PHP-FPM configuration file +* A Wordpress / PHP-FPM configuration file template for Nginx Changes to this repository are automatically published to [Docker Hub](https://hub.docker.com/r/thecoopcloud/nginx) as diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..cef7c96 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +goenvtemplator2 -template /etc/nginx/templates.override/default.conf.template:/etc/nginx/conf.d/default.conf + +/docker-entrypoint.sh "$@" diff --git a/nginx.conf b/nginx.conf index c9283bb..e2cdbd3 100644 --- a/nginx.conf +++ b/nginx.conf @@ -30,7 +30,11 @@ server { location ~ .php$ { fastcgi_read_timeout 300; - fastcgi_pass ${STACK_NAME}_php:9000; + {{ if not (eq (env "PHP_SERVICE") "") }} + fastcgi_pass {{ env "PHP_SERVICE" }}:9000; + {{ else }} + fastcgi_pass {{ env "STACK_NAME" }}_php:9000; + {{ end }} fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /app/web/$fastcgi_script_name;