mount config and webroot from params file

This commit is contained in:
Asif Bacchus 2019-10-17 18:53:22 -06:00
parent fd5aa717e6
commit ddfebb0390

View File

@ -17,6 +17,7 @@ container_name="ab-nginx"
shell=false shell=false
unset CONFIG_DIR unset CONFIG_DIR
unset WEBROOT_DIR unset WEBROOT_DIR
unset vmount
scriptHelp () { scriptHelp () {
@ -107,6 +108,17 @@ if [ "$WEBROOT_DIR" ] && [ ! -d "$WEBROOT_DIR" ]; then
exit 4 exit 4
fi fi
# set up volume mounts for config and/or webroot
if [ -z "$CONFIG_DIR" ] && [ -z "$WEBROOT_DIR" ]; then
vmount=""
elif [ "$CONFIG_DIR" ] && [ "$WEBROOT_DIR" ]; then
vmount="-v $CONFIG_DIR:/etc/nginx/config/ -v $WEBROOT_DIR:/usr/share/nginx/html/"
elif [ "$CONFIG_DIR" ]; then
vmount="-v $CONFIG_DIR:/etc/nginx/config/"
elif [ "$WEBROOT_DIR" ]; then
vmount="-v $WEBROOT_DIR:/usr/share/nginx/html/"
fi
# process startup parameters # process startup parameters
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
@ -144,11 +156,19 @@ if [ -z "$SSL_CERT" ]; then
if [ $shell = true ]; then if [ $shell = true ]; then
# exec shell # exec shell
printf "${cyan}\nRunning SHELL on %s...${norm}\n" "$container_name" printf "${cyan}\nRunning SHELL on %s...${norm}\n" "$container_name"
docker run --rm -it --name ${container_name} --env-file ab-nginx.params -p 80:80 ab-nginx:testing /bin/sh docker run --rm -it --name ${container_name} \
--env-file ab-nginx.params \
$vmount \
-p 80:80 \
ab-nginx:testing /bin/sh
else else
# exec normally # exec normally
printf "${cyan}\nRunning NGINX on %s...${norm}\n" "$container_name" printf "${cyan}\nRunning NGINX on %s...${norm}\n" "$container_name"
docker run --rm -d --name ${container_name} --env-file ab-nginx.params -p 80:80 ab-nginx:testing docker run --rm -d --name ${container_name} \
--env-file ab-nginx.params \
$vmount \
-p 80:80 \
ab-nginx:testing
fi fi
# run with TLS1.2 # run with TLS1.2
elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = FALSE ]; then elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = FALSE ]; then
@ -157,6 +177,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = FALSE ]; then
printf "${cyan}\nRunning SHELL on %s (TLS 1.2)...${norm}\n" "$container_name" printf "${cyan}\nRunning SHELL on %s (TLS 1.2)...${norm}\n" "$container_name"
docker run --rm -it --name ${container_name} \ docker run --rm -it --name ${container_name} \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
$vmount \
-v "$SSL_CERT":/certs/fullchain.pem:ro \ -v "$SSL_CERT":/certs/fullchain.pem:ro \
-v "$SSL_KEY":/certs/privkey.pem:ro \ -v "$SSL_KEY":/certs/privkey.pem:ro \
-v "$SSL_CHAIN":/certs/chain.pem:ro \ -v "$SSL_CHAIN":/certs/chain.pem:ro \
@ -168,6 +189,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = FALSE ]; then
printf "${cyan}\nRunning NGINX on %s (TLS 1.2)...${norm}\n" "$container_name" printf "${cyan}\nRunning NGINX on %s (TLS 1.2)...${norm}\n" "$container_name"
docker run --rm -d --name ${container_name} \ docker run --rm -d --name ${container_name} \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
$vmount \
-v "$SSL_CERT":/certs/fullchain.pem:ro \ -v "$SSL_CERT":/certs/fullchain.pem:ro \
-v "$SSL_KEY":/certs/privkey.pem:ro \ -v "$SSL_KEY":/certs/privkey.pem:ro \
-v "$SSL_CHAIN":/certs/chain.pem:ro \ -v "$SSL_CHAIN":/certs/chain.pem:ro \
@ -182,6 +204,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = TRUE ]; then
printf "${cyan}\nRunning SHELL on %s (TLS 1.3)...${norm}\n" "$container_name" printf "${cyan}\nRunning SHELL on %s (TLS 1.3)...${norm}\n" "$container_name"
docker run --rm -it --name ${container_name} \ docker run --rm -it --name ${container_name} \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
$vmount \
-v "$SSL_CERT":/certs/fullchain.pem:ro \ -v "$SSL_CERT":/certs/fullchain.pem:ro \
-v "$SSL_KEY":/certs/privkey.pem:ro \ -v "$SSL_KEY":/certs/privkey.pem:ro \
-v "$SSL_CHAIN":/certs/chain.pem:ro \ -v "$SSL_CHAIN":/certs/chain.pem:ro \
@ -192,6 +215,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = TRUE ]; then
printf "${cyan}\nRunning NGINX on %s (TLS 1.3)...${norm}\n" "$container_name" printf "${cyan}\nRunning NGINX on %s (TLS 1.3)...${norm}\n" "$container_name"
docker run --rm -d --name ${container_name} \ docker run --rm -d --name ${container_name} \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
$vmount \
-v "$SSL_CERT":/certs/fullchain.pem:ro \ -v "$SSL_CERT":/certs/fullchain.pem:ro \
-v "$SSL_KEY":/certs/privkey.pem:ro \ -v "$SSL_KEY":/certs/privkey.pem:ro \
-v "$SSL_CHAIN":/certs/chain.pem:ro \ -v "$SSL_CHAIN":/certs/chain.pem:ro \