🐛 Fix entrypoint when AUTH_REGISTRIES is empty

pull/16/head
Sebastián Ramírez 2019-08-09 18:53:09 -05:00
parent 4e5e75e91d
commit df8c057855
1 changed files with 27 additions and 24 deletions

View File

@ -34,32 +34,35 @@ export ALLDOMAINS=${ALLDOMAINS:1} # remove the first comma and export
# Now handle the auth part. # Now handle the auth part.
echo -n "" > /etc/nginx/docker.auth.map echo -n "" > /etc/nginx/docker.auth.map
# Ref: https://stackoverflow.com/a/47633817/219530 # Only configure auth registries if the env var contains values
AUTH_REGISTRIES_DELIMITER=${AUTH_REGISTRIES_DELIMITER:-" "} if [ "$AUTH_REGISTRIES" ]; then
s=$AUTH_REGISTRIES$AUTH_REGISTRIES_DELIMITER # Ref: https://stackoverflow.com/a/47633817/219530
auth_array=(); AUTH_REGISTRIES_DELIMITER=${AUTH_REGISTRIES_DELIMITER:-" "}
while [[ $s ]]; do s=$AUTH_REGISTRIES$AUTH_REGISTRIES_DELIMITER
auth_array+=( "${s%%"$AUTH_REGISTRIES_DELIMITER"*}" ); auth_array=();
s=${s#*"$AUTH_REGISTRIES_DELIMITER"};
done
AUTH_REGISTRY_DELIMITER=${AUTH_REGISTRY_DELIMITER:-":"}
for ONEREGISTRY in "${auth_array[@]}"; do
s=$ONEREGISTRY$AUTH_REGISTRY_DELIMITER
registry_array=();
while [[ $s ]]; do while [[ $s ]]; do
registry_array+=( "${s%%"$AUTH_REGISTRY_DELIMITER"*}" ); auth_array+=( "${s%%"$AUTH_REGISTRIES_DELIMITER"*}" );
s=${s#*"$AUTH_REGISTRY_DELIMITER"}; s=${s#*"$AUTH_REGISTRIES_DELIMITER"};
done done
AUTH_HOST="${registry_array[0]}"
AUTH_USER="${registry_array[1]}" AUTH_REGISTRY_DELIMITER=${AUTH_REGISTRY_DELIMITER:-":"}
AUTH_PASS="${registry_array[2]}"
# make base64 not wrap lines: https://superuser.com/a/1225334 for ONEREGISTRY in "${auth_array[@]}"; do
AUTH_BASE64=$(echo -n "${AUTH_USER}:${AUTH_PASS}" | base64 | tr -d \\n ) s=$ONEREGISTRY$AUTH_REGISTRY_DELIMITER
echo "Adding Auth for registry '${AUTH_HOST}' with user '${AUTH_USER}'." registry_array=();
echo "\"${AUTH_HOST}\" \"${AUTH_BASE64}\";" >> /etc/nginx/docker.auth.map while [[ $s ]]; do
done registry_array+=( "${s%%"$AUTH_REGISTRY_DELIMITER"*}" );
s=${s#*"$AUTH_REGISTRY_DELIMITER"};
done
AUTH_HOST="${registry_array[0]}"
AUTH_USER="${registry_array[1]}"
AUTH_PASS="${registry_array[2]}"
# make base64 not wrap lines: https://superuser.com/a/1225334
AUTH_BASE64=$(echo -n "${AUTH_USER}:${AUTH_PASS}" | base64 | tr -d \\n )
echo "Adding Auth for registry '${AUTH_HOST}' with user '${AUTH_USER}'."
echo "\"${AUTH_HOST}\" \"${AUTH_BASE64}\";" >> /etc/nginx/docker.auth.map
done
fi
echo "" > /etc/nginx/docker.verify.ssl.conf echo "" > /etc/nginx/docker.verify.ssl.conf
if [[ "a${VERIFY_SSL}" == "atrue" ]]; then if [[ "a${VERIFY_SSL}" == "atrue" ]]; then