-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (137 loc) · 4.68 KB
/
ci.yml
File metadata and controls
157 lines (137 loc) · 4.68 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
name: CI
on:
workflow_dispatch:
push:
branches:
#- main
- dev
- "dev/**"
permissions:
packages: write
env:
REGISTRY: ghcr.io
IMAGE_BASE: ghcr.io/channinghe/labelgate
# Pinned base images for reproducible builds
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 (output is platform-independent)
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
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: |
BRANCH="${GITHUB_REF_NAME}"
BRANCH_SAFE=$(echo "$BRANCH" | tr '/' '-')
SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c1-7)
VERSION="${BRANCH_SAFE}-${SHORT_SHA}"
go build \
-ldflags "-s -w \
-X github.com/channinghe/labelgate/internal/version.Version=${VERSION} \
-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 }}
retention-days: 1
# 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: tag
run: |
BRANCH="${GITHUB_REF_NAME}"
BRANCH_SAFE=$(echo "$BRANCH" | tr '/' '-')
SHORT_SHA=$(echo "$GITHUB_SHA" | cut -c1-7)
SHA_TAG="${BRANCH_SAFE}-${SHORT_SHA}${{ matrix.suffix }}"
BRANCH_TAG="${BRANCH_SAFE}${{ matrix.suffix }}"
echo "tags=${IMAGE_BASE}:${SHA_TAG},${IMAGE_BASE}:${BRANCH_TAG}" >> "$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.tag.outputs.tags }}
build-args: |
BASE_IMAGE=${{ steps.base.outputs.image }}
cache-from: type=gha,scope=ci${{ matrix.suffix || '-default' }}
cache-to: type=gha,mode=max,scope=ci${{ matrix.suffix || '-default' }}