From 9bdc1ad13d15d7d5a426feb68e56cbbcb917d29d Mon Sep 17 00:00:00 2001 From: Tin Pham <72054441+tinpham5614@users.noreply.github.com> Date: Thu, 9 May 2024 23:46:06 -0700 Subject: [PATCH] add auto update from deployment via ssh (#359) --- .github/workflows/ssh.yml | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/ssh.yml diff --git a/.github/workflows/ssh.yml b/.github/workflows/ssh.yml new file mode 100644 index 00000000..5d3f18d0 --- /dev/null +++ b/.github/workflows/ssh.yml @@ -0,0 +1,44 @@ +name: Continuous Deployment via SSH +on: + [workflow_dispatch] + # push: + # branches: + # - main + +jobs: + deploy: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 20.x] + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install SSH Key + run: | + mkdir -p ~/.ssh/ + echo "${{ secrets.DEPLOYUSERSSHKEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + + - name: Execute Deployment Commands + run: | + ssh -o StrictHostKeyChecking=no deployuser@44.238.195.106 << 'EOF' + source ~/.profile || true + source ~/.bashrc || true + # Ensure you're in the correct directory + cd ~/belindasFrontEnd + # Fetch the latest changes + git pull origin main + # Activate the Node.js version managed by nvm + source ~/.nvm/nvm.sh + nvm use ${{ matrix.node-version }} + # Install any new dependencies using npm from nvm + npm install + # Build the project + npm run build + # Restart the application with PM2 + pm2 restart belindas-frontend + EOF