Merge branch 'fix/preset-uuid' #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Backend to EC2 | |
| on: | |
| push: | |
| branches: [main] | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Setup SSH key | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| - name: Install Node.js and Deploy to EC2 | |
| env: | |
| EC2_USER: ${{ secrets.EC2_USER }} | |
| EC2_HOST: ${{ secrets.EC2_HOST }} | |
| run: | | |
| ssh -o StrictHostKeyChecking=no "$EC2_USER@$EC2_HOST" << 'EOF' | |
| sudo apt update | |
| curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - | |
| sudo apt-get install -y nodejs | |
| sudo npm install -g pm2 | |
| sudo chown -R ubuntu:ubuntu ~/Domido-Backend | |
| cd ~/Domido-Backend | |
| git fetch origin | |
| git pull origin main | |
| npm install | |
| if pm2 list | grep -q domido-backend; then | |
| pm2 restart domido-backend | |
| else | |
| pm2 start npm --name domido-backend -- start | |
| fi | |
| pm2 save | |
| EOF | |