@@ -5,7 +5,7 @@ trap "echo TRAPed signal" HUP INT QUIT TERM
55
66# configure nginx DNS settings to match host, why must we do that nginx?
77export RESOLVERS=$( awk ' $1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed ' s/ *$//g' )
8- if [ " x $RESOLVERS " = " x " ]; then
8+ if [ -z " $RESOLVERS " ]; then
99 echo " Warning: unable to determine DNS resolvers for nginx" >&2
1010 exit 66
1111fi
2020
2121echo " Final chosen resolver: $conf "
2222confpath=/etc/nginx/resolvers.conf
23- if [ ! -e $confpath ] || [ " $conf " != " $( cat $confpath ) " ]
23+ if [ ! -e " $confpath " ] || [ " $conf " != " $( cat " $confpath " ) " ]
2424then
2525 echo " Using auto-determined resolver '$conf ' via '$confpath '"
2626 echo " $conf " > $confpath
@@ -55,7 +55,7 @@ echo -n "" > /etc/nginx/docker.targetHost.map
5555echo -n " " > /etc/nginx/docker.auth.map
5656
5757# Only configure auth registries if the env var contains values
58- if [ " $AUTH_REGISTRIES " ]; then
58+ if [ -n " $AUTH_REGISTRIES " ]; then
5959 # Ref: https://stackoverflow.com/a/47633817/219530
6060 AUTH_REGISTRIES_DELIMITER=${AUTH_REGISTRIES_DELIMITER:- " " }
6161 s=$AUTH_REGISTRIES$AUTH_REGISTRIES_DELIMITER
@@ -94,67 +94,66 @@ echo "proxy_cache_path /docker_mirror_cache levels=1:2 max_size=$CACHE_MAX_SIZE
9494# Manifest caching configuration. We generate config based on the environment vars.
9595echo -n " " > /etc/nginx/nginx.manifest.caching.config.conf
9696
97- [[ " a${ENABLE_MANIFEST_CACHE} " == " atrue" ]] && [[ " a${MANIFEST_CACHE_PRIMARY_REGEX} " != " a" ]] && cat << EOD >>/etc/nginx/nginx.manifest.caching.config.conf
97+ if [ " ${ENABLE_MANIFEST_CACHE} " = " true" ]; then
98+ [ -n " ${MANIFEST_CACHE_PRIMARY_REGEX} " ] && cat << EOF >>/etc/nginx/nginx.manifest.caching.config.conf
9899 # First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
99100 location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
100101 set \$ docker_proxy_request_type "manifest-primary";
101102 proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME} ;
102103 include "/etc/nginx/nginx.manifest.stale.conf";
103104 }
104- EOD
105-
106- [[ " a${ENABLE_MANIFEST_CACHE} " == " atrue" ]] && [[ " a${MANIFEST_CACHE_SECONDARY_REGEX} " != " a" ]] && cat << EOD >>/etc/nginx/nginx.manifest.caching.config.conf
105+ EOF
106+ [ -n " ${MANIFEST_CACHE_SECONDARY_REGEX} " ] && cat << EOF >>/etc/nginx/nginx.manifest.caching.config.conf
107107 # Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
108108 location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
109109 set \$ docker_proxy_request_type "manifest-secondary";
110110 proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME} ;
111111 include "/etc/nginx/nginx.manifest.stale.conf";
112112 }
113- EOD
114-
115- [[ " a${ENABLE_MANIFEST_CACHE} " == " atrue" ]] && cat << EOD >>/etc/nginx/nginx.manifest.caching.config.conf
113+ EOF
114+ cat << EOF >>/etc/nginx/nginx.manifest.caching.config.conf
116115 # Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
117116 location ~ ^/v2/(.*)/manifests/ {
118117 set \$ docker_proxy_request_type "manifest-default";
119118 proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME} ;
120119 include "/etc/nginx/nginx.manifest.stale.conf";
121120 }
122- EOD
123-
124- [[ " a ${ENABLE_MANIFEST_CACHE} " != " atrue " ]] && cat << EOD >>/etc/nginx/nginx.manifest.caching.config.conf
121+ EOF
122+ else
123+ cat << EOF >>/etc/nginx/nginx.manifest.caching.config.conf
125124 # Manifest caching is disabled. Enable it with ENABLE_MANIFEST_CACHE=true
126125 location ~ ^/v2/(.*)/manifests/ {
127126 set \$ docker_proxy_request_type "manifest-default-disabled";
128127 proxy_cache_valid 0s;
129128 include "/etc/nginx/nginx.manifest.stale.conf";
130129 }
131- EOD
130+ EOF
131+ fi
132132
133133echo -e " \nManifest caching config: ---\n"
134134cat /etc/nginx/nginx.manifest.caching.config.conf
135135echo " ---"
136136
137- if [[ " a${ALLOW_OWN_AUTH} " == " atrue" ]]; then
138- cat << 'EOF ' > /etc/nginx/conf.d/allowed_override_auth.conf
137+ echo -n " " > /etc/nginx/conf.d/allowed_override_auth.conf
138+ if [ " ${ALLOW_OWN_AUTH} " = " true" ]; then
139+ cat << 'EOF ' > /etc/nginx/conf.d/allowed_override_auth.conf
139140 if ($http_authorization != "") {
140141 # override with own authentication if provided
141142 set $finalAuth $http_authorization;
142143 }
143144EOF
144- else
145- echo ' ' > /etc/nginx/conf.d/allowed_override_auth.conf
146145fi
147146
148- if [[ " a ${ALLOW_PUSH} " == " atrue " ] ]; then
147+ if [ " ${ALLOW_PUSH} " = " true " ]; then
149148 cat << EOF > /etc/nginx/conf.d/allowed.methods.conf
150149 # allow to upload big layers
151150 client_max_body_size 0;
152151
153152 # only cache GET requests
154153 proxy_cache_methods GET;
155154EOF
156- elif [[ " a ${ALLOW_PUSH_WITH_OWN_AUTH} " == " atrue " ] ]; then
157- cat << 'EOF ' > /etc/nginx/conf.d/allowed.methods.conf
155+ elif [ " ${ALLOW_PUSH_WITH_OWN_AUTH} " = " true " ]; then
156+ cat << 'EOF ' > /etc/nginx/conf.d/allowed.methods.conf
158157 # Block POST/PUT/DELETE if own authentication is not provided.
159158 set $combined_ha_rm "$http_authorization$request_method";
160159 if ($combined_ha_rm = POST) {
196195# normally use non-debug version of nginx
197196NGINX_BIN=" /usr/sbin/nginx"
198197
199- if [[ " a ${DEBUG} " == " atrue " ] ]; then
200- if [[ ! -f /usr/bin/mitmweb ] ]; then
198+ if [ " ${DEBUG} " = " true " ]; then
199+ if [ ! -f /usr/bin/mitmweb ]; then
201200 echo " To debug, you need the -debug version of this image, eg: :latest-debug"
202201 exit 3
203202 fi
@@ -215,8 +214,8 @@ if [[ "a${DEBUG}" == "atrue" ]]; then
215214 echo " Access mitmweb via http://127.0.0.1:8081/ "
216215fi
217216
218- if [[ " a ${DEBUG_HUB} " == " atrue " ] ]; then
219- if [[ ! -f /usr/bin/mitmweb ] ]; then
217+ if [ " ${DEBUG_HUB} " = " true " ]; then
218+ if [ ! -f /usr/bin/mitmweb ]; then
220219 echo " To debug, you need the -debug version of this image, eg: :latest-debug"
221220 exit 3
222221 fi
@@ -238,8 +237,8 @@ if [[ "a${DEBUG_HUB}" == "atrue" ]]; then
238237 echo " Access mitmweb for outgoing DockerHub requests via http://127.0.0.1:8082/ "
239238fi
240239
241- if [[ " a ${DEBUG_NGINX} " == " atrue " ] ]; then
242- if [[ ! -f /usr/sbin/nginx-debug ] ]; then
240+ if [ " ${DEBUG_NGINX} " = " true " ]; then
241+ if [ ! -f /usr/sbin/nginx-debug ]; then
243242 echo " To debug, you need the -debug version of this image, eg: :latest-debug"
244243 exit 4
245244 fi
252251
253252
254253# Timeout configurations
255- echo " " > /etc/nginx/nginx.timeouts.config.conf
256- cat << EOD >>/etc/nginx/nginx.timeouts.config.conf
254+ echo -n " " > /etc/nginx/nginx.timeouts.config.conf
255+ cat << EOF >>/etc/nginx/nginx.timeouts.config.conf
257256 # Timeouts
258257
259258 # ngx_http_core_module
@@ -271,23 +270,23 @@ cat <<EOD >>/etc/nginx/nginx.timeouts.config.conf
271270 proxy_connect_read_timeout ${PROXY_CONNECT_READ_TIMEOUT} ;
272271 proxy_connect_connect_timeout ${PROXY_CONNECT_CONNECT_TIMEOUT} ;
273272 proxy_connect_send_timeout ${PROXY_CONNECT_SEND_TIMEOUT} ;
274- EOD
273+ EOF
275274
276275echo -e " \nTimeout configs: ---"
277276cat /etc/nginx/nginx.timeouts.config.conf
278277echo -e " ---\n"
279278
280279# Upstream SSL verification.
281- echo " " > /etc/nginx/docker.verify.ssl.conf
282- if [[ " a ${VERIFY_SSL} " == " atrue " ] ]; then
283- cat << EOD > /etc/nginx/docker.verify.ssl.conf
280+ echo -n " " > /etc/nginx/docker.verify.ssl.conf
281+ if [ " ${VERIFY_SSL} " = " true " ]; then
282+ cat << EOF > /etc/nginx/docker.verify.ssl.conf
284283 # We actually wanna be secure and avoid mitm attacks.
285284 # Fitting, since this whole thing is a mitm...
286285 # We'll accept any cert signed by a CA trusted by Mozilla (ca-certificates-bundle in alpine)
287286 proxy_ssl_verify on;
288287 proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
289288 proxy_ssl_verify_depth 2;
290- EOD
289+ EOF
291290 echo " Upstream SSL certificate verification enabled."
292291else
293292 echo " Upstream SSL certificate verification is DISABLED."
0 commit comments