Skip to content

Commit b115f70

Browse files
committed
Cleanup: Fix weird conditional statement syntax
1 parent b335f0e commit b115f70

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ARG DEBUG_BUILD="0"
1717
ENV DO_DEBUG_BUILD="$DEBUG_BUILD"
1818

1919
# Build mitmproxy via pip. This is heavy, takes minutes do build and creates a 90mb+ layer. Oh well.
20-
RUN [[ "a$DO_DEBUG_BUILD" == "a1" ]] && { echo "Debug build ENABLED." \
20+
RUN [ "$DO_DEBUG_BUILD" = "1" ] && { echo "Debug build ENABLED." \
2121
&& apk add --no-cache --update su-exec git g++ libffi libffi-dev libstdc++ openssl-dev python3 python3-dev py3-pip py3-wheel py3-six py3-idna py3-certifi py3-setuptools \
2222
&& LDFLAGS=-L/lib pip install mitmproxy==5.2 \
2323
&& apk del --purge git g++ libffi-dev openssl-dev python3-dev py3-pip py3-wheel \
@@ -28,7 +28,7 @@ RUN [[ "a$DO_DEBUG_BUILD" == "a1" ]] && { echo "Debug build ENABLED." \
2828
ENV LANG=en_US.UTF-8
2929

3030
# Check the installed mitmproxy version, if built.
31-
RUN [[ "a$DO_DEBUG_BUILD" == "a1" ]] && { mitmproxy --version && mitmweb --version ; } || { echo "Debug build disabled."; }
31+
RUN [ "$DO_DEBUG_BUILD" = "1" ] && { mitmproxy --version && mitmweb --version ; } || { echo "Debug build disabled."; }
3232

3333
# Create the cache directory and CA directory
3434
RUN mkdir -p /docker_mirror_cache /ca

entrypoint.sh

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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?
77
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
99
echo "Warning: unable to determine DNS resolvers for nginx" >&2
1010
exit 66
1111
fi
@@ -20,7 +20,7 @@ done
2020

2121
echo "Final chosen resolver: $conf"
2222
confpath=/etc/nginx/resolvers.conf
23-
if [ ! -e $confpath ] || [ "$conf" != "$(cat $confpath)" ]
23+
if [ ! -e "$confpath" ] || [ "$conf" != "$(cat "$confpath")" ]
2424
then
2525
echo "Using auto-determined resolver '$conf' via '$confpath'"
2626
echo "$conf" > $confpath
@@ -55,7 +55,7 @@ echo -n "" > /etc/nginx/docker.targetHost.map
5555
echo -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.
9595
echo -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

133133
echo -e "\nManifest caching config: ---\n"
134134
cat /etc/nginx/nginx.manifest.caching.config.conf
135135
echo "---"
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
}
143144
EOF
144-
else
145-
echo '' > /etc/nginx/conf.d/allowed_override_auth.conf
146145
fi
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;
155154
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
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) {
@@ -196,8 +195,8 @@ fi
196195
# normally use non-debug version of nginx
197196
NGINX_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/ "
216215
fi
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/ "
239238
fi
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
@@ -252,8 +251,8 @@ 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

276275
echo -e "\nTimeout configs: ---"
277276
cat /etc/nginx/nginx.timeouts.config.conf
278277
echo -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."
292291
else
293292
echo "Upstream SSL certificate verification is DISABLED."

0 commit comments

Comments
 (0)