Skip to content

Commit 0f312d2

Browse files
committed
ci: align prod deploy workflow with beta (Go build + systemctl prod)
1 parent df7f57c commit 0f312d2

1 file changed

Lines changed: 56 additions & 30 deletions

File tree

.github/workflows/deploy-main.yml

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,56 @@
1-
name: Deploy Main
2-
3-
on:
4-
push:
5-
branches: [main]
6-
7-
permissions:
8-
contents: read
9-
10-
jobs:
11-
deploy:
12-
runs-on: ubuntu-latest
13-
steps:
14-
- name: SSH and deploy
15-
uses: appleboy/ssh-action@v1.2.0
16-
with:
17-
host: ${{ secrets.SSH_HOST }}
18-
username: ${{ secrets.SSH_USER }}
19-
key: ${{ secrets.SSH_PRIVATE_KEY }}
20-
port: ${{ secrets.SSH_PORT || 22 }}
21-
host_key_checking: false
22-
script: |
23-
cd ${{ secrets.MAIN_PATH }}
24-
cp .env /tmp/main.env 2>/dev/null; cp port.txt /tmp/main.port.txt 2>/dev/null
25-
git fetch origin --prune
26-
git checkout main
27-
git reset --hard origin/main
28-
cp /tmp/main.env .env 2>/dev/null; cp /tmp/main.port.txt port.txt 2>/dev/null
29-
npm install
30-
pm2 restart zerohost-dashboard
1+
name: Deploy Main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: 'stable'
21+
22+
- name: Build
23+
run: go build -o server ./cmd/server/
24+
25+
- name: Stop service
26+
uses: appleboy/ssh-action@v1.2.0
27+
with:
28+
host: ${{ secrets.SSH_HOST }}
29+
username: ${{ secrets.SSH_USER }}
30+
key: ${{ secrets.SSH_PRIVATE_KEY }}
31+
port: ${{ secrets.SSH_PORT || 22 }}
32+
script: |
33+
systemctl stop prod || true
34+
35+
- name: Upload binary
36+
uses: appleboy/scp-action@v0.1.7
37+
with:
38+
host: ${{ secrets.SSH_HOST }}
39+
username: ${{ secrets.SSH_USER }}
40+
key: ${{ secrets.SSH_PRIVATE_KEY }}
41+
port: ${{ secrets.SSH_PORT || 22 }}
42+
source: server
43+
target: ${{ secrets.MAIN_PATH }}
44+
strip_components: 0
45+
overwrite: true
46+
47+
- name: Start service
48+
uses: appleboy/ssh-action@v1.2.0
49+
with:
50+
host: ${{ secrets.SSH_HOST }}
51+
username: ${{ secrets.SSH_USER }}
52+
key: ${{ secrets.SSH_PRIVATE_KEY }}
53+
port: ${{ secrets.SSH_PORT || 22 }}
54+
script: |
55+
chmod +x ${{ secrets.MAIN_PATH }}/server
56+
systemctl start prod

0 commit comments

Comments
 (0)