From caae17258985b310ae48f4295e98a0791b010a85 Mon Sep 17 00:00:00 2001 From: Damian Silbergleith Cunniff Date: Fri, 17 May 2019 07:15:22 -0700 Subject: [PATCH 1/3] allow user configs without custom image --- README.md | 11 ++++++----- example/Dockerfile | 2 -- example/{ => conf.d}/nginx.conf | 0 example/docker-compose.yml | 4 +++- src/scripts/startup/link_user_configs.sh | 15 +++++++++++++++ 5 files changed, 24 insertions(+), 8 deletions(-) delete mode 100644 example/Dockerfile rename example/{ => conf.d}/nginx.conf (100%) create mode 100755 src/scripts/startup/link_user_configs.sh diff --git a/README.md b/README.md index 0c795ac..01b4483 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,12 @@ This repository was originally forked from `@henridwyer`, many thanks to him for # Usage -Use this image with a `Dockerfile` such as: -```Dockerfile -FROM staticfloat/nginx-certbot -COPY *.conf /etc/nginx/conf.d/ +Create a config directory for your custom configs: +``` +mkdir conf.d ``` -And a `.conf` file such as: +And a `.conf` file such as in that directory: ```nginx server { listen 443 ssl; @@ -43,6 +42,8 @@ services: - 443:443/tcp environment: - CERTBOT_EMAIL=owner@company.com + volumes: + - ./conf.d:/etc/nginx/user.conf.d ... ``` diff --git a/example/Dockerfile b/example/Dockerfile deleted file mode 100644 index 21c5edd..0000000 --- a/example/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM staticfloat/nginx-certbot -COPY *.conf /etc/nginx/conf.d/ \ No newline at end of file diff --git a/example/nginx.conf b/example/conf.d/nginx.conf similarity index 100% rename from example/nginx.conf rename to example/conf.d/nginx.conf diff --git a/example/docker-compose.yml b/example/docker-compose.yml index 8e4bad8..9e2a1af 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -2,10 +2,12 @@ version: '3' services: proxy: - build: . + image: staticfloat/nginx-certbot restart: always environment: CERTBOT_EMAIL: "your.email@example.com" ports: - "80:80" - "443:443" + volumes: + - ./conf.d:/etc/nginx/user.conf.d diff --git a/src/scripts/startup/link_user_configs.sh b/src/scripts/startup/link_user_configs.sh new file mode 100755 index 0000000..eb987a2 --- /dev/null +++ b/src/scripts/startup/link_user_configs.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +SOURCE_DIR=/etc/nginx/user.conf.d +TARGET_DIR=/etc/nginx/conf.d + +echo "symlinking scripts from ${SOURCE_DIR} to ${TARGET_DIR}" + +if [ ! -d "$SOURCE_DIR" ]; then + echo "no ${SOURCE_DIR}, nothing to do." +else + for conf in ${SOURCE_DIR}/*.conf; do + echo "symlinking: ${conf}" "${TARGET_DIR}/$(basename ${conf})" + ln -s "${conf}" "${TARGET_DIR}/$(basename ${conf})" + done +fi From 67821fcc0db1d44579112f4ba5be655ff3a80c54 Mon Sep 17 00:00:00 2001 From: Damian Silbergleith Cunniff Date: Fri, 24 May 2019 19:43:57 -0700 Subject: [PATCH 2/3] move link functionality into utils as a sh function --- src/scripts/entrypoint.sh | 3 +++ src/scripts/startup/link_user_configs.sh | 15 --------------- src/scripts/util.sh | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) delete mode 100755 src/scripts/startup/link_user_configs.sh diff --git a/src/scripts/entrypoint.sh b/src/scripts/entrypoint.sh index 71d433e..ef57e61 100644 --- a/src/scripts/entrypoint.sh +++ b/src/scripts/entrypoint.sh @@ -7,6 +7,9 @@ trap "kill 0" EXIT # Source in util.sh so we can have our nice tools . $(cd $(dirname $0); pwd)/util.sh +# first include any user configs if they've been mounted +link_user_configs + # Immediately run auto_enable_configs so that nginx is in a runnable state auto_enable_configs diff --git a/src/scripts/startup/link_user_configs.sh b/src/scripts/startup/link_user_configs.sh deleted file mode 100755 index eb987a2..0000000 --- a/src/scripts/startup/link_user_configs.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -SOURCE_DIR=/etc/nginx/user.conf.d -TARGET_DIR=/etc/nginx/conf.d - -echo "symlinking scripts from ${SOURCE_DIR} to ${TARGET_DIR}" - -if [ ! -d "$SOURCE_DIR" ]; then - echo "no ${SOURCE_DIR}, nothing to do." -else - for conf in ${SOURCE_DIR}/*.conf; do - echo "symlinking: ${conf}" "${TARGET_DIR}/$(basename ${conf})" - ln -s "${conf}" "${TARGET_DIR}/$(basename ${conf})" - done -fi diff --git a/src/scripts/util.sh b/src/scripts/util.sh index 2c47c7d..02bff88 100644 --- a/src/scripts/util.sh +++ b/src/scripts/util.sh @@ -91,3 +91,22 @@ is_renewal_required() { is_finshed_week_sec=$(( ($one_week_sec - $last_renewal_delta_sec) )) [ $is_finshed_week_sec -lt 0 ] } + +# symlinks any *.conf files in /etc/nginx/user.conf.d +# to /etc/nginx/conf.d so they are included as configs +# this allows a user to easily mount their own configs +link_user_configs() { + SOURCE_DIR=${1-/etc/nginx/user.conf.d} + TARGET_DIR=${2-/etc/nginx/conf.d} + + echo "symlinking scripts from ${SOURCE_DIR} to ${TARGET_DIR}" + + if [ ! -d "$SOURCE_DIR" ]; then + echo "no ${SOURCE_DIR}, nothing to do." + else + for conf in ${SOURCE_DIR}/*.conf; do + echo "symlinking: ${conf}" "${TARGET_DIR}/$(basename ${conf})" + ln -s "${conf}" "${TARGET_DIR}/$(basename ${conf})" + done + fi +} \ No newline at end of file From d49c7c544fbb11266be55ebd342234b3635b3175 Mon Sep 17 00:00:00 2001 From: Damian Silbergleith Cunniff Date: Wed, 2 Oct 2019 21:00:59 -0700 Subject: [PATCH 3/3] address PR request comments for minor cleanup --- README.md | 4 ++-- example/docker-compose.yml | 3 ++- src/scripts/util.sh | 9 ++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 01b4483..9dc73c7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Create a config directory for your custom configs: mkdir conf.d ``` -And a `.conf` file such as in that directory: +And a `.conf` in that directory: ```nginx server { listen 443 ssl; @@ -43,7 +43,7 @@ services: environment: - CERTBOT_EMAIL=owner@company.com volumes: - - ./conf.d:/etc/nginx/user.conf.d + - ./conf.d:/etc/nginx/user.conf.d :ro ... ``` diff --git a/example/docker-compose.yml b/example/docker-compose.yml index 9e2a1af..3337320 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -10,4 +10,5 @@ services: - "80:80" - "443:443" volumes: - - ./conf.d:/etc/nginx/user.conf.d + - ./conf.d:/etc/nginx/user.conf.d :ro + diff --git a/src/scripts/util.sh b/src/scripts/util.sh index 02bff88..b96b149 100644 --- a/src/scripts/util.sh +++ b/src/scripts/util.sh @@ -96,8 +96,8 @@ is_renewal_required() { # to /etc/nginx/conf.d so they are included as configs # this allows a user to easily mount their own configs link_user_configs() { - SOURCE_DIR=${1-/etc/nginx/user.conf.d} - TARGET_DIR=${2-/etc/nginx/conf.d} + SOURCE_DIR="${1-/etc/nginx/user.conf.d}" + TARGET_DIR="${2-/etc/nginx/conf.d}" echo "symlinking scripts from ${SOURCE_DIR} to ${TARGET_DIR}" @@ -105,8 +105,7 @@ link_user_configs() { echo "no ${SOURCE_DIR}, nothing to do." else for conf in ${SOURCE_DIR}/*.conf; do - echo "symlinking: ${conf}" "${TARGET_DIR}/$(basename ${conf})" - ln -s "${conf}" "${TARGET_DIR}/$(basename ${conf})" + ln -sv "${conf}" "${TARGET_DIR}/$(basename ${conf})" done fi -} \ No newline at end of file +}