Skip to content

Commit 35835ac

Browse files
committed
fix: improve backend environment variable loading in deployment script
1 parent 65931cf commit 35835ac

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

.github/workflows/cd.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,27 @@ jobs:
172172
script: |
173173
set -eu
174174
cd "$DEPLOY_PATH"
175+
ENV_FILE="./deploy/env/backend.env"
175176
176-
if [ ! -f "./deploy/env/backend.env" ]; then
177-
echo "Missing required file: ./deploy/env/backend.env"
177+
if [ ! -f "$ENV_FILE" ]; then
178+
echo "Missing required file: $ENV_FILE"
178179
exit 1
179180
fi
180181
182+
# Load backend env even when file is owned by root (e.g. mode 600).
181183
set -a
182-
. ./deploy/env/backend.env
184+
TMP_ENV="$(mktemp)"
185+
if [ -r "$ENV_FILE" ]; then
186+
cat "$ENV_FILE" > "$TMP_ENV"
187+
else
188+
echo "No read permission for $ENV_FILE, loading via sudo..."
189+
sudo cat "$ENV_FILE" > "$TMP_ENV"
190+
fi
191+
192+
# Normalize potential CRLF and source variables
193+
sed -i 's/\r$//' "$TMP_ENV"
194+
. "$TMP_ENV"
195+
rm -f "$TMP_ENV"
183196
set +a
184197
185198
: "${DB_USERNAME:=smalltrend}"

0 commit comments

Comments
 (0)