Skip to content

chore: update deploy-to-aws-ec2.yml (#22) #2

chore: update deploy-to-aws-ec2.yml (#22)

chore: update deploy-to-aws-ec2.yml (#22) #2

name: Deploy to AWS EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '22'
- name: Install dependencies
run: npm install
- name: Build the project
run: npm run build
- name: Create SSH key file
run: |
echo "${{ secrets.EC2_KEY }}" > ec2_key.pem
chmod 600 ec2_key.pem
- name: Deploy to EC2 via SSH
run: |
ssh -i ec2_key.pem -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
cd ~/front-end
git pull origin main
npm install
npm run build
pm2 start npm --name "${{ secrets.APP_NAME }}" -- start || pm2 restart "${{ secrets.APP_NAME }}"
EOF