Skip to content

Instantly share code, notes, and snippets.

@jamiejackson
Last active October 25, 2022 17:31
Show Gist options
  • Save jamiejackson/284b309a89d9966852d77a811ca8189b to your computer and use it in GitHub Desktop.
Save jamiejackson/284b309a89d9966852d77a811ca8189b to your computer and use it in GitHub Desktop.
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
setting 'cloudfront_access_token' var
${HOSTNAME} ${HOME} ${PKG_RELEASE} ${cloudfront_access_token} ${NGINX_VERSION} ${PATH} ${NJS_VERSION} ${PWD}
/docker-entrypoint.d/20-envsubst-on-templates.sh: 37: 3: Bad file descriptor
#!/bin/sh
set -e
# HUDX customization: convert secrets to env vars
for pathname in /run/secrets/* ; do
filename=$(basename $pathname)
if [ -f "$pathname" ]; then
val=$(cat "${pathname}")
echo "setting '$filename' var"
export "$filename"="$val"
fi
done
# end HUDX customization
ME=$(basename $0)
auto_envsubst() {
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
local template defined_envs relative_path output_path subdir
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
echo "$defined_envs"
[ -d "$template_dir" ] || return 0
if [ ! -w "$output_dir" ]; then
echo >&3 "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
return 0
fi
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
relative_path="${template#$template_dir/}"
output_path="$output_dir/${relative_path%$suffix}"
subdir=$(dirname "$relative_path")
# create a subdirectory where the template file exists
mkdir -p "$output_dir/$subdir"
echo >&3 "$ME: Running envsubst on $template to $output_path"
envsubst "$defined_envs" < "$template" > "$output_path"
done
}
auto_envsubst
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment