Repository navigation
128 lines (106 loc) · 4.18 KB
/
Copy pathdeploy.yml
File metadata and controls
128 lines (106 loc) · 4.18 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Build & Deploy
on:
release:
types: [published]
workflow_dispatch:
env:
REGISTRY: ghcr.io
APP_IMAGE: ghcr.io/${{ github.repository }}/app
FRONTEND_IMAGE: ghcr.io/${{ github.repository }}/frontend
jobs:
# ── Build App (Wippy backend) ────────────────────────────────
build-app:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push app image
uses: docker/build-push-action@v6
with:
context: .
file: .docker/Dockerfile
push: true
tags: |
${{ env.APP_IMAGE }}:latest
${{ env.APP_IMAGE }}:${{ github.event.release.tag_name || github.sha }}
cache-from: type=gha,scope=app
cache-to: type=gha,mode=max,scope=app
# ── Build Frontend (Nuxt SSR) ───────────────────────────────
build-frontend:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push frontend image
uses: docker/build-push-action@v6
with:
context: ./frontend
file: ./frontend/.docker/Dockerfile
push: true
tags: |
${{ env.FRONTEND_IMAGE }}:latest
${{ env.FRONTEND_IMAGE }}:${{ github.event.release.tag_name || github.sha }}
cache-from: type=gha,scope=frontend
cache-to: type=gha,mode=max,scope=frontend
# ── Deploy to production server ─────────────────────────────
deploy:
runs-on: ubuntu-latest
needs: [build-app, build-frontend]
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
steps:
- name: Connect to WireGuard VPN
run: |
sudo apt-get install -y wireguard
echo "${{ secrets.WG_CONFIG }}" | sudo tee /etc/wireguard/wg0.conf > /dev/null
sudo chmod 600 /etc/wireguard/wg0.conf
sudo wg-quick up wg0
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_SSH_PORT || 22 }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
# Stop at the first failing command, so the job goes red
# instead of reporting a deploy that did not happen.
set -eu
cd /servers/buggregator.dev.v2
# Host files (docker-compose.yml, infra/nginx.conf, pages) come
# from the repo's default branch, master. --ff-only: a host
# checkout with local changes or commits fails here, not merges.
git pull --ff-only origin master
# Host nginx (system service, certbot TLS) serves infra/nginx.conf.
# Test the config before anything restarts; a bad one stops the
# deploy and the running nginx keeps its old config.
SUDO=""
if [ "$(id -u)" -ne 0 ]; then SUDO="sudo -n"; fi
$SUDO nginx -t
# Pull latest images
docker compose pull app frontend
# Restart app + frontend with new images
docker compose up -d app frontend
# Apply the pulled nginx config (graceful: open connections finish)
$SUDO systemctl reload nginx
# Clean up old images
docker image prune -f