-
Notifications
You must be signed in to change notification settings - Fork 2.4k
308 lines (279 loc) · 10.6 KB
/
webhooks.yml
File metadata and controls
308 lines (279 loc) · 10.6 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: Build Webhooks image
on:
workflow_call:
inputs:
push_image:
description: "Push image"
required: false
type: boolean
default: false
push_image_tag:
description: "Push image tag"
default: "latest"
required: false
type: string
disable_cilint:
description: "Disable golangci-lint"
default: false
required: false
type: boolean
workflow_dispatch:
inputs:
push_image:
description: "Push image"
required: false
type: boolean
default: false
push_image_tag:
description: "Push image tag"
default: "latest"
required: false
type: string
disable_cilint:
description: "Disable golangci-lint"
default: false
required: false
type: boolean
push:
branches: ["*"]
paths:
- "webhooks/**"
- ".github/workflows/webhooks.yml"
- "!**/*.md"
- "!**/*.yaml"
pull_request:
branches: ["*"]
paths:
- "webhooks/**"
- ".github/workflows/webhooks.yml"
- "!**/*.md"
- "!**/*.yaml"
# Avoid using ${{ github.workflow }} - when called via workflow_call, it inherits the caller's name causing conflicts
concurrency:
group: webhooks-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
# Common versions
GO_VERSION: "1.25"
DEFAULT_OWNER: "labring"
ALIYUN_REGISTRY: ${{ secrets.ALIYUN_REGISTRY }}
ALIYUN_REPO_PREFIX: ${{ secrets.ALIYUN_REPO_PREFIX && secrets.ALIYUN_REPO_PREFIX || secrets.ALIYUN_USERNAME && format('{0}/{1}', secrets.ALIYUN_REGISTRY, secrets.ALIYUN_USERNAME) || '' }}
jobs:
resolve-modules:
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve Modules
id: set-matrix
run: bash ./scripts/resolve-modules.sh ./webhooks
golangci-lint:
if: ${{ !inputs.disable_cilint && (github.event_name == 'push' || github.event_name == 'pull_request') }}
needs: [resolve-modules]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Dependencies
run: |
sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Run Linter
uses: golangci/golangci-lint-action@v8
with:
version: v2.5.0
working-directory: ${{ matrix.workdir }}
# args between =, not space
args: --color=always --config=${{ github.workspace }}/.golangci.yml
image-build:
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
strategy:
matrix:
module: [admission]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build ${{ matrix.module }} amd64
working-directory: webhooks/${{ matrix.module }}
env:
MODULE: ${{ matrix.module }}
run: |
GOARCH=amd64 make build
mv bin/manager "bin/webhook-${MODULE}-amd64"
chmod +x "bin/webhook-${MODULE}-amd64"
- name: Build ${{ matrix.module }} arm64
working-directory: webhooks/${{ matrix.module }}
env:
MODULE: ${{ matrix.module }}
run: |
GOARCH=arm64 make build
mv bin/manager "bin/webhook-${MODULE}-arm64"
chmod +x "bin/webhook-${MODULE}-arm64"
- name: Set image repo
env:
REPO_OWNER: ${{ github.repository_owner }}
MODULE_NAME: ${{ matrix.module }}
run: |
echo "GHCR_REPO=ghcr.io/${REPO_OWNER}/sealos-${MODULE_NAME}-webhook" >> $GITHUB_ENV
if [[ -n "${{ env.ALIYUN_REPO_PREFIX }}" ]]; then
echo "ALIYUN_REPO=${{ env.ALIYUN_REPO_PREFIX }}/sealos-${MODULE_NAME}-webhook" >> $GITHUB_ENV
fi
- # Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ (github.event_name == 'push') ||(github.event_name == 'create') || (inputs.push_image == true) }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN || secrets.GITHUB_TOKEN }}
- name: Login to Aliyun Registry
uses: docker/login-action@v3
if: ${{ ((github.event_name == 'push') ||(github.event_name == 'create') || (inputs.push_image == true)) && env.ALIYUN_REGISTRY }}
with:
registry: ${{ env.ALIYUN_REGISTRY }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_REPO }}
${{ env.ALIYUN_REPO }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{ inputs.push_image_tag }},enable=${{ inputs.push_image_tag != '' && inputs.push_image_tag != 'latest' }}
type=ref,event=branch
type=ref,event=tag
type=sha
env:
DOCKER_METADATA_SHORT_SHA_LENGTH: 9
- name: build (and publish) ${{ matrix.module }} main image
uses: docker/build-push-action@v6
with:
context: ./webhooks/${{ matrix.module }}
file: ./webhooks/${{ matrix.module }}/Dockerfile
# Push if it's a push event or if push_image is true
push: ${{ (github.event_name == 'push')||(github.event_name == 'create') || (inputs.push_image == true) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-cluster-image:
if: ${{ (github.event_name == 'push') ||(github.event_name == 'create') || (inputs.push_image == true) }}
needs:
- image-build
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
strategy:
matrix:
module: [admission]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set image repo
env:
REPO_OWNER: ${{ github.repository_owner }}
MODULE_NAME: ${{ matrix.module }}
run: |
echo "MODULE_NAME=${MODULE_NAME}" >> $GITHUB_ENV
echo "OLD_DOCKER_REPO=ghcr.io/labring/sealos-${MODULE_NAME}-webhook" >> $GITHUB_ENV
# Docker image repo (always use GHCR for manifests to avoid Aliyun bandwidth costs)
echo "GHCR_DOCKER_REPO=ghcr.io/${REPO_OWNER}/sealos-${MODULE_NAME}-webhook" >> $GITHUB_ENV
# Cluster image repos
echo "GHCR_CLUSTER_REPO=ghcr.io/${REPO_OWNER}/sealos-cloud-${MODULE_NAME}-webhook" >> $GITHUB_ENV
if [[ -n "${{ env.ALIYUN_REPO_PREFIX }}" ]]; then
echo "ALIYUN_CLUSTER_REPO=${{ env.ALIYUN_REPO_PREFIX }}/sealos-cloud-${MODULE_NAME}-webhook" >> $GITHUB_ENV
fi
- name: Docker meta for cluster image
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GHCR_CLUSTER_REPO }}
${{ env.ALIYUN_CLUSTER_REPO }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{ inputs.push_image_tag }},enable=${{ inputs.push_image_tag != '' && inputs.push_image_tag != 'latest' }}
type=ref,event=branch
type=ref,event=tag
type=sha
env:
DOCKER_METADATA_SHORT_SHA_LENGTH: 9
- name: Install sealos
run: |
sudo bash ./.github/scripts/install.sh
- name: Build ${{ matrix.module }}-webhook cluster image
working-directory: webhooks/${{ matrix.module }}/deploy
env:
MODULE_NAME: ${{ env.MODULE_NAME }}
OLD_DOCKER_REPO: ${{ env.OLD_DOCKER_REPO }}
GHCR_DOCKER_REPO: ${{ env.GHCR_DOCKER_REPO }}
run: |
# Build cluster images for each tag (amd64)
for TAG in $DOCKER_METADATA_OUTPUT_TAGS; do
# Always use GHCR docker image to avoid Aliyun bandwidth costs
IMAGE_TAG="${TAG##*:}"
NEW_DOCKER_IMAGE="${GHCR_DOCKER_REPO}:${IMAGE_TAG}"
echo "Updating manifests to: ${NEW_DOCKER_IMAGE}"
sed -i -E "s;(${OLD_DOCKER_REPO}|${GHCR_DOCKER_REPO}):[^[:space:]\"']*;${NEW_DOCKER_IMAGE};" manifests/*
sudo rm -rf registry
echo "Building ${TAG}-amd64"
sudo sealos build -t "${TAG}-amd64" --platform linux/amd64 -f Kubefile
done
# Build cluster images for each tag (arm64)
for TAG in $DOCKER_METADATA_OUTPUT_TAGS; do
IMAGE_TAG="${TAG##*:}"
NEW_DOCKER_IMAGE="${GHCR_DOCKER_REPO}:${IMAGE_TAG}"
sed -i -E "s;(${OLD_DOCKER_REPO}|${GHCR_DOCKER_REPO}):[^[:space:]\"']*;${NEW_DOCKER_IMAGE};" manifests/*
sudo rm -rf registry
echo "Building ${TAG}-arm64"
sudo sealos build -t "${TAG}-arm64" --platform linux/arm64 -f Kubefile
done
- name: Sealos login to ghcr.io
env:
REPOSITORY_OWNER: ${{ github.repository_owner }}
GH_PAT: ${{ secrets.GHCR_TOKEN || secrets.GITHUB_TOKEN }}
run: |
sudo sealos login -u "${REPOSITORY_OWNER}" -p "${GH_PAT}" --debug ghcr.io
- name: Sealos login to Aliyun Registry
if: ${{ env.ALIYUN_REGISTRY }}
env:
ALIYUN_USERNAME: ${{ secrets.ALIYUN_USERNAME }}
ALIYUN_PASSWORD: ${{ secrets.ALIYUN_PASSWORD }}
run: |
sudo sealos login -u "$ALIYUN_USERNAME" -p "$ALIYUN_PASSWORD" --debug ${{ env.ALIYUN_REGISTRY }}
- name: Manifest Cluster Images
run: |
sudo sealos images
for TAG in $DOCKER_METADATA_OUTPUT_TAGS; do
echo "Creating manifest for ${TAG}"
bash scripts/manifest-cluster-images.sh "$TAG"
done