This repository has been archived on 2022-10-07. You can view files and clone it, but cannot push or open issues or pull requests.
2022-04-21 12:22:50 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# https://github.com/nginxinc/docker-nginx/blob/master/entrypoint/20-envsubst-on-templates.sh
|
2022-04-21 13:57:16 +00:00
|
|
|
# https://github.com/nginxinc/docker-nginx/blob/master/LICENSE
|
2022-04-21 12:22:50 +00:00
|
|
|
# Copyright (C) 2011-2016 Nginx, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
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))
|
|
|
|
[ -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
|