Skip to content

Commit f0dab74

Browse files
authored
Merge pull request #39 from BUAA-SE-coders007/chore/autodeploy
[chore]: try to auto deploy
2 parents 3beb80b + fec5613 commit f0dab74

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy FastAPI Backend
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- dev
8+
9+
jobs:
10+
deploy:
11+
name: Deploy to Server
12+
runs-on: ubuntu-22.04
13+
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v3
17+
18+
- name: Setup SSH
19+
uses: webfactory/[email protected]
20+
with:
21+
ssh-private-key: ${{ secrets.SERVER_SSH_KEY }}
22+
23+
- name: Add server to known_hosts
24+
run: |
25+
ssh-keyscan -H jienote.top >> ~/.ssh/known_hosts
26+
27+
- name: Sync Code to Server
28+
run: |
29+
rsync -avz --delete \
30+
--exclude '.git' \
31+
--exclude '.github' \
32+
./ \
33+
${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:${{ secrets.REMOTE_PATH }}
34+
35+
- name: Build and Restart Docker on Server
36+
run: |
37+
ssh ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} << 'EOF'
38+
cd ${{ secrets.REMOTE_PATH }}
39+
cd ..
40+
docker-compose down
41+
docker-compose build
42+
docker-compose up -d
43+
EOF

0 commit comments

Comments
 (0)