From e3ab37f926a047a2a3f761820c20bcf15f37d826 Mon Sep 17 00:00:00 2001 From: Yunus Ashyrov Date: Thu, 29 Feb 2024 14:02:08 +0500 Subject: [PATCH] fix deployment keys --- .github/workflows/vps_server_production.yml | 29 ++++++++------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/vps_server_production.yml b/.github/workflows/vps_server_production.yml index 49d6c85..5e90109 100644 --- a/.github/workflows/vps_server_production.yml +++ b/.github/workflows/vps_server_production.yml @@ -9,38 +9,35 @@ jobs: deploy: if: github.event.pull_request.merged == true name: Deploy latest production updates of app on VPS - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - - name: Set up SSH key - run: echo "${{secrets.PRIVATE_KEY}}" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa + - name: Setup SSH + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: ${{ secrets.PRIVATE_KEY }} - - name: Add VPS host to known hosts - run: ssh-keyscan -H ${{secrets.PROD_HOST}} >> ~/.ssh/known_hosts - - - name: Run commands on remote VPS server + - name: Deploy to production VPS env: - HOSTNAME: ${{secrets.PROD_HOST}} - USER_NAME: ${{secrets.PROD_USER}} - SMTP_DEPLOYMENT_KEY: ${{secrets.SMTP_DEPLOYMENT_KEY}} + HOSTNAME: ${{ secrets.PROD_HOST }} + USER_NAME: ${{ secrets.PROD_USER }} + SMTP_DEPLOYMENT_KEY: ${{ secrets.SMTP_DEPLOYMENT_KEY }} run: | - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${USER_NAME}@${HOSTNAME} ' + ssh -o StrictHostKeyChecking=no ${USER_NAME}@${HOSTNAME} ' echo "Script execution started." source ~/.nvm/nvm.sh nvm use v18.18.0 PM2_PATH="/home/ubuntu/.nvm/versions/node/v18.18.0/bin/pm2" CROSS_ENV_PATH="/home/ubuntu/.nvm/versions/node/v18.18.0/bin/cross-env" TSC_PATH="/home/ubuntu/.nvm/versions/node/v18.18.0/bin/tsc" - if [ -f "$PM2_PATH" ]; then $PM2_PATH stop all echo "pm2 stop all executed." else echo "pm2 not found at $PM2_PATH." fi - cd /var/www/ sudo rm -r -f ./smtp_server/ mkdir smtp_server @@ -48,23 +45,19 @@ jobs: git init git remote add origin https://$SMTP_DEPLOYMENT_KEY@github.com/yunusmi/smtp_server.git git pull origin main - if [ $? -eq 0 ]; then echo 'git pull success.' else echo 'git pull failure.' - exit 1 + exit 1; fi - npm ci - if [ -f "$CROSS_ENV_PATH" ]; then $TSC_PATH echo "tsc executed." else echo "tsc not found at $TSC_PATH." fi - $CROSS_ENV_PATH NODE_ENV=production $PM2_PATH start ./dist/app.js $PM2_PATH save echo "Script execution completed."