@@ -5,7 +5,7 @@ trap "echo TRAPed signal" HUP INT QUIT TERM
5
5
6
6
# configure nginx DNS settings to match host, why must we do that nginx?
7
7
export 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
9
9
echo " Warning: unable to determine DNS resolvers for nginx" >&2
10
10
exit 66
11
11
fi
20
20
21
21
echo " Final chosen resolver: $conf "
22
22
confpath=/etc/nginx/resolvers.conf
23
- if [ ! -e $confpath ] || [ " $conf " != " $( cat $confpath ) " ]
23
+ if [ ! -e " $confpath " ] || [ " $conf " != " $( cat " $confpath " ) " ]
24
24
then
25
25
echo " Using auto-determined resolver '$conf ' via '$confpath '"
26
26
echo " $conf " > $confpath
@@ -55,7 +55,7 @@ echo -n "" > /etc/nginx/docker.targetHost.map
55
55
echo -n " " > /etc/nginx/docker.auth.map
56
56
57
57
# Only configure auth registries if the env var contains values
58
- if [ " $AUTH_REGISTRIES " ]; then
58
+ if [ -n " $AUTH_REGISTRIES " ]; then
59
59
# Ref: https://stackoverflow.com/a/47633817/219530
60
60
AUTH_REGISTRIES_DELIMITER=${AUTH_REGISTRIES_DELIMITER:- " " }
61
61
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
94
94
# Manifest caching configuration. We generate config based on the environment vars.
95
95
echo -n " " > /etc/nginx/nginx.manifest.caching.config.conf
96
96
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
98
99
# First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
99
100
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
100
101
set \$ docker_proxy_request_type "manifest-primary";
101
102
proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME} ;
102
103
include "/etc/nginx/nginx.manifest.stale.conf";
103
104
}
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
107
107
# Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
108
108
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
109
109
set \$ docker_proxy_request_type "manifest-secondary";
110
110
proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME} ;
111
111
include "/etc/nginx/nginx.manifest.stale.conf";
112
112
}
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
116
115
# Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
117
116
location ~ ^/v2/(.*)/manifests/ {
118
117
set \$ docker_proxy_request_type "manifest-default";
119
118
proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME} ;
120
119
include "/etc/nginx/nginx.manifest.stale.conf";
121
120
}
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
125
124
# Manifest caching is disabled. Enable it with ENABLE_MANIFEST_CACHE=true
126
125
location ~ ^/v2/(.*)/manifests/ {
127
126
set \$ docker_proxy_request_type "manifest-default-disabled";
128
127
proxy_cache_valid 0s;
129
128
include "/etc/nginx/nginx.manifest.stale.conf";
130
129
}
131
- EOD
130
+ EOF
131
+ fi
132
132
133
133
echo -e " \nManifest caching config: ---\n"
134
134
cat /etc/nginx/nginx.manifest.caching.config.conf
135
135
echo " ---"
136
136
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
139
140
if ($http_authorization != "") {
140
141
# override with own authentication if provided
141
142
set $finalAuth $http_authorization;
142
143
}
143
144
EOF
144
- else
145
- echo ' ' > /etc/nginx/conf.d/allowed_override_auth.conf
146
145
fi
147
146
148
- if [[ " a ${ALLOW_PUSH} " == " atrue " ] ]; then
147
+ if [ " ${ALLOW_PUSH} " = " true " ]; then
149
148
cat << EOF > /etc/nginx/conf.d/allowed.methods.conf
150
149
# allow to upload big layers
151
150
client_max_body_size 0;
152
151
153
152
# only cache GET requests
154
153
proxy_cache_methods GET;
155
154
EOF
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
158
157
# Block POST/PUT/DELETE if own authentication is not provided.
159
158
set $combined_ha_rm "$http_authorization$request_method";
160
159
if ($combined_ha_rm = POST) {
196
195
# normally use non-debug version of nginx
197
196
NGINX_BIN=" /usr/sbin/nginx"
198
197
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
201
200
echo " To debug, you need the -debug version of this image, eg: :latest-debug"
202
201
exit 3
203
202
fi
@@ -215,8 +214,8 @@ if [[ "a${DEBUG}" == "atrue" ]]; then
215
214
echo " Access mitmweb via http://127.0.0.1:8081/ "
216
215
fi
217
216
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
220
219
echo " To debug, you need the -debug version of this image, eg: :latest-debug"
221
220
exit 3
222
221
fi
@@ -238,8 +237,8 @@ if [[ "a${DEBUG_HUB}" == "atrue" ]]; then
238
237
echo " Access mitmweb for outgoing DockerHub requests via http://127.0.0.1:8082/ "
239
238
fi
240
239
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
243
242
echo " To debug, you need the -debug version of this image, eg: :latest-debug"
244
243
exit 4
245
244
fi
252
251
253
252
254
253
# 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
257
256
# Timeouts
258
257
259
258
# ngx_http_core_module
@@ -271,23 +270,23 @@ cat <<EOD >>/etc/nginx/nginx.timeouts.config.conf
271
270
proxy_connect_read_timeout ${PROXY_CONNECT_READ_TIMEOUT} ;
272
271
proxy_connect_connect_timeout ${PROXY_CONNECT_CONNECT_TIMEOUT} ;
273
272
proxy_connect_send_timeout ${PROXY_CONNECT_SEND_TIMEOUT} ;
274
- EOD
273
+ EOF
275
274
276
275
echo -e " \nTimeout configs: ---"
277
276
cat /etc/nginx/nginx.timeouts.config.conf
278
277
echo -e " ---\n"
279
278
280
279
# 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
284
283
# We actually wanna be secure and avoid mitm attacks.
285
284
# Fitting, since this whole thing is a mitm...
286
285
# We'll accept any cert signed by a CA trusted by Mozilla (ca-certificates-bundle in alpine)
287
286
proxy_ssl_verify on;
288
287
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
289
288
proxy_ssl_verify_depth 2;
290
- EOD
289
+ EOF
291
290
echo " Upstream SSL certificate verification enabled."
292
291
else
293
292
echo " Upstream SSL certificate verification is DISABLED."
0 commit comments