-
Notifications
You must be signed in to change notification settings - Fork 0
230 lines (199 loc) · 6.8 KB
/
release.yml
File metadata and controls
230 lines (199 loc) · 6.8 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_BASE: ghcr.io/channinghe/labelgate
BASE_NONROOT: gcr.io/distroless/static-debian13:nonroot@sha256:01e550fdb7ab79ee7be5ff440a563a58f1fd000ad9e0c532e65c3d23f917f1c5
BASE_DEBUG: gcr.io/distroless/static-debian13:debug-nonroot@sha256:b80e889821affbb581c2743235fe72fca378182a64e7e6313c36aa9a60f6f244
jobs:
# Phase 1: Build dashboard frontend once
dashboard:
name: Build Dashboard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: yarn
cache-dependency-path: dashboard/yarn.lock
- name: Build dashboard
working-directory: dashboard
run: |
yarn install --frozen-lockfile
yarn build
- uses: actions/upload-artifact@v4
with:
name: dashboard-static
path: dashboard/static
retention-days: 1
# Phase 2: Cross-compile Go binaries (native speed, no QEMU)
binaries:
name: Binary ${{ matrix.goos }}/${{ matrix.goarch }}
runs-on: ubuntu-latest
needs: dashboard
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dashboard-static
path: dashboard/static
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build binary
env:
CGO_ENABLED: "0"
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build \
-ldflags "-s -w \
-X github.com/channinghe/labelgate/internal/version.Version=${{ github.ref_name }} \
-X github.com/channinghe/labelgate/internal/version.Commit=${{ github.sha }} \
-X github.com/channinghe/labelgate/internal/version.Date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-o labelgate-${{ matrix.goos }}-${{ matrix.goarch }} \
./cmd/labelgate
- uses: actions/upload-artifact@v4
with:
name: labelgate-${{ matrix.goos }}-${{ matrix.goarch }}
path: labelgate-${{ matrix.goos }}-${{ matrix.goarch }}
# Phase 3: Package pre-built binaries into multi-arch Docker images
docker:
name: Docker${{ matrix.suffix }}
runs-on: ubuntu-latest
needs: binaries
strategy:
matrix:
include:
- suffix: ""
base_image_env: BASE_NONROOT
- suffix: "-full"
base_image_env: BASE_DEBUG
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: labelgate-linux-*
path: docker-context
merge-multiple: true
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
id: tags
run: |
VERSION="${GITHUB_REF_NAME}"
MAJOR=$(echo "$VERSION" | grep -oE '^v[0-9]+')
MINOR=$(echo "$VERSION" | grep -oE '^v[0-9]+\.[0-9]+')
SUFFIX="${{ matrix.suffix }}"
TAGS="${{ env.IMAGE_BASE }}:${VERSION}${SUFFIX}"
TAGS="${TAGS},${{ env.IMAGE_BASE }}:${MINOR}${SUFFIX}"
TAGS="${TAGS},${{ env.IMAGE_BASE }}:${MAJOR}${SUFFIX}"
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Set base image
id: base
run: |
if [ "${{ matrix.base_image_env }}" = "BASE_NONROOT" ]; then
echo "image=${{ env.BASE_NONROOT }}" >> "$GITHUB_OUTPUT"
else
echo "image=${{ env.BASE_DEBUG }}" >> "$GITHUB_OUTPUT"
fi
- name: Build and push
uses: docker/build-push-action@v6
with:
context: docker-context
file: docker/ci.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
BASE_IMAGE=${{ steps.base.outputs.image }}
cache-from: type=gha,scope=release${{ matrix.suffix || '-default' }}
cache-to: type=gha,mode=max,scope=release${{ matrix.suffix || '-default' }}
# Create GitHub Release with binaries
release:
name: GitHub Release
runs-on: ubuntu-latest
needs: [docker, binaries]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
path: artifacts
pattern: labelgate-*
merge-multiple: true
- name: Generate release body
id: body
run: |
VERSION="${GITHUB_REF_NAME}"
PREV_TAG=$(git tag --sort=-v:refname | grep -E '^v' | sed -n '2p' || echo "")
{
echo "body<<RELEASE_EOF"
if [ -n "$PREV_TAG" ]; then
echo "## Changes since ${PREV_TAG}"
echo ""
git log --pretty=format:"- %s (%h)" "${PREV_TAG}..HEAD"
else
echo "## Changes"
echo ""
git log --pretty=format:"- %s (%h)" HEAD
fi
cat <<'COMPOSE'
## Deploy with Docker Compose
```yaml
services:
labelgate:
image: ghcr.io/channinghe/labelgate:VERSION_PLACEHOLDER
container_name: labelgate
restart: unless-stopped
# use command "stat -c '%g' /var/run/docker.sock" to get the group id of the docker socket
group_add:
- "REPLACE_WITH_GROUP_ID"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
# Run the command "sudo chown -R 65532:65532 ./labelgate-data" to ensure the mount path has the correct ownership.
- ./labelgate-data:/app/config
environment:
- LABELGATE_CLOUDFLARE_API_TOKEN
- LABELGATE_CLOUDFLARE_ACCOUNT_ID
- LABELGATE_CLOUDFLARE_TUNNEL_ID
ports:
- "28111:8080"
network_mode: bridge
```
COMPOSE
echo ""
echo "RELEASE_EOF"
} >> "$GITHUB_OUTPUT"
sed -i "s|VERSION_PLACEHOLDER|${VERSION}|g" "$GITHUB_OUTPUT"
- name: Create release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.body.outputs.body }}
generate_release_notes: false
files: artifacts/*