Deploy Server to EC2 #5
This file contains 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
run-name: Deploy Server to EC2 | |
name: Server Deploy | |
on: | |
workflow_dispatch: | |
jobs: | |
test-lint: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: "backend" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: npm install, test and lint | |
run: | | |
npm install | |
npm run test | |
npm run lint | |
deploy: | |
runs-on: ubuntu-latest | |
needs: test-lint | |
steps: | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.AWS_EC2_SECRET_KEY }} | |
host: ${{ secrets.AWS_EC2_INSTANCE_IP }} | |
username: ${{ secrets.AWS_EC2_INSTANCE_USERNAME }} | |
port: ${{ secrets.AWS_EC2_INSTANCE_PORT }} | |
script: | | |
cd ${{ secrets.AWS_EC2_INSTANCE_PATH }} | |
git pull origin main | |
npm install | |
npm run build | |
pm2 restart toeic-server | |
pm2 list |