Skip to content

Commit

Permalink
优化启动脚本,忽略已存在的环境变量
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry committed Apr 23, 2024
1 parent d65698e commit 727d430
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ npx prisma migrate deploy
export VERSION=$(cat /app/version)

ENV_FILE="/app/.env"
export $(grep -v '^#' "$ENV_FILE" | grep -v '^$' | xargs)

# 读取 .env 文件并导出环境变量,跳过已存在的环境变量
grep -v -e '^#' -e '^$' "$ENV_FILE" | while read -r line; do
key=$(echo "$line" | cut -d '=' -f 1)
if [ -z "${!key+x}" ]; then
# 导出整个键值对
export "$line"
fi
done

node /app/.output/server/index.mjs > output.log 2>&1

0 comments on commit 727d430

Please sign in to comment.