-
Notifications
You must be signed in to change notification settings - Fork 10
56 lines (48 loc) · 1.59 KB
/
Copy pathdeploy-hetzner.yml
File metadata and controls
56 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
name: deploy-hetzner
on:
push:
branches: [master]
workflow_dispatch:
concurrency:
group: deploy-hetzner
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true
- name: Test
run: go test -v ./...
- name: Build (ARM64)
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 \
go build -trimpath -ldflags="-s -w" -o lyrics-api-go .
- name: SSH setup
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy
run: |
scp -i ~/.ssh/id_ed25519 lyrics-api-go \
${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/opt/lyrics-api/lyrics-api-go.new
ssh -i ~/.ssh/id_ed25519 ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} '
set -eo pipefail
mv /opt/lyrics-api/lyrics-api-go.new /opt/lyrics-api/lyrics-api-go
chmod +x /opt/lyrics-api/lyrics-api-go
sudo systemctl restart lyrics-api
for i in $(seq 1 30); do
if curl -sf http://localhost:8080/health > /dev/null 2>&1; then
echo "Service healthy after ${i}s"
exit 0
fi
sleep 1
done
echo "Health check timed out after 30s — service likely failed to start"
exit 1
'