37 Commits

Author SHA1 Message Date
asif f7a6d924d9 feature(helpers): add exit codes to update script 2021-07-27 18:28:09 -06:00
asif 16f302c3fd struct(tools): checksum generator script 2021-07-27 17:08:55 -06:00
asif a6107f7e25 struct(helpers): set params file as template again
- prevents accidental overwrite of user params on updates
2021-07-27 16:17:04 -06:00
asif 03e0631964 style(helpers): reformat update script and bump version 2021-07-27 16:09:27 -06:00
asif 4d5f3fa809 refactor(helpers): echo docker run result code on exit 2021-07-27 16:04:31 -06:00
asif fb81443cba style(helpers): make comment header style consistent 2021-07-27 16:00:30 -06:00
asif 92c0217374 perf(helpers): import and check params-file only if running 2021-07-27 15:58:12 -06:00
asif 750ad05d06 refactor(helpers): change name of stop and remove parameter switch 2021-07-27 15:55:17 -06:00
asif 0db9675bc4 feature(helpers): add stop and remove commands 2021-07-27 15:53:17 -06:00
asif dd7ef19d88 refactor(helpers): update and notate return codes 2021-07-27 15:39:30 -06:00
asif 810cbd44b7 feature(helpers): add container status display 2021-07-27 15:26:53 -06:00
asif 2b583ad7e0 struct(dockerfile): change internal labels
- add internal name label to allow finding containers
- use new domain in private labels
2021-07-27 15:10:49 -06:00
asif 4a1c1e5153 refactor(helpers): set initial vars to null vs unset 2021-07-27 14:59:16 -06:00
asif 2b55ae11f4 refactor(helpers): change volume mount var name
- change from vmount to volumeMounts
2021-07-27 14:58:01 -06:00
asif 49fa74159b refactor(helpers): remove dhparams check
- container now auto-generates this file if needed
2021-07-27 14:41:32 -06:00
asif 3548d88b63 style(helpers): rename textBlock functions
- rename functions to camelCase
2021-07-27 14:37:57 -06:00
asif a1e2911dc0 docs(helpers): change help text for container name 2021-07-27 14:35:57 -06:00
asif a2b08d5a72 refactor(helpers): activate params file by default
- remove template concept, use live file with defaults
- easier implementation, no need to user to rename
- active by default, one source for behaviour
- allow IDE parsing from active file
2021-07-27 14:34:46 -06:00
asif 85ff24faaf refactor(helpers): update domain and path in update script 2021-07-26 02:23:45 -06:00
asif 2e2c93b2b1 feature(helpers): change docker run cmd
- add user specification so UID/GID always specified
- add container default values
2021-07-26 01:36:41 -06:00
asif e208d22664 style(helpers): reformat helper script 2021-07-26 01:30:35 -06:00
asif bc2a34ddd8 feature(helpers): allow specifying tag 2021-07-26 01:20:38 -06:00
asif a3c6656764 fix(helpers): rename shell var in helper script 2021-07-26 00:54:27 -06:00
asif b2582b9bad refactor(helpers): condense TLS section of helper script
Take advantage of container generating DHParams and remove redundant
docker run blocks
2021-07-26 00:49:51 -06:00
asif 1ee8b8bf03 refactor(helpers): remove dhparams mapping from params template 2021-07-26 00:32:48 -06:00
asif 8c5bbe8d9c refactor(helpers): update domain in helper script 2021-07-26 00:29:35 -06:00
asif 60f79fdd45 docs(config): update sites readme file 2021-07-26 00:23:23 -06:00
asif f1faf3fedf feature(generate-cert): allow create self-signed cert
- self-signed cert with a group-readable key and customizable hostname
2021-07-25 19:18:32 -06:00
asif 4ded854631 feature(entrypoint): generate missing dhparam file if needed 2021-07-25 16:00:16 -06:00
asif 8890e662b0 docs(dockerfile): update domain in labels 2021-07-25 15:42:18 -06:00
asif a4cebd5216 fix(dockerfile): remove quotes in maintainer tag 2021-07-25 15:39:36 -06:00
asif f6efb86f2a feature(dockerfile): specify NGINX version via build-arg
- build-arg for NGINX version
- add labels incorporating NGINX version and internal version
- add label to reference GIT commit for tagged release
2021-07-25 15:37:38 -06:00
asif e499b7982c struct(entrypoint): add planned exit codes 2021-07-25 15:13:31 -06:00
asif 1c608859e7 refactor(dockerfile): change healthcheck periods
- reduce interval and increase start-period
- format for clarity
2021-07-25 15:04:22 -06:00
asif 7ea21e2cc4 feature(dockerfile): allow separate UID and GID during build 2021-07-25 15:03:24 -06:00
asif d045d098d9 docs(dockerfile): add deprecated maintainer tag
Harbor still uses this for informational display
2021-07-25 15:02:54 -06:00
asif 287830ffe7 chore(dockerfile): bump internal and nginx version
- update nginx to current
- bump internal version in preparation for new features
2021-07-25 15:02:11 -06:00
10 changed files with 707 additions and 440 deletions
+9 -2
View File
@@ -2,11 +2,18 @@
<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="ERROR" enabled_by_default="true" /> <inspection_tool class="BodyLimit" enabled="true" level="WEAK WARNING" 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="ERROR" enabled_by_default="true" /> <inspection_tool class="SubjectLimit" enabled="true" level="WARNING" 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>
+37 -16
View File
@@ -1,10 +1,17 @@
FROM nginx:mainline-alpine #
# build AB-NGINX container (based on NGINX mainline)
#
# default uid for nginx user ARG NGINX_VERSION=1.21.1
FROM nginx:${NGINX_VERSION}-alpine
ARG NGINX_VERSION
# default uid and gid for nginx user
ARG UID=8080 ARG UID=8080
ARG GID=8080
# create nginx user # create nginx user
RUN addgroup --gid ${UID} www-docker \ RUN addgroup --gid ${GID} www-docker \
&& adduser \ && adduser \
-S \ -S \
-h /home/www-docker \ -h /home/www-docker \
@@ -15,11 +22,13 @@ RUN addgroup --gid ${UID} www-docker \
www-docker www-docker
# add libcap, allow nginx to bind to ports <1024, extract fun error pages & create LetsEncrypt challenge directory outside webroot # add libcap, allow nginx to bind to ports <1024, extract fun error pages & create LetsEncrypt challenge directory outside webroot
RUN apk --no-cache add libcap \ RUN apk --update --no-cache add \
libcap \
openssl \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \ && setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& cd /usr/share/nginx \ && cd /usr/share/nginx \
&& rm -rf html/* \ && rm -rf html/* \
&& wget -O /tmp/errorpages.tar.gz https://git.asifbacchus.app/asif/fun-errorpages/archive/v1.0.tar.gz \ && wget -O /tmp/errorpages.tar.gz https://git.asifbacchus.dev/asif/fun-errorpages/archive/v1.0.tar.gz \
&& tar -xzf /tmp/errorpages.tar.gz -C /tmp \ && tar -xzf /tmp/errorpages.tar.gz -C /tmp \
&& mv /tmp/fun-errorpages/errorpages ./ \ && mv /tmp/fun-errorpages/errorpages ./ \
&& rm -rf /tmp/* \ && rm -rf /tmp/* \
@@ -28,22 +37,29 @@ RUN apk --no-cache add libcap \
&& mkdir /usr/share/nginx/letsencrypt && mkdir /usr/share/nginx/letsencrypt
# health check # health check
HEALTHCHECK --interval=60s --timeout=5s --start-period=30s --retries=3 \ HEALTHCHECK \
--interval=10s \
--timeout=5s \
--start-period=60s \
--retries=3 \
CMD curl --fail http://127.0.0.1:9000/nginx_status || exit 1 CMD curl --fail http://127.0.0.1:9000/nginx_status || exit 1
# standardized labels # standardized labels
LABEL author="Asif Bacchus <asif@bacchus.cloud>" MAINTAINER Asif Bacchus <asif@bacchus.cloud>
LABEL maintainer="Asif Bacchus <asif@bacchus.cloud>" LABEL maintainer="Asif Bacchus <asif@bacchus.cloud>"
LABEL dev.asifbacchus.docker.internalName="ab-nginx"
LABEL org.opencontainers.image.author="Asif Bacchus <asif@bacchus.cloud>" LABEL org.opencontainers.image.author="Asif Bacchus <asif@bacchus.cloud>"
LABEL org.opencontainers.image.url="https://git.asifbacchus.app/ab-docker/ab-nginx" LABEL org.opencontainers.image.url="https://git.asifbacchus.dev/ab-docker/ab-nginx"
LABEL org.opencontainers.image.documentation="https://git.asifbacchus.app/ab-docker/ab-nginx/wiki" LABEL org.opencontainers.image.documentation="https://git.asifbacchus.dev/ab-docker/ab-nginx/wiki"
LABEL org.opencontainers.image.source="https://git.asifbacchus.app/ab-docker/ab-nginx.git" LABEL org.opencontainers.image.source="https://git.asifbacchus.dev/ab-docker/ab-nginx.git"
LABEL org.opencontainers.image.vendor="NGINX" LABEL org.opencontainers.image.vendor="NGINX"
LABEL org.opencontainers.image.title="ab-nginx" LABEL org.opencontainers.image.title="ab-nginx"
LABEL org.opencontainers.image.description="NGINX-mainline-alpine with more logical file location layout and automatic SSL set up if certificates are provided." LABEL org.opencontainers.image.description="NGINX-mainline-alpine with more logical file location layout and automatic SSL set up if certificates are provided."
# copy configuration files # copy configuration files and utility scripts
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /usr/local/bin/entrypoint.sh
COPY generate-cert.sh /usr/local/bin/generate-cert
COPY selfsigned.cnf /etc/selfsigned.cnf
COPY config /etc/nginx/ COPY config /etc/nginx/
COPY sites /etc/nginx/sites/ COPY sites /etc/nginx/sites/
COPY webroot /usr/share/nginx/html/ COPY webroot /usr/share/nginx/html/
@@ -59,7 +75,9 @@ RUN chown -R www-docker:www-docker /usr/share/nginx \
&& find /etc/nginx -type d -exec chmod 750 {} \; \ && find /etc/nginx -type d -exec chmod 750 {} \; \
&& find /etc/nginx -type f -exec chmod 640 {} \; \ && find /etc/nginx -type f -exec chmod 640 {} \; \
&& chown www-docker:www-docker /var/cache/nginx \ && chown www-docker:www-docker /var/cache/nginx \
&& chown www-docker:www-docker /var/log/nginx && chown www-docker:www-docker /var/log/nginx \
&& chmod 644 /etc/selfsigned.cnf \
&& chmod 755 /usr/local/bin/generate-cert /usr/local/bin/entrypoint.sh
USER www-docker USER www-docker
WORKDIR /usr/share/nginx/html WORKDIR /usr/share/nginx/html
@@ -73,7 +91,7 @@ ENV HSTS=FALSE
ENV TLS13_ONLY=FALSE ENV TLS13_ONLY=FALSE
# entrypoint script # entrypoint script
ENTRYPOINT [ "/entrypoint.sh" ] ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
# run NGINX by default # run NGINX by default
STOPSIGNAL SIGQUIT STOPSIGNAL SIGQUIT
@@ -81,8 +99,11 @@ CMD [ "nginx", "-g", "daemon off;" ]
# add build date and version labels # add build date and version labels
ARG BUILD_DATE ARG BUILD_DATE
LABEL org.opencontainers.image.version="1.19.9" ARG GIT_COMMIT
LABEL app.asifbacchus.docker.internalVersion="4.0-1.19.9" ARG INTERNAL_VERSION
LABEL org.opencontainers.image.revision=${GIT_COMMIT}
LABEL org.opencontainers.image.version=${NGINX_VERSION}
LABEL dev.asifbacchus.docker.internalVersion=${INTERNAL_VERSION}-${NGINX_VERSION}
LABEL org.opencontainers.image.created=${BUILD_DATE} LABEL org.opencontainers.image.created=${BUILD_DATE}
#EOF #EOF
+20 -1
View File
@@ -54,8 +54,20 @@ fi
if [ -f "/certs/fullchain.pem" ]; then if [ -f "/certs/fullchain.pem" ]; then
# activate SSL configuration as appropriate and only if certs exist # activate SSL configuration as appropriate and only if certs exist
if [ "$TLS13_ONLY" = 'FALSE' ]; then if [ "$TLS13_ONLY" = 'FALSE' ]; then
if [ -f "/certs/fullchain.pem" ] && [ -f "/certs/privkey.pem" ] && [ -f "/certs/chain.pem" ] && [ -f "/certs/dhparam.pem" ]; then if [ -f "/certs/fullchain.pem" ] && [ -f "/certs/privkey.pem" ] && [ -f "/certs/chain.pem" ]; then
printf "Certificates found. Securing deployment using TLS 1.2\n" printf "Certificates found. Securing deployment using TLS 1.2\n"
# check for dhparam file and generate, if necessary
if ! [ -f "/certs/dhparam.pem" ]; then
printf "Diffie-Hellman Parameters not found... generating (using Digital Signature Algorithm instead of Diffie-Hellman)...\n"
if ! openssl dhparam -dsaparam -out /certs/dhparam.pem 4096; then
printf "\n\nUnable to generate 'dhparam.pem'. Is your '/certs' directory writable by this container?\n"
printf "TLS version 1.2 requires DHParams (or DSAParams) in order to function securely. Exiting.\n\n"
exit 101
fi
printf "\nDSA-Params generated successfully\n"
fi
# activate shared SSL configuration file # activate shared SSL configuration file
if [ -f "/etc/nginx/ssl-config/mozIntermediate_ssl.conf.disabled" ]; then if [ -f "/etc/nginx/ssl-config/mozIntermediate_ssl.conf.disabled" ]; then
mv /etc/nginx/ssl-config/mozIntermediate_ssl.conf.disabled \ mv /etc/nginx/ssl-config/mozIntermediate_ssl.conf.disabled \
@@ -123,4 +135,11 @@ fi
printf "\nSetup complete...Container ready...\n" printf "\nSetup complete...Container ready...\n"
exec "$@" exec "$@"
# exit return codes
# 10x certificate generation errors
# 101 unable to generate DSA-parameters
# 102 unable to generate private key
# 103 unable to generate self-signed certificate
#EOF #EOF
+48
View File
@@ -0,0 +1,48 @@
#!/bin/sh
#
# generate a self-signed certificate
#
# check for null hostname
if [ -z "$1" ]; then
printf "\nPlease supply a hostname for the generated certificate as a parameter to this script. Exiting.\n\n"
exit 1
fi
# update openssl configuration file
sed -e "s/{CERT_HOSTNAME}/$1/" /etc/selfsigned.cnf > /tmp/selfsigned.cnf
printf "\nGenerating self-signed certificate for '%s':\n" "$1"
# create placeholder files to set permissions
if ! touch /certs/fullchain.pem && chmod 644 /certs/fullchain.pem; then
printf "\nUnable to write to '/certs', is it mounted writable by this container?\n\n"
exit 2
fi
touch /certs/privkey.pem && chmod 640 /certs/privkey.pem
# generate certificate
if ! openssl req -new -x509 -days 365 -nodes -out /certs/fullchain.pem -keyout /certs/privkey.pem -config /tmp/selfsigned.cnf; then
printf "\nUnable to generate certificate. Is the '/certs' directory writable by this container?\n\n"
exit 3
fi
\cp /certs/fullchain.pem /certs/chain.pem
# print user notification
printf "\n\nA self-signed certificate has been generated and saved in the location mounted to '/certs' in this container.\n"
printf "The certificate and private key are PEM formatted with names 'fullchain.pem' and 'privkey.pem', respectively.\n"
printf "Remember to import 'fullchain.pem' to the trusted store on any client machines or you will get warnings.\n\n"
# exit gracefully
exit 0
#
# exit codes
# 0: normal exit, no errors
# 1: invalid or missing parameters
# 2: unable to write to certs directory
# 3: unable to generate certificate
#EOF
+16
View File
@@ -0,0 +1,16 @@
default_bits = 4096
default_md = sha256
distinguished_name = dn
req_extensions = san
x509_extensions = san
prompt = no
[dn]
organizationName = AB-NGINX Webserver
CN = {CERT_HOSTNAME}
[san]
subjectAltName = @alt_names
[alt_names]
DNS.1 = {CERT_HOSTNAME}
+28
View File
@@ -0,0 +1,28 @@
#!/bin/sh
#
# generate checksums from provided path suitable for use by 'update.sh'
#
# check for missing path to helper files, otherwise strip trailing slash
if [ -z "$1" ]; then
printf "\nPlease supply path to helper files. Exiting.\n\n"
exit 1
fi
srcDir="${1%/}"
# verify path exists and is accessible
if ! [ -d "$srcDir" ]; then
printf "\nUnable to find or read supplied path to helper files. Exiting.\n\n"
exit 1
fi
# generate checksum file
\rm -f "${srcDir}/checksums.sha256"
find "${srcDir}/" -type f -exec sha256sum {} + >>"${srcDir}/checksums.sha256"
sed -i "s+$srcDir/++g" "${srcDir}/checksums.sha256"
# exit gracefully
exit 0
#EOF
+37 -18
View File
@@ -6,6 +6,23 @@
### ###
#
# Container options
#
# Specify a particular tag to 'version pin' the ab-nginx container.
TAG=latest
# Specify a runtime UID and GID for the container user. This is useful to
# ensure the container can read and/or write to locations on the host or
# has access to files shared between members of a container stack.
# REQUIRED: NO
# DEFAULT: NGINX_UID=8080, NGINX_GID=8080
# VALID OPTIONS: any permissible and available UID/GID value
NGINX_UID=8080
NGINX_GID=8080
# #
# Network options # Network options
# #
@@ -16,7 +33,7 @@
# REQUIRED: NO # REQUIRED: NO
# DEFAULT: nginx_network # DEFAULT: nginx_network
# VALID OPTIONS: network names acceptable to the docker engine # VALID OPTIONS: network names acceptable to the docker engine
#NETWORK=nginx_network NETWORK=nginx_network
# If you want to specify a particular IP subnet for the network to be created # 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 # as per the above variable, specify it here. Again, if you don't know what
@@ -24,7 +41,7 @@
# REQUIRED: NO # REQUIRED: NO
# DEFAULT: '172.31.254.0/24' # DEFAULT: '172.31.254.0/24'
# VALID OPTIONS: subnet in CIDR format # VALID OPTIONS: subnet in CIDR format
#SUBNET='172.31.254.0/24' SUBNET='172.31.254.0/24'
# #
@@ -38,7 +55,7 @@
# REQUIRED: NO # REQUIRED: NO
# DEFAULT: Etc/UTC # DEFAULT: Etc/UTC
# VALID OPTIONS: IANA time zones in TZ format # VALID OPTIONS: IANA time zones in TZ format
#TZ=Etc/UTC TZ=Etc/UTC
# #
@@ -55,7 +72,8 @@
# #
# REQUIRED: YES, if using SSL and default server-blocks # REQUIRED: YES, if using SSL and default server-blocks
# DEFAULT: "_" # DEFAULT: "_"
#HOSTNAMES="domain.tld www.domain.tld server.domain.tld alt.domain.tld" # EXAMPLE: HOSTNAMES="domain.tld www.domain.tld server.domain.tld alt.domain.tld"
HOSTNAMES="_"
# Ports to listen on: # Ports to listen on:
# If you need to use ports other than HTTP=80 and HTTPS=443, remember to set up # If you need to use ports other than HTTP=80 and HTTPS=443, remember to set up
@@ -65,8 +83,8 @@
# you use here. # you use here.
# REQUIRED: NO # REQUIRED: NO
# DEFAULTS: 80 and 443, respectively # DEFAULTS: 80 and 443, respectively
#HTTP_PORT=80 HTTP_PORT=80
#HTTPS_PORT=443 HTTPS_PORT=443
# Access logging (global preference): # Access logging (global preference):
# Unless overridden in a server/location block, access logging will be handled # Unless overridden in a server/location block, access logging will be handled
@@ -74,7 +92,7 @@
# REQUIRED: NO # REQUIRED: NO
# DEFAULT: OFF # DEFAULT: OFF
# VALID OPTIONS: 'ON' or 'OFF' # VALID OPTIONS: 'ON' or 'OFF'
#ACCESS_LOG=OFF ACCESS_LOG=OFF
# #
@@ -89,7 +107,7 @@
# Only files with a ".conf" extension will be loaded! If you want to disable a # Only files with a ".conf" extension will be loaded! If you want to disable a
# file, simply change its extension (i.e. '.conf.disabled'). # file, simply change its extension (i.e. '.conf.disabled').
# #
# REMEMBER: Your configuration files must be readable by UID 8080! # REMEMBER: Your configuration files must be readable by the container UID/GID!
CONFIG_DIR=$(pwd)/config CONFIG_DIR=$(pwd)/config
# Specify a directory containing your NGINX server-block configurations (if any) # Specify a directory containing your NGINX server-block configurations (if any)
@@ -103,7 +121,7 @@ CONFIG_DIR=$(pwd)/config
# Only files with a ".conf" extension will be loaded! If you want to disable a # Only files with a ".conf" extension will be loaded! If you want to disable a
# file, simply change its extension (i.e. '.conf.disabled'). # file, simply change its extension (i.e. '.conf.disabled').
# #
# REMEMBER: Your server-block files must be readable by UID 8080! # REMEMBER: Your server-block files must be readable by the container UID/GID!
SERVERS_DIR=$(pwd)/sites SERVERS_DIR=$(pwd)/sites
# Specify a directory containing 'snippets' of NGINX code you want/need to # Specify a directory containing 'snippets' of NGINX code you want/need to
@@ -114,11 +132,11 @@ SERVERS_DIR=$(pwd)/sites
# instead of having to type the same thing many times. # instead of having to type the same thing many times.
# This is totally optional! Comment this variable to disable it. # This is totally optional! Comment this variable to disable it.
# REMEMBER: Your snippets must be readable by UID 8080! # REMEMBER: Your snippets must be readable by the container UID/GID!
SNIPPETS_DIR=$(pwd)/snippets SNIPPETS_DIR=$(pwd)/snippets
# Specify a directory with the content you want to serve. # Specify a directory with the content you want to serve.
# REMEMBER: This directory must be readable by UID 8080! # REMEMBER: This directory must be readable by the container UID/GID!
WEBROOT_DIR=/var/www WEBROOT_DIR=/var/www
@@ -131,26 +149,27 @@ WEBROOT_DIR=/var/www
# REQUIRED: NO # REQUIRED: NO
# DEFAULT: FALSE # DEFAULT: FALSE
# VALID OPTIONS: 'TRUE', 'FALSE' # VALID OPTIONS: 'TRUE', 'FALSE'
#HSTS=FALSE HSTS=FALSE
# TLS 1.3 mode: # TLS 1.3 mode:
# If 'FALSE' (default), NGINX will accept both TLS 1.2 and 1.3 connections. # If 'FALSE' (default), NGINX will accept both TLS 1.2 and 1.3 connections.
# If 'TRUE', only TLS 1.3 connections will be accepted. # If 'TRUE', only TLS 1.3 connections will be accepted.
#TLS13_ONLY=FALSE TLS13_ONLY=FALSE
# #
# Certificate files # Certificate files
# #
# If you are mounting symlinks you MUST specify the full path of the symlink so # 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 # the target is resolved!
# if using TLS 1.2.
# #
# REMEMBER: ALL files must be readble by UID 8080! # REMEMBER: ALL files must be readable by container UID/GID!
# EXAMPLES:
# SSL_CERT=/path/to/your/ssl-certificate/fullchain.pem # SSL_CERT=/path/to/your/ssl-certificate/fullchain.pem
# SSL_KEY=/path/to/your/ssl-private-key/privkey.pem # SSL_KEY=/path/to/your/ssl-private-key/privkey.pem
# SSL_CHAIN=/path/to/your/ssl-certificate-chain/chain.pem # SSL_CHAIN=/path/to/your/ssl-certificate-chain/chain.pem
#DH=/path/to/your/diffie-hellman-parameters-file/dhparam.pem SSL_CERT=""
SSL_KEY=""
SSL_CHAIN=""
#EOF #EOF
+196 -120
View File
@@ -4,6 +4,7 @@
# start ab-nginx container using params file variables # start ab-nginx container using params file variables
# #
#
# 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)
@@ -21,57 +22,82 @@ else
width=80 width=80
fi fi
### parameter defaults #
shell=false # parameter defaults
doShell=false
doStatus=false
doStop=false
removeStopped=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'
HTTP_PORT=80 HTTP_PORT=80
HTTPS_PORT=443 HTTPS_PORT=443
unset CONFIG_DIR CONFIG_DIR=""
unset SERVERS_DIR SERVERS_DIR=""
unset WEBROOT_DIR WEBROOT_DIR=""
unset vmount volumeMounts=""
stopErr=0
### functions removeErr=0
#
# functions
checkExist() { checkExist() {
if [ "$1" = 'file' ]; then if [ "$1" = 'file' ]; then
if [ ! -f "$2" ]; then if [ ! -f "$2" ]; then
printf "%s\nCannot find file: '$2'. Exiting.\n%s" "$err" "$norm" printf "%s\nCannot find file: '$2'. Exiting.\n%s" "$err" "$norm"
exit 3 exit 1
fi fi
elif [ "$1" = 'dir' ]; then elif [ "$1" = 'dir' ]; then
if [ ! -d "$2" ]; then if [ ! -d "$2" ]; then
printf "%s\nCannot find directory: '$2'. Exiting.\n$%s" "$err" "$norm" printf "%s\nCannot find directory: '$2'. Exiting.\n$%s" "$err" "$norm"
exit 3 exit 1
fi fi
fi fi
return 0 return 0
} }
scriptHelp() { scriptHelp() {
printf "\n%s%1000s\n" "$magenta" | tr " " "-" | cut -c -$width # header and description
printf "%s" "$norm" printf "\n%s" "$magenta"
textblock "This is a simple helper script so you can avoid typing lengthy commands when working with the ab-nginx container." printf '%.0s-' $(seq "$width")
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." 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 "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 "Note: Containers (except shell) are always set to restart 'unless-stopped'. You must remove them manually if desired." # explanatory text
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."
printf "%s" "$magenta" printf "%s" "$magenta"
newline newline
textblock "The script has the following (optional) parameters:"
textblockParam 'parameter in cyan' 'default in yellow' # parameters
textBlock "The script has the following (optional) parameters:"
textBlockParam 'parameter in cyan' 'default in yellow'
newline newline
textblockParam '-n|--name' 'ab-nginx' textBlockParam '-n|--name' 'ab-nginx'
textblock "Change the name of the container. This is cosmetic and does not affect operation in any way." textBlock "Set the name of the container, otherwise the default will be used."
newline
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."
newline
textBlockParam '--status'
textBlock "Run a search for all AB-NGINX containers and display their name and status."
newline
textBlockParam '--stop'
textBlock "Stops the container specified by the '--name' parameter or with the default name 'ab-nginx'."
newline
textBlockParam '--remove | --stop-remove'
textBlock "Stops and removes the container specified by the '--name' parameter or with the default name 'ab-nginx'."
# footer
newline newline
textblockParam '-s|--shell' 'off: run in detached mode'
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 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
} }
@@ -79,11 +105,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"
@@ -93,7 +119,8 @@ textblockParam() {
fi fi
} }
### pre-requisite checks #
# pre-requisite checks
# is docker installed? # is docker installed?
if ! command -v docker >/dev/null; then if ! command -v docker >/dev/null; then
@@ -105,14 +132,106 @@ fi
if [ ! "$(id -u)" -eq 0 ]; then if [ ! "$(id -u)" -eq 0 ]; then
if ! id -Gn | grep docker >/dev/null; then if ! id -Gn | grep docker >/dev/null; then
printf "%s\nYou must either be root or in the 'docker' group to run this script since you must be able to actually start the container! Exiting.\n$%s" "$err" "$norm" printf "%s\nYou must either be root or in the 'docker' group to run this script since you must be able to actually start the container! Exiting.\n$%s" "$err" "$norm"
exit 2 exit 3
fi fi
fi fi
#
# process startup parameters
while [ $# -gt 0 ]; do
case "$1" in
-h | -\? | --help)
# display help
scriptHelp
exit 0
;;
-s | --shell)
# start shell instead of default CMD
doShell=true
;;
-n | --name)
# container name
if [ -z "$2" ]; then
printf "%s\nNo container name specified. Exiting.\n%s" "$err" "$norm"
exit 1
fi
container_name="$2"
shift
;;
--status)
# find containers and check their status
doStatus=true
;;
--stop)
# stop named container
doStop=true
;;
--remove | --stop-remove)
# stop and remove named container
doStop=true
removeStopped=true
;;
*)
printf "%s\nUnknown option: %s\n" "$err" "$1"
printf "Use '--help' for valid options.\n\n%s" "$norm"
exit 1
;;
esac
shift
done
#
# status check
if [ "$doStatus" = "true" ]; then
printf "\nFound the following AB-NGINX containers:\n"
docker ps -a --filter "label=dev.asifbacchus.docker.internalName=ab-nginx"
printf "\n"
exit 0
fi
#
# stop container
if [ "$doStop" = "true" ]; then
printf "\nStopping container '%s'... " "$container_name"
# ensure container exists
if ! docker inspect "$container_name" >/dev/null 2>&1; then
printf "[ERROR]: No container with that name found.\n\n"
exit 11
fi
# stop and/or remove container
if ! docker stop "$container_name" >/dev/null 2>&1; then stopErr=1; fi
if [ "$removeStopped" = "true" ] && [ "$stopErr" -eq 0 ]; then
if ! docker rm "$container_name" >/dev/null 2>&1; then removeErr=1; fi
fi
# update status message
if [ "$stopErr" -eq 1 ]; then
printf "[ERROR]: Unable to stop container. Please try removing it manually.\n\n"
exit 12
fi
if [ "$removeErr" -eq 1 ]; then
printf "[STOPPED]\n"
printf "[ERROR]: Unable to remove container. Please try removing it manually.\n\n"
exit 13
fi
if [ "$removeStopped" = "true" ]; then
printf "[REMOVED]\n\n"
else
printf "[STOPPED]\n\n"
fi
exit 0
fi
#
# run container
# does the params file exist? # does the params file exist?
checkExist 'file' './ab-nginx.params' checkExist 'file' './ab-nginx.params'
# read .params file # read .params file
# shellcheck source=ab-nginx.params.template
. "./ab-nginx.params" . "./ab-nginx.params"
# fix case of TLS13_ONLY var # fix case of TLS13_ONLY var
@@ -125,16 +244,6 @@ 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"
@@ -152,53 +261,23 @@ fi
# set up volume mounts # set up volume mounts
if [ "$CONFIG_DIR" ]; then if [ "$CONFIG_DIR" ]; then
vmount="$vmount -v $CONFIG_DIR:/etc/nginx/config" volumeMounts="${volumeMounts} -v $CONFIG_DIR:/etc/nginx/config"
fi fi
if [ "$SERVERS_DIR" ]; then if [ "$SERVERS_DIR" ]; then
vmount="$vmount -v $SERVERS_DIR:/etc/nginx/sites" volumeMounts="${volumeMounts} -v $SERVERS_DIR:/etc/nginx/sites"
fi fi
if [ "$SNIPPETS_DIR" ]; then if [ "$SNIPPETS_DIR" ]; then
vmount="$vmount -v $SNIPPETS_DIR:/etc/nginx/snippets" volumeMounts="${volumeMounts} -v $SNIPPETS_DIR:/etc/nginx/snippets"
fi fi
if [ "$WEBROOT_DIR" ]; then if [ "$WEBROOT_DIR" ]; then
vmount="$vmount -v $WEBROOT_DIR:/usr/share/nginx/html" volumeMounts="${volumeMounts} -v $WEBROOT_DIR:/usr/share/nginx/html"
fi fi
# trim leading whitespace # trim leading whitespace
vmount=${vmount##[[:space:]]} volumeMounts=${volumeMounts##[[:space:]]}
# handle null HOSTNAMES # handle null HOSTNAMES
if [ -z "$HOSTNAMES" ]; then HOSTNAMES="_"; fi if [ -z "$HOSTNAMES" ]; then HOSTNAMES="_"; fi
# process startup parameters
while [ $# -gt 0 ]; do
case "$1" in
-h | -\? | --help)
# display help
scriptHelp
exit 0
;;
-s | --shell)
# start shell instead of default CMD
shell=true
;;
-n | --name)
# container name
if [ -z "$2" ]; then
printf "%s\nNo container name specified. Exiting.\n%s" "$err" "$norm"
exit 1
fi
container_name="$2"
shift
;;
*)
printf "%s\nUnknown option: %s\n" "$err" "$1"
printf "Use '--help' for valid options.\n\n%s" "$norm"
exit 1
;;
esac
shift
done
# create network if it doesn't already exist # create network if it doesn't already exist
docker network inspect ${NETWORK} >/dev/null 2>&1 || docker network inspect ${NETWORK} >/dev/null 2>&1 ||
docker network create \ docker network create \
@@ -209,91 +288,88 @@ 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 [ $shell = 'true' ]; then if [ "$doShell" = '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 \ ${volumeMounts} \
--network=${NETWORK} \ --network=${NETWORK} \
-p ${HTTP_PORT}:80 \ -p ${HTTP_PORT}:80 \
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh docker.asifbacchus.dev/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 \ ${volumeMounts} \
--network=${NETWORK} \ --network=${NETWORK} \
-p ${HTTP_PORT}:80 \ -p ${HTTP_PORT}:80 \
--restart unless-stopped \ --restart unless-stopped \
docker.asifbacchus.app/nginx/ab-nginx:latest docker.asifbacchus.dev/nginx/ab-nginx:${TAG:-latest}
fi fi
# run with TLS1.2 # run with TLS
elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'FALSE' ]; then else
if [ $shell = 'true' ]; then if [ "$doShell" = 'true' ]; then
# exec shell if [ "$TLS13_ONLY" = 'FALSE' ]; then
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"
docker run --rm -it --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 \
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
else 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" 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" \ -e SERVER_NAMES="$HOSTNAMES" \
$vmount \ ${volumeMounts} \
--network=${NETWORK} \ --network=${NETWORK} \
-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 \
-p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \ -p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh docker.asifbacchus.dev/nginx/ab-nginx:${TAG:-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 \ ${volumeMounts} \
--network=${NETWORK} \ --network=${NETWORK} \
-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 \
-p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \ -p ${HTTP_PORT}:80 -p ${HTTPS_PORT}:443 \
--restart unless-stopped \ --restart unless-stopped \
docker.asifbacchus.app/nginx/ab-nginx:latest docker.asifbacchus.dev/nginx/ab-nginx:${TAG:-latest}
fi fi
fi fi
### exit gracefully #
exit 0 # exit with code from docker
exit "$?"
#
# exit return codes
# 0: normal exit, no errors
# 1: missing or invalid parameter
# 2: cannot find docker
# 3: incorrect permissions to access docker
# 1x: operation errors
# 11 no container found with specified name
# 12 unable to stop container
# 13 unable to remove container
# other refer to docker exit codes
#EOF
+2 -2
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 test pages included in the container by - this bind-mount will override the default server configurations
default. included in the container by 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,
+62 -29
View File
@@ -1,14 +1,16 @@
#!/bin/sh #!/bin/sh
### update script for ab-nginx container and utility scripts #
# version 2.0.0 # update script for ab-nginx container and utility scripts
# version 2.1.0
# script by Asif Bacchus # script by Asif Bacchus
### #
### functions #
# functions
errMsg() { errMsg() {
printf "\n%s%s%s\n\n" "$err" "$1" "$norm" printf "\n%s%s%s\n\n" "$err" "$1" "$norm"
exit 1 [ -n "$2" ] && exit "$2" || exit 1
} }
errNotify() { errNotify() {
@@ -25,27 +27,27 @@ okNotify() {
scriptHelp() { scriptHelp() {
textNewline textNewline
textblock "Update ${containerName} container and helper script files" textBlock "Update ${containerName} container and helper script files"
textblock "${bold}Usage: ${localScriptName} [parameters]${norm}" textBlock "${bold}Usage: ${localScriptName} [parameters]${norm}"
textNewline textNewline
textblock "If run with no parameters, the script will update both the container and the helper script files, including this update script." textBlock "If run with no parameters, the script will update both the container and the helper script files, including this update script."
textblockHeader " parameters " textBlockHeader " parameters "
textblockParam "-h|-?|--help" "Display this help screen." textBlockParam "-h|-?|--help" "Display this help screen."
textblockParam "-c|--container|--container-only" "Update the docker container only." textBlockParam "-c|--container|--container-only" "Update the docker container only."
textblockParam "-s|--scripts|--scripts-only" "Update the helper scripts (including this update script) only." textBlockParam "-s|--scripts|--scripts-only" "Update the helper scripts (including this update script) only."
textNewline textNewline
exit 0 exit 0
} }
textblock() { textBlock() {
printf "%s\n" "$1" | fold -w "$width" -s printf "%s\n" "$1" | fold -w "$width" -s
} }
textblockHeader() { textBlockHeader() {
printf "\n%s***%s***%s\n" "$header" "$1" "$norm" printf "\n%s***%s***%s\n" "$header" "$1" "$norm"
} }
textblockParam() { textBlockParam() {
printf "%s%-35s%s%s\n" "$info" "$1" "$2" "$norm" printf "%s%-35s%s%s\n" "$info" "$1" "$2" "$norm"
} }
@@ -53,7 +55,8 @@ textNewline() {
printf "\n" printf "\n"
} }
### text formatting presets #
# text formatting presets
if command -v tput >/dev/null 2>&1; then if command -v tput >/dev/null 2>&1; then
bold=$(tput bold) bold=$(tput bold)
err=$(tput bold)$(tput setaf 1) err=$(tput bold)$(tput setaf 1)
@@ -74,7 +77,8 @@ else
width=80 width=80
fi fi
### pre-requisites #
# pre-requisites
# check if wget is installed # check if wget is installed
if ! command -v wget >/dev/null 2>&1; then if ! command -v wget >/dev/null 2>&1; then
errMsg "Sorry, this script requires that 'wget' is installed in order to download updates. Exiting." errMsg "Sorry, this script requires that 'wget' is installed in order to download updates. Exiting."
@@ -90,8 +94,8 @@ updateSuccess=0
# reference constants # reference constants
dockerNamespace='nginx' dockerNamespace='nginx'
containerName='ab-nginx' containerName='ab-nginx'
containerUpdatePath="docker.asifbacchus.app/$dockerNamespace/$containerName:latest" containerUpdatePath="docker.asifbacchus.dev/$dockerNamespace/$containerName:latest"
server="https://asifbacchus.app/updates/docker/$dockerNamespace/$containerName/" server="https://asifbacchus.dev/public/docker/$dockerNamespace/$containerName/"
checksumFilename='checksums.sha256' checksumFilename='checksums.sha256'
# operation triggers # operation triggers
@@ -102,7 +106,8 @@ doScriptUpdate=1
localScriptName="$(basename "$0")" localScriptName="$(basename "$0")"
repoScriptName='update.sh' repoScriptName='update.sh'
### process startup parameters #
# process startup parameters
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
-h | -\? | --help) -h | -\? | --help)
@@ -126,29 +131,31 @@ while [ $# -gt 0 ]; do
shift shift
done done
### update container #
# update container
if [ "$doDockerUpdate" -eq 1 ]; then if [ "$doDockerUpdate" -eq 1 ]; then
# check if docker is installed # check if docker is installed
if ! command -v docker >/dev/null 2>&1; then if ! command -v docker >/dev/null 2>&1; then
errMsg "Sorry, it appears that docker is not installed on this machine! Exiting." errMsg "Sorry, it appears that docker is not installed on this machine! Exiting." 2
fi fi
# is user root or in the docker group? # is user root or in the docker group?
if [ ! "$(id -u)" -eq 0 ]; then if [ ! "$(id -u)" -eq 0 ]; then
if ! id -Gn | grep docker >/dev/null; then if ! id -Gn | grep docker >/dev/null; then
errMsg "You must either be root or in the 'docker' group to pull container updates." errMsg "You must either be root or in the 'docker' group to pull container updates." 2
fi fi
fi fi
printf "%s\n*** Updating %s container ***\n\n%s" "$info" "$containerName" "$norm" printf "%s\n*** Updating %s container ***\n\n%s" "$info" "$containerName" "$norm"
if ! docker pull "$containerUpdatePath"; then if ! docker pull "$containerUpdatePath"; then
errMsg "There was an error updating the container. Try again later." errMsg "There was an error updating the container. Try again later." 31
else else
okMsg "Container updated!" okMsg "Container updated!"
fi fi
fi fi
### update scripts #
# update scripts
if [ "$doScriptUpdate" -eq 1 ]; then if [ "$doScriptUpdate" -eq 1 ]; then
printf "%s*** Updating %s service scripts ***%s\n" "$info" "$containerName" "$norm" printf "%s*** Updating %s service scripts ***%s\n" "$info" "$containerName" "$norm"
@@ -156,7 +163,7 @@ if [ "$doScriptUpdate" -eq 1 ]; then
printf "Getting latest checksums... " printf "Getting latest checksums... "
if ! wget --quiet --tries=3 --timeout=10 -N "${server}${checksumFilename}"; then if ! wget --quiet --tries=3 --timeout=10 -N "${server}${checksumFilename}"; then
errNotify errNotify
errMsg "Unable to download checksums. Try again later." errMsg "Unable to download checksums. Try again later." 41
else else
okNotify okNotify
fi fi
@@ -175,7 +182,7 @@ if [ "$doScriptUpdate" -eq 1 ]; then
errNotify errNotify
# delete failed download as necessary # delete failed download as necessary
rm -f ./update.sh.tmp 2>/dev/null rm -f ./update.sh.tmp 2>/dev/null
errMsg "Unable to download script update. Try again later." errMsg "Unable to download script update. Try again later." 42
else else
# verify download # verify download
dlScriptChecksum=$(sha256sum "update.sh.tmp" | grep -o '^\S*') dlScriptChecksum=$(sha256sum "update.sh.tmp" | grep -o '^\S*')
@@ -183,7 +190,7 @@ if [ "$doScriptUpdate" -eq 1 ]; then
printf "[ERROR]\n" printf "[ERROR]\n"
# delete corrupt download as necessary # delete corrupt download as necessary
rm -f ./update.sh.tmp 2>/dev/null rm -f ./update.sh.tmp 2>/dev/null
errMsg "Checksum mismatch! Try again later." errMsg "Checksum mismatch! Try again later." 42
else else
okNotify okNotify
printf "\n%s*** This script has been updated. Please re-run it to load the updated version of this file. ***%s\n\n" "$warn" "$norm" printf "\n%s*** This script has been updated. Please re-run it to load the updated version of this file. ***%s\n\n" "$warn" "$norm"
@@ -239,7 +246,8 @@ if [ "$doScriptUpdate" -eq 1 ]; then
done <"$checksumFilename" done <"$checksumFilename"
fi fi
### display results #
# display results
if [ "$doScriptUpdate" -eq 1 ]; then if [ "$doScriptUpdate" -eq 1 ]; then
printf "\n%s*** Results ***%s\n" "$info" "$norm" printf "\n%s*** Results ***%s\n" "$info" "$norm"
printf "\tUpdates: %s available\n" "$updatesAvailable" printf "\tUpdates: %s available\n" "$updatesAvailable"
@@ -247,4 +255,29 @@ if [ "$doScriptUpdate" -eq 1 ]; then
printf "\tUpdates: %s%s applied%s, %s%s failed%s\n" "$ok" "$updateSuccess" "$norm" "$err" "$updateFailed" "$norm" printf "\tUpdates: %s%s applied%s, %s%s failed%s\n" "$ok" "$updateSuccess" "$norm" "$err" "$updateFailed" "$norm"
fi fi
#
# exit
if [ "$downloadFailed" -gt 0 ]; then
exit 43
elif [ "$updateFailed" -gt 0 ]; then
exit 44
else
exit 0 exit 0
fi
# this is a trap for mis-coding... should never get an exit code 99!
exit 99
#
# exit return codes
# 0: normal exit, no errors
# 1: missing or invalid parameter
# 2: docker not found or no docker permissions
# 31: unable to update docker container
# 4x: helper files errors
# 41: unable to download checksums
# 42: update script: unable to download or bad checksum
# 43: update helpers: unable to download
# 44: update helpers: bad checksum, no update
# 99: coding mistake trap -- this return code should never happen!
#EOF