Skip to content

Commit

Permalink
Merge pull request #8 from yunusmi/dev
Browse files Browse the repository at this point in the history
fix deployment keys
  • Loading branch information
yunusmi authored Feb 29, 2024
2 parents d11564a + e3ab37f commit 2e180a3
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions .github/workflows/vps_server_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,55 @@ 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
cd smtp_server
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."
Expand Down

0 comments on commit 2e180a3

Please sign in to comment.