Skip to content

0.1.3

0.1.3 #6

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 restart "${{ secrets.APP_NAME }}" || pm2 start --name "${{ secrets.APP_NAME }}" npm -- start
EOF