From c3fb24d420778cf5a3ace87cf4158b608ad5389e Mon Sep 17 00:00:00 2001 From: Prashant Vasudevan <71649489+vprashrex@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:39:12 +0530 Subject: [PATCH] fix(deployment): Load NVM and restart pm2 as deploy user in production With HOME=/root the production deploy got past git but failed at npm ci with "npm: command not found": node is installed through NVM under the deploy user, not system-wide, and the app runs in that user's pm2. Use the same remote command as deploy-staging.yml: export HOME for the deploy user, load NVM from their home, and restart pm2 as that user. Closes #300 --- .github/workflows/create-release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index eee02d5..7bc5184 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -57,18 +57,22 @@ jobs: APP_NAME: ${{ secrets.PM2_APP_NAME }} AWS_REGION: ${{ secrets.AWS_REGION }} INSTANCE_ID: ${{ secrets.EC2_INSTANCE_ID }} + ROOT_USER: ${{ secrets.USER }} DEPLOY_SHA: ${{ github.sha }} run: | : "${BUILD_DIRECTORY:?BUILD_DIRECTORY secret is not set}" + : "${ROOT_USER:?USER secret is not set}" - REMOTE_CMD="export HOME=/root \ + REMOTE_CMD="export HOME=/home/$ROOT_USER \ + && export NVM_DIR=/home/$ROOT_USER/.nvm \ + && . \$NVM_DIR/nvm.sh \ && git config --global --add safe.directory $BUILD_DIRECTORY \ && cd $BUILD_DIRECTORY \ && git fetch origin --tags --prune \ && git checkout $DEPLOY_SHA \ && npm ci \ && npm run build \ - && pm2 restart $APP_NAME" + && sudo -iu $ROOT_USER pm2 restart $APP_NAME" # Build the parameters as JSON so quoting in REMOTE_CMD can't break it. PARAMS=$(jq -n --arg cmd "$REMOTE_CMD" '{commands: [$cmd]}')