Compare commits

..

No commits in common. "49fa74159bf0d4a2274ec96b1162bc7bcb9b2972" and "f1faf3fedfb73784d5459902ac906ed59bbbcdd0" have entirely different histories.

5 changed files with 362 additions and 190 deletions

View File

@ -2,18 +2,11 @@
<project version="4"> <project version="4">
<component name="CommitMessageInspectionProfile"> <component name="CommitMessageInspectionProfile">
<profile version="1.0"> <profile version="1.0">
<inspection_tool class="BodyLimit" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> <inspection_tool class="BodyLimit" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SubjectBodySeparation" enabled="true" level="ERROR" enabled_by_default="true" /> <inspection_tool class="SubjectBodySeparation" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SubjectLimit" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="SubjectLimit" enabled="true" level="ERROR" enabled_by_default="true" />
</profile> </profile>
</component> </component>
<component name="GitSharedSettings">
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
<list>
<option value="master main" />
</list>
</option>
</component>
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>

View File

@ -0,0 +1,156 @@
###
### Parameters for use by ab-nginx helper script
###
### If you are NOT using the 'ab-nginx.sh' script file to start the container,
### then you don't have to do anything with this file.
###
#
# Network options
#
# If you want to specify a network to which this container should bind or one
# that should be created, then use this variable. If you don't know what this
# means or if you just want to use the default, leave this variable commented.
# REQUIRED: NO
# DEFAULT: nginx_network
# VALID OPTIONS: network names acceptable to the docker engine
#NETWORK=nginx_network
# If you want to specify a particular IP subnet for the network to be created
# as per the above variable, specify it here. Again, if you don't know what
# this means, just leave this variable commented.
# REQUIRED: NO
# DEFAULT: '172.31.254.0/24'
# VALID OPTIONS: subnet in CIDR format
#SUBNET='172.31.254.0/24'
#
# Timezone
#
# This doesn't impact any functionality of the container, but it does make your
# logs easier to understand if they report the correct local time, right? Valid
# options can be found at
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
# REQUIRED: NO
# DEFAULT: Etc/UTC
# VALID OPTIONS: IANA time zones in TZ format
#TZ=Etc/UTC
#
# NGINX options
#
# Hostnames to which this instance of NGINX should answer:
# By default, this is set to '_' meaning 'match anything'. However, that won't
# work if you're using SSL certificates! Multiple hostnames must be space
# delimited and "enclosed in quotes".
#
# This is NOT required if you are supplying your own server blocks via
# 'SERVERS_DIR'
#
# REQUIRED: YES, if using SSL and default server-blocks
# DEFAULT: "_"
#HOSTNAMES="domain.tld www.domain.tld server.domain.tld alt.domain.tld"
# Ports to listen on:
# If you need to use ports other than HTTP=80 and HTTPS=443, remember to set up
# your server blocks accordingly!
#
# If you're using the default server-blocks, they will auto-adjust to whatever
# you use here.
# REQUIRED: NO
# DEFAULTS: 80 and 443, respectively
#HTTP_PORT=80
#HTTPS_PORT=443
# Access logging (global preference):
# Unless overridden in a server/location block, access logging will be handled
# according to this setting. Logs are printed to the container console.
# REQUIRED: NO
# DEFAULT: OFF
# VALID OPTIONS: 'ON' or 'OFF'
#ACCESS_LOG=OFF
#
# Content locations
# Whatever you specify here will replace the default files in the container with
# your content/configurations. You may comment any/all of the following lines to
# disable them use the container defaults.
#
# Specify a directory containing your NGINX configurations (if any)
# Remember that these will be all be applied in the HTTP configuration context.
# Only files with a ".conf" extension will be loaded! If you want to disable a
# file, simply change its extension (i.e. '.conf.disabled').
#
# REMEMBER: Your configuration files must be readable by UID 8080!
CONFIG_DIR=$(pwd)/config
# Specify a directory containing your NGINX server-block configurations (if any)
# If you are just serving static content from the 'webroot', you can use the
# container default server-blocks and comment this variable.
#
# More likely, you will have your own server blocks. Remember, files are
# processed in order so consider starting file names with numbers
# (i.e. 00-first_server.conf, 05-second_server.conf)
#
# Only files with a ".conf" extension will be loaded! If you want to disable a
# file, simply change its extension (i.e. '.conf.disabled').
#
# REMEMBER: Your server-block files must be readable by UID 8080!
SERVERS_DIR=$(pwd)/sites
# Specify a directory containing 'snippets' of NGINX code you want/need to
# reference in other configuration files. Pointers to other SSL certificates for
# hosted domains or commonly used headers are good examples.
#
# You can then "include /etc/nginx/snippets/yourSnippet.conf;" in your configs
# instead of having to type the same thing many times.
# This is totally optional! Comment this variable to disable it.
# REMEMBER: Your snippets must be readable by UID 8080!
SNIPPETS_DIR=$(pwd)/snippets
# Specify a directory with the content you want to serve.
# REMEMBER: This directory must be readable by UID 8080!
WEBROOT_DIR=/var/www
#
# SSL options:
#
# Enable HSTS only AFTER you've tested SSL implementation! Container sets the
# header to require SSL for 6 months! Subdomains are NOT included.
# REQUIRED: NO
# DEFAULT: FALSE
# VALID OPTIONS: 'TRUE', 'FALSE'
#HSTS=FALSE
# TLS 1.3 mode:
# If 'FALSE' (default), NGINX will accept both TLS 1.2 and 1.3 connections.
# If 'TRUE', only TLS 1.3 connections will be accepted.
#TLS13_ONLY=FALSE
#
# Certificate files
#
# If you are mounting symlinks you MUST specify the full path of the symlink so
# the target is resolved! DH (Diffie-Hellman Parameters file) is only required
# if using TLS 1.2.
#
# REMEMBER: ALL files must be readble by UID 8080!
#SSL_CERT=/path/to/your/ssl-certificate/fullchain.pem
#SSL_KEY=/path/to/your/ssl-private-key/privkey.pem
#SSL_CHAIN=/path/to/your/ssl-certificate-chain/chain.pem
#DH=/path/to/your/diffie-hellman-parameters-file/dhparam.pem
#EOF

View File

@ -4,8 +4,6 @@
# start ab-nginx container using params file variables # start ab-nginx container using params file variables
# #
# TODO: add stop & stop and remove commands
# text formatting presets # text formatting presets
if command -v tput >/dev/null; then if command -v tput >/dev/null; then
cyan=$(tput bold)$(tput setaf 6) cyan=$(tput bold)$(tput setaf 6)
@ -24,7 +22,7 @@ else
fi fi
### parameter defaults ### parameter defaults
doShell=false shell=false
container_name="ab-nginx" container_name="ab-nginx"
NETWORK='nginx_network' NETWORK='nginx_network'
SUBNET='172.31.254.0/24' SUBNET='172.31.254.0/24'
@ -53,30 +51,27 @@ checkExist() {
} }
scriptHelp() { scriptHelp() {
printf "\n%s" "$magenta" printf "\n%s%1000s\n" "$magenta" | tr " " "-" | cut -c -$width
printf '%.0s-' $(seq "$width") printf "%s" "$norm"
printf "\n%s" "$norm" textblock "This is a simple helper script so you can avoid typing lengthy commands when working with the ab-nginx container."
textBlock "This is a simple helper script so you can avoid typing lengthy commands when working with the ab-nginx container." textblock "The script reads the contents of 'ab-nginx.params' and constructs various 'docker run' commands based on that file. The biggest time-saver is working with certificates. If they are specified in the params file, the script will automatically bind-mount them so nginx serves content via SSL by default."
textBlock "The script reads the contents of 'ab-nginx.params' and constructs various 'docker run' commands based on that file. The biggest time-saver is working with certificates. If they are specified in the params file, the script will automatically bind-mount them so nginx serves content via SSL by default."
newline newline
textBlock "If you run the script with no parameters, it will execute the container 'normally': Run in detached mode with nginx automatically launched. If you specified certificates, nginx will serve over SSL by default." textblock "If you run the script with no parameters, it will execute the container 'normally': Run in detached mode with nginx automatically launched. If you specified certificates, nginx will serve over SSL by default."
textBlock "Note: Containers (except shell) are always set to restart 'unless-stopped'. You must remove them manually if desired." textblock "Note: Containers (except shell) are always set to restart 'unless-stopped'. You must remove them manually if desired."
printf "%s" "$magenta" printf "%s" "$magenta"
newline newline
textBlock "The script has the following (optional) parameters:" textblock "The script has the following (optional) parameters:"
textBlockParam 'parameter in cyan' 'default in yellow' textblockParam 'parameter in cyan' 'default in yellow'
newline newline
textBlockParam '-n|--name' 'ab-nginx' textblockParam '-n|--name' 'ab-nginx'
textBlock "Set the name of the container, otherwise the default will be used." textblock "Change the name of the container. This is cosmetic and does not affect operation in any way."
newline newline
textBlockParam'-s|--shell' 'off: run in detached mode' textblockParam '-s|--shell' 'off: run in detached mode'
textBlock "Enter the container using an interactive ASH/BusyBox shell. This happens after startup operations but *before* nginx is actually started. This is a great way to see configuration changes possibly stopping nginx from starting normally." textblock "Enter the container using an interactive POSIX shell. This happens after startup operations but *before* nginx is actually started. This is a great way to see configuration changes possibly stopping nginx from starting normally."
printf "%s" "$yellow" printf "%s" "$yellow"
newline newline
textBlock"More information can be found at: https://git.asifbacchus.dev/ab-docker/ab-nginx/wiki" textblock "More information can be found at: https://git.asifbacchus.app/ab-docker/ab-nginx/wiki"
printf "\n%s" "$magenta" printf "%s%1000s\n" "$magenta" | tr " " "-" | cut -c -$width
printf '%.0s-' $(seq "$width")
printf "\n%s" "$norm"
exit 0 exit 0
} }
@ -84,11 +79,11 @@ newline() {
printf "\n" printf "\n"
} }
textBlock() { textblock() {
printf "%s\n" "$1" | fold -w "$width" -s printf "%s\n" "$1" | fold -w "$width" -s
} }
textBlockParam() { textblockParam() {
if [ -z "$2" ]; then if [ -z "$2" ]; then
# no default # no default
printf "%s%s%s\n" "$cyan" "$1" "$norm" printf "%s%s%s\n" "$cyan" "$1" "$norm"
@ -130,6 +125,16 @@ if [ "$SSL_CERT" ]; then checkExist 'file' "$SSL_CERT"; fi
if [ "$SSL_KEY" ]; then checkExist 'file' "$SSL_KEY"; fi if [ "$SSL_KEY" ]; then checkExist 'file' "$SSL_KEY"; fi
if [ "$SSL_CHAIN" ]; then checkExist 'file' "$SSL_CHAIN"; fi if [ "$SSL_CHAIN" ]; then checkExist 'file' "$SSL_CHAIN"; fi
# check for DHparam if using TLS1.2
if [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'FALSE' ]; then
if [ -z "$DH" ]; then
printf "%s\nA DHparam file must be specified when using TLS 1.2. Exiting.%s\n" "$err" "$norm"
exit 5
else
checkExist 'file' "$DH"
fi
fi
# check if specified config directory exists # check if specified config directory exists
if [ "$CONFIG_DIR" ]; then if [ "$CONFIG_DIR" ]; then
checkExist 'dir' "$CONFIG_DIR" checkExist 'dir' "$CONFIG_DIR"
@ -174,7 +179,7 @@ while [ $# -gt 0 ]; do
;; ;;
-s | --shell) -s | --shell)
# start shell instead of default CMD # start shell instead of default CMD
doShell=true shell=true
;; ;;
-n | --name) -n | --name)
# container name # container name
@ -204,44 +209,67 @@ docker network inspect ${NETWORK} >/dev/null 2>&1 ||
# run without TLS # run without TLS
if [ -z "$SSL_CERT" ]; then if [ -z "$SSL_CERT" ]; then
if [ "$doShell" = 'true' ]; then if [ $shell = 'true' ]; then
# exec shell # exec shell
printf "%s\nRunning SHELL on %s...%s\n" "$cyan" "$container_name" "$norm" printf "%s\nRunning SHELL on %s...%s\n" "$cyan" "$container_name" "$norm"
# shellcheck disable=SC2086
docker run --rm -it --name "${container_name}" \ docker run --rm -it --name "${container_name}" \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
--user="${NGINX_UID:-8080}:${NGINX_GID:-8080}" \
-e SERVER_NAMES="$HOSTNAMES" \ -e SERVER_NAMES="$HOSTNAMES" \
$vmount \ $vmount \
--network=${NETWORK} \ --network=${NETWORK} \
-p ${HTTP_PORT}:80 \ -p ${HTTP_PORT}:80 \
docker.asifbacchus.dev/nginx/ab-nginx:latest /bin/sh docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
else else
# exec normally # exec normally
printf "%s\nRunning NGINX on %s...%s\n" "$cyan" "$container_name" "$norm" printf "%s\nRunning NGINX on %s...%s\n" "$cyan" "$container_name" "$norm"
# shellcheck disable=SC2086
docker run -d --name "${container_name}" \ docker run -d --name "${container_name}" \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
--user="${NGINX_UID:-8080}:${NGINX_GID:-8080}" \
-e SERVER_NAMES="$HOSTNAMES" \ -e SERVER_NAMES="$HOSTNAMES" \
$vmount \ $vmount \
--network=${NETWORK} \ --network=${NETWORK} \
-p ${HTTP_PORT}:80 \ -p ${HTTP_PORT}:80 \
--restart unless-stopped \ --restart unless-stopped \
docker.asifbacchus.dev/nginx/ab-nginx:${TAG:-latest} docker.asifbacchus.app/nginx/ab-nginx:latest
fi fi
# run with TLS # run with TLS1.2
else elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'FALSE' ]; then
if [ "$doShell" = 'true' ]; then if [ $shell = 'true' ]; then
if [ "$TLS13_ONLY" = 'FALSE' ]; then # exec shell
printf "%s\nRunning SHELL on %s (TLS 1.2)...%s\n" "$cyan" "$container_name" "$norm" printf "%s\nRunning SHELL on %s (TLS 1.2)...%s\n" "$cyan" "$container_name" "$norm"
else
printf "%s\nRunning SHELL on %s (TLS 1.3)...%s\n" "$cyan" "$container_name" "$norm"
fi
# shellcheck disable=SC2086
docker run --rm -it --name "${container_name}" \ docker run --rm -it --name "${container_name}" \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
--user="${NGINX_UID:-8080}:${NGINX_GID:-8080}" \ -e SERVER_NAMES="$HOSTNAMES" \
$vmount \
--network=${NETWORK} \
-v "$SSL_CERT":/certs/fullchain.pem:ro \
-v "$SSL_KEY":/certs/privkey.pem:ro \
-v "$SSL_CHAIN":/certs/chain.pem:ro \
-v "$DH":/certs/dhparam.pem:ro \
-p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
else
# exec normally
printf "%s\nRunning NGINX on %s (TLS 1.2)...%s\n" "$cyan" "$container_name" "$norm"
docker run -d --name "${container_name}" \
--env-file ab-nginx.params \
-e SERVER_NAMES="$HOSTNAMES" \
$vmount \
--network=${NETWORK} \
-v "$SSL_CERT":/certs/fullchain.pem:ro \
-v "$SSL_KEY":/certs/privkey.pem:ro \
-v "$SSL_CHAIN":/certs/chain.pem:ro \
-v "$DH":/certs/dhparam.pem:ro \
-p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \
--restart unless-stopped \
docker.asifbacchus.app/nginx/ab-nginx:latest
fi
# run with TLS1.3
elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'TRUE' ]; then
if [ $shell = 'true' ]; then
# exec shell
printf "%s\nRunning SHELL on %s (TLS 1.3)...%s\n" "$cyan" "$container_name" "$norm"
docker run --rm -it --name "${container_name}" \
--env-file ab-nginx.params \
-e SERVER_NAMES="$HOSTNAMES" \ -e SERVER_NAMES="$HOSTNAMES" \
$vmount \ $vmount \
--network=${NETWORK} \ --network=${NETWORK} \
@ -249,17 +277,12 @@ else
-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 \
-p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \ -p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \
docker.asifbacchus.dev/nginx/ab-nginx:${TAG:-latest} /bin/sh docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
else
if [ "$TLS13_ONLY" = 'FALSE' ]; then
printf "%s\nRunning NGINX on %s (TLS 1.2)...%s\n" "$cyan" "$container_name" "$norm"
else else
# exec normally
printf "%s\nRunning NGINX on %s (TLS 1.3)...%s\n" "$cyan" "$container_name" "$norm" printf "%s\nRunning NGINX on %s (TLS 1.3)...%s\n" "$cyan" "$container_name" "$norm"
fi
# shellcheck disable=SC2086
docker run -d --name "${container_name}" \ docker run -d --name "${container_name}" \
--env-file ab-nginx.params \ --env-file ab-nginx.params \
--user="${NGINX_UID:-8080}:${NGINX_GID:-8080}" \
-e SERVER_NAMES="$HOSTNAMES" \ -e SERVER_NAMES="$HOSTNAMES" \
$vmount \ $vmount \
--network=${NETWORK} \ --network=${NETWORK} \
@ -268,7 +291,7 @@ else
-v "$SSL_CHAIN":/certs/chain.pem:ro \ -v "$SSL_CHAIN":/certs/chain.pem:ro \
-p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \ -p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \
--restart unless-stopped \ --restart unless-stopped \
docker.asifbacchus.dev/nginx/ab-nginx:${TAG:-latest} docker.asifbacchus.app/nginx/ab-nginx:latest
fi fi
fi fi

View File

@ -1,8 +1,8 @@
- Place all your server block configuration files in this directory - Place all your server block configuration files in this directory
- This path should be bind-mounted to the container at: - This path should be bind-mounted to the container at:
'/etc/nginx/sites' '/etc/nginx/sites'
- this bind-mount will override the default server configurations - this bind-mount will override the test pages included in the container by
included in the container by default. default.
- All files should begin in the 'server' configuration context - All files should begin in the 'server' configuration context
- ONLY files that end with '.conf' will be processed! - ONLY files that end with '.conf' will be processed!
- if you want to keep a file for reference or disable it temporarily, - if you want to keep a file for reference or disable it temporarily,

View File

@ -90,8 +90,8 @@ updateSuccess=0
# reference constants # reference constants
dockerNamespace='nginx' dockerNamespace='nginx'
containerName='ab-nginx' containerName='ab-nginx'
containerUpdatePath="docker.asifbacchus.dev/$dockerNamespace/$containerName:latest" containerUpdatePath="docker.asifbacchus.app/$dockerNamespace/$containerName:latest"
server="https://asifbacchus.dev/public/docker/$dockerNamespace/$containerName/" server="https://asifbacchus.app/updates/docker/$dockerNamespace/$containerName/"
checksumFilename='checksums.sha256' checksumFilename='checksums.sha256'
# operation triggers # operation triggers