fix(deploy): SSH into server to deploy instead of local rsync; add rsync install
Deploy to route.crispygoat.com / deploy (push) Has been cancelled
Deploy to route.crispygoat.com / deploy (push) Has been cancelled
This commit is contained in:
+20
-16
@@ -66,6 +66,9 @@ jobs:
|
|||||||
MINIMAX_BASE_URL: ${{ secrets.MINIMAX_BASE_URL }}
|
MINIMAX_BASE_URL: ${{ secrets.MINIMAX_BASE_URL }}
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Install rsync
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y rsync
|
||||||
|
|
||||||
- name: Deploy
|
- name: Deploy
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
||||||
@@ -104,9 +107,19 @@ jobs:
|
|||||||
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
|
MINIMAX_API_KEY: ${{ secrets.MINIMAX_API_KEY }}
|
||||||
MINIMAX_BASE_URL: ${{ secrets.MINIMAX_BASE_URL }}
|
MINIMAX_BASE_URL: ${{ secrets.MINIMAX_BASE_URL }}
|
||||||
CRON_SECRET: ${{ secrets.CRON_SECRET }}
|
CRON_SECRET: ${{ secrets.CRON_SECRET }}
|
||||||
|
SERVER_SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||||
run: |
|
run: |
|
||||||
|
set -e
|
||||||
APP_DIR=/home/tyler/route-commerce
|
APP_DIR=/home/tyler/route-commerce
|
||||||
|
|
||||||
|
# Add server SSH host key if provided
|
||||||
|
if [ -n "$SERVER_SSH_KEY" ]; then
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "$SERVER_SSH_KEY" >> ~/.ssh/id_ed25519
|
||||||
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
ssh-keyscan route.crispygoat.com >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
# Write production env file
|
# Write production env file
|
||||||
{
|
{
|
||||||
printf "DATABASE_URL=%s\n" "$DATABASE_URL"
|
printf "DATABASE_URL=%s\n" "$DATABASE_URL"
|
||||||
@@ -147,22 +160,13 @@ jobs:
|
|||||||
printf "CRON_SECRET=%s\n" "$CRON_SECRET"
|
printf "CRON_SECRET=%s\n" "$CRON_SECRET"
|
||||||
} > $APP_DIR/.env.production
|
} > $APP_DIR/.env.production
|
||||||
|
|
||||||
# Sync build output and required files
|
# Sync build output and required files to server
|
||||||
rsync -a --delete .next/ $APP_DIR/.next/
|
rsync -a --delete .next/ tyler@route.crispygoat.com:$APP_DIR/.next/
|
||||||
rsync -a --delete public/ $APP_DIR/public/
|
rsync -a --delete public/ tyler@route.crispygoat.com:$APP_DIR/public/
|
||||||
cp package.json $APP_DIR/
|
rsync $APP_DIR/package.json tyler@route.crispygoat.com:$APP_DIR/
|
||||||
cp next.config.ts $APP_DIR/ 2>/dev/null || true
|
rsync next.config.ts tyler@route.crispygoat.com:$APP_DIR/ 2>/dev/null || true
|
||||||
|
|
||||||
# Install production deps only
|
# Install production deps and restart on server
|
||||||
cd $APP_DIR
|
ssh tyler@route.crispygoat.com "cd $APP_DIR && npm install --omit=dev && pm2 restart route-commerce || pm2 start npm --name route-commerce -- start -- -p 3100 && pm2 save"
|
||||||
npm install --omit=dev
|
|
||||||
|
|
||||||
# Start or restart PM2
|
|
||||||
if pm2 describe route-commerce > /dev/null 2>&1; then
|
|
||||||
pm2 restart route-commerce
|
|
||||||
else
|
|
||||||
pm2 start npm --name route-commerce -- start -- -p 3100
|
|
||||||
pm2 save
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Deployed successfully"
|
echo "Deployed successfully"
|
||||||
|
|||||||
Reference in New Issue
Block a user