commit f0b8ac6301ceab2046bb72f59e72596adbfda13e Author: redxef Date: Fri Feb 5 15:13:20 2021 +0100 Init commit. diff --git a/environment_variables.txt b/environment_variables.txt new file mode 100644 index 0000000..0ec23cc --- /dev/null +++ b/environment_variables.txt @@ -0,0 +1 @@ +${DOMAIN_NAME} diff --git a/nginx.Dockerfile b/nginx.Dockerfile new file mode 100644 index 0000000..40ae86a --- /dev/null +++ b/nginx.Dockerfile @@ -0,0 +1,12 @@ +# FROM nginx:alpine +FROM alpine:latest + +RUN apk update && apk upgrade && apk add nginx gettext && \ + rm -r /etc/nginx + +COPY start-nginx.sh /usr/local/bin/ +COPY environemnt_variables.txt / + +USER root +ENTRYPOINT ["/bin/sh", "-c"] +CMD ["start-nginx.sh"] diff --git a/start-nginx.sh b/start-nginx.sh new file mode 100755 index 0000000..16ee0bd --- /dev/null +++ b/start-nginx.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env sh + +set -x + +enable_server() { + for name in "$@"; do + src_dir="/etc/nginx/sites-available" + dst_dir="/etc/nginx/sites-enabled" + mkdir -p "$dst_dir" + envsubst '${DOMAIN_NAME}' < "$src_dir/$name.conf" > "$dst_dir/$name.conf" + done +} + +enable_ssh_server() { + for name in "$@"; do + src_dir="/etc/nginx/ssh-available" + dst_dir="/etc/nginx/ssh-enabled" + mkdir -p "$dst_dir" + envsubst '${DOMAIN_NAME}' < "$src_dir/$name.conf" > "$dst_dir/$name.conf" + done +} + +sub_env_vars="$(cat /environment_variables.txt)" + +echo "Enabling servers" +( + pushd "/etc/nginx/sites-available" || exit $? + for f in *.conf; do + envsubst "$sub_env_vars" < "$f" > "../sites-enabled/$f" + done +) + +echo "Starting nginx" +exec nginx -g 'daemon off;' -c /etc/nginx/nginx.conf