From db144708d4cf97950dc1517b202fe890d397e495 Mon Sep 17 00:00:00 2001 From: Lewis Zou Date: Tue, 30 Jul 2024 17:38:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=AE=E7=94=9F?= =?UTF-8?q?=E6=88=90=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-entrypoint.sh | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 673a65e..23e6128 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,23 +1,32 @@ #!/bin/bash set -eu -# 输入文件名 -input_file="${CONFIG_SOURCE}" -# 输出文件名 -output_file="/app/appsettings.json" +generate() { + # 输入文件名 + input_file="$1" + # 输出文件名 + output_file="$2" + + # 检查输入文件是否存在 + if [ -f "${input_file}" ]; then + awk '{ + while (match($0, /\$\{[A-Za-z_][A-Za-z0-9_]*\}/)) { + var=substr($0, RSTART+2, RLENGTH-3) + gsub(/\$\{[A-Za-z_][A-Za-z0-9_]*\}/, ENVIRON[var]) + } + print + }' "${input_file}" >"${output_file}" + echo "配置文件 ${output_file} 已生成" + else + echo "使用默认配置文件 ${output_file}" + fi +} -# 检查输入文件是否存在 -if [ -f "${input_file}" ]; then - awk '{ - while (match($0, /\$\{[A-Za-z_][A-Za-z0-9_]*\}/)) { - var=substr($0, RSTART+2, RLENGTH-3) - gsub(/\$\{[A-Za-z_][A-Za-z0-9_]*\}/, ENVIRON[var]) - } - print - }' "$input_file" >"$output_file" - echo "配置文件已生成" +CONFIG_SOURCE_V=$(env | grep "CONFIG_SOURCE") +if [ -z "$CONFIG_SOURCE_V" ]; then + echo "环境变量 CONFIG_SOURCE 不存在, 使用默认配置文件" else - echo "使用默认配置文件" + generate "${CONFIG_SOURCE}" "/app/appsettings.json" fi exec "$@" \ No newline at end of file