Skip to content

Commit b87f8e3

Browse files
committed
feat: add workflow to deploy automatically
1 parent e4b8d61 commit b87f8e3

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/production-workflow.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy Cafe-search Backend to Server
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Add SSH Key to Agent
17+
run: |
18+
mkdir -p ~/.ssh
19+
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
20+
chmod 600 ~/.ssh/id_rsa
21+
eval "$(ssh-agent -s)"
22+
ssh-add ~/.ssh/id_rsa
23+
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
24+
25+
- name: Transfer updated code to server
26+
run: |
27+
scp -r -i ~/.ssh/id_rsa . ubuntu@${{ secrets.HOST }}:~/backend-temp
28+
ssh -i ~/.ssh/id_rsa ubuntu@${{ secrets.HOST }} << 'EOF'
29+
rm -rf ~/backend
30+
mv ~/backend-temp ~/backend
31+
EOF
32+
33+
- name: Deploy and Restart on EC2
34+
run: |
35+
ssh -i ~/.ssh/id_rsa ubuntu@${{ secrets.HOST }} << 'EOF'
36+
cd ~/backend
37+
git pull origin main
38+
npm ci
39+
npx prisma generate
40+
npx prisma migrate deploy
41+
npm run build
42+
pm2 reload cafe_backend
43+
EOF

0 commit comments

Comments
 (0)