Skip to content

Commit f913d33

Browse files
committed
Make deployment hooks use server's shared/.env
Ensure consistency between deployment hooks and running application: - Export SHARED_ENV_PATH in run_pre_deploy_hook() and run_post_deploy_hook() - Update pre-deploy.sh.template to source shared/.env before execution - Update post-deploy.sh.template to source shared/.env before execution - Hooks now use same environment variables as the deployed app at runtime - Prevents mismatches between local .env and server .env during migrations
1 parent 5be012d commit f913d33

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/release.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ run_pre_deploy_hook() {
148148
export REMOTE_PATH="$REMOTE_PATH"
149149
export PM2_APP_NAME="${PM2_APP_NAME:-}"
150150
export BACKEND_PORT="${BACKEND_PORT:-}"
151+
export SHARED_ENV_PATH="$REMOTE_PATH/shared/.env"
151152
152153
# Make hook executable and run it
153154
chmod +x .shipnode-pre-deploy.sh
@@ -198,6 +199,7 @@ run_post_deploy_hook() {
198199
export REMOTE_PATH="$REMOTE_PATH"
199200
export PM2_APP_NAME="${PM2_APP_NAME:-}"
200201
export BACKEND_PORT="${BACKEND_PORT:-}"
202+
export SHARED_ENV_PATH="$REMOTE_PATH/shared/.env"
201203
202204
# Make hook executable and run it
203205
chmod +x .shipnode-post-deploy.sh

templates/post-deploy.sh.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@
88
# REMOTE_PATH - Base deployment directory
99
# PM2_APP_NAME - PM2 process name (backend only)
1010
# BACKEND_PORT - Application port (backend only)
11+
# SHARED_ENV_PATH - Path to the server's shared .env file
1112

1213
set -e # Exit on error (but failure won't rollback deployment)
1314

15+
# Source the server's shared .env to use same variables as the app
16+
if [ -f "$SHARED_ENV_PATH" ]; then
17+
set -a
18+
source "$SHARED_ENV_PATH"
19+
set +a
20+
fi
21+
1422
echo "Running post-deploy hook for release: $RELEASE_PATH"
1523

1624
# Example: Clear application cache

templates/pre-deploy.sh.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@
88
# REMOTE_PATH - Base deployment directory
99
# PM2_APP_NAME - PM2 process name (backend only)
1010
# BACKEND_PORT - Application port (backend only)
11+
# SHARED_ENV_PATH - Path to the server's shared .env file
1112

1213
set -e # Exit on error
1314

15+
# Source the server's shared .env to use same variables as the app
16+
if [ -f "$SHARED_ENV_PATH" ]; then
17+
set -a
18+
source "$SHARED_ENV_PATH"
19+
set +a
20+
fi
21+
1422
echo "Running pre-deploy hook for release: $RELEASE_PATH"
1523

1624
# Example: Run database migrations

0 commit comments

Comments
 (0)