Skip to content

Commit 49a78b7

Browse files
authored
v5.1.0 (#119)
Major updates * Adding environment variables to auto generate SSL config and certs on first startup
1 parent b7c1e4a commit 49a78b7

File tree

13 files changed

+105
-8
lines changed

13 files changed

+105
-8
lines changed

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ ARG BF_VERSION
99
EXPOSE 443
1010

1111
ENV \
12+
# the base URI of the proxy server (will be used when SSL bindings fail)
1213
PROXY_URI= \
1314
# clean all config and certificates before doing anything else
1415
PROXY_CLEAN_INSTALL=0 \
1516
# used for renewal notification emails
1617
PROXY_LETS_ENCRYPT_EMAIL= \
17-
# the base URI of the proxy server (will be used when SSL bindings fail)
1818
# set to 1 to use live instead of staging server
1919
PROXY_LETS_ENCRYPT_LIVE=0 \
2020
# enable automatic certificate updating
@@ -26,7 +26,14 @@ ENV \
2626
# canonical domain name redirection
2727
PROXY_SSL_REDIRECT_TO_CANONICAL=0 \
2828
# set to true to skip local HTTP token check
29-
PROXY_GETSSL_SKIP_HTTP_TOKEN_CHECK="false"
29+
PROXY_GETSSL_SKIP_HTTP_TOKEN_CHECK="false" \
30+
# if both are set, on first startup will generate SSL config and request certs
31+
PROXY_AUTO_PRIMARY= \
32+
PROXY_AUTO_UPSTREAM= \
33+
# optional - add aliases to the auto-generated conf.json on first startup
34+
PROXY_AUTO_ALIASES= \
35+
# optional - mark the Nginx config as custom so it isn't regenerated on future startups
36+
PROXY_AUTO_CUSTOM=0
3037

3138
COPY ./overlay /
3239

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0.16
1+
5.1.0

VERSION_MINOR

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0
1+
5.1

overlay/etc/bf/init.d/20-env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bf-env "PROXY_GETSSL" "${PROXY_LIB}/getssl"
1414

1515
PROXY_SSL=/ssl
1616
bf-env "PROXY_SSL" ${PROXY_SSL}
17+
bf-env "PROXY_SSL_CONF" "${PROXY_SSL}/conf.json"
1718
bf-env "PROXY_SSL_DHPARAM" "${PROXY_SSL}/dhparam.pem"
1819

1920
PROXY_SSL_CERTS=${PROXY_SSL}/certs

overlay/etc/bf/init.d/21-ssl renamed to overlay/etc/bf/init.d/21-ssl-init

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ if [ "${PROXY_CLEAN_INSTALL}" = "1" ] ; then
2020
fi
2121

2222

23+
#======================================================================================================================
24+
# If there is no SSL configuration file, and auto environment variables are set, generate config.
25+
#======================================================================================================================
26+
27+
if [ ! -f "${PROXY_SSL_CONF}" ] && [ -n "${PROXY_AUTO_PRIMARY-}" ] && [ -n "${PROXY_AUTO_UPSTREAM-}" ] ; then
28+
29+
# generate conf
30+
bf-echo "Generating conf.json using auto environment variables."
31+
bf-esh ${BF_TEMPLATES}/conf.json.esh ${PROXY_SSL_CONF}
32+
bf-env "PROXY_AUTO" "1"
33+
34+
# if there are aliases enable canonical redirection
35+
[[ -n "${PROXY_AUTO_ALIASES}" ]] && bf-env "PROXY_SSL_REDIRECT_TO_CANONICAL" "1"
36+
37+
fi
38+
39+
2340
#======================================================================================================================
2441
# Run initialisation script.
2542
#======================================================================================================================
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/bfren/docker-nginx-proxy/main/ssl-conf-schema.json",
3+
"domains": [
4+
{
5+
"primary": "<%= ${PROXY_AUTO_PRIMARY} %>",
6+
"upstream": "<%= ${PROXY_AUTO_UPSTREAM} %>"<% if [ -n "${PROXY_AUTO_ALIASES-}" ] ; then %>,
7+
"aliases": [ "<%= ${PROXY_AUTO_ALIASES// /\", \"} %>" ]<% fi ; if [ "${PROXY_AUTO_CUSTOM-}" = "1" ] ; then %>,
8+
"custom": true<% fi %>
9+
}
10+
]
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nginx
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/command/with-contenv bash
2+
3+
set -euo pipefail
4+
export BF_E="${PWD##*/}/$(basename ${0})"
5+
6+
7+
#======================================================================================================================
8+
# Show helpful log message.
9+
#======================================================================================================================
10+
11+
bf-svc-finish
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/command/with-contenv bash
2+
3+
set -euo pipefail
4+
export BF_E="${PWD##*/}/$(basename ${0})"
5+
6+
7+
#======================================================================================================================
8+
# Run request executable and then disable the service.
9+
# First, wait until the Nginx service is running.
10+
#======================================================================================================================
11+
12+
if [ "${PROXY_AUTO-}" = "1" ] ; then
13+
14+
if [ -n "$(pidof nginx)" ]; then
15+
16+
# run upgrade executable
17+
bf-echo "Requesting SSL certificates using auto-generated conf.json."
18+
ssl-request
19+
20+
# disable the auto request service
21+
ssl-auto-request-disable
22+
23+
else
24+
25+
# wait 2s before exiting the service - S6 will keep restarting it until Nginx comes online
26+
# on first run, it will disable this upgrade service itself
27+
SLEEP=2
28+
bf-debug "Waiting ${SLEEP}s for Nginx to come online..."
29+
sleep ${SLEEP}
30+
31+
fi
32+
33+
else
34+
35+
# disable the auto request service
36+
ssl-auto-request-disable
37+
38+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
longrun

0 commit comments

Comments
 (0)