This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
206 lines (198 loc) · 7.33 KB
/
ci.yml
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
name: CI
permissions:
contents: read
pull-requests: read
actions: read
env:
REPO: "sealio"
VERSION: "${{ github.ref_name }}"
PARALLELIZE: "false"
GO_VERSION: "1.21.9"
defaults:
run:
shell: bash
on:
workflow_dispatch: { }
push:
tags:
- "v*.*.*"
branches:
- "main"
- "dev"
paths-ignore:
- "docs/**"
- "**.md"
- "**.mdx"
- "**.png"
- "**.jpg"
pull_request:
branches:
- "main"
- "dev"
paths-ignore:
- "docs/**"
- "**.md"
- "**.mdx"
- "**.png"
- "**.jpg"
jobs:
build:
timeout-minutes: 60
runs-on: ubuntu-22.04
steps:
# Clean up unused tools to have more disk space in the GitHub hosted runner.
- name: Free disk space
run:
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
- name: Checkout
uses: actions/checkout@v4
with:
# checkout the whole histories for commitsar,
# currently commitsar needs full git objects to work correctly.
fetch-depth: 0
persist-credentials: false
- name: Setup Go
timeout-minutes: 15
uses: actions/setup-go@v5
with:
go-version: "${{ env.GO_VERSION }}"
cache-dependency-path: |
**/go.sum
- name: Setup Toolbox
timeout-minutes: 5
uses: actions/cache@v3
with:
# restore/save service binaries, e.g. goimports, golangci-lint, commitsar.
key: toolbox-${{ runner.os }}
path: |
${{ github.workspace }}/.sbin
- name: Build
run: make ci
env:
LINT_DIRTY: "true"
PACKAGE_BUILD: "false"
WALRUS_TELEMETRY_API_KEY: "${{ github.event_name != 'pull_request' && secrets.CI_TELEMETRY_API_KEY || '' }}"
- name: Archive Publish Result
uses: actions/cache/save@v3
with:
# save package resources, e.g. go build result, downloaded UI, entrypoint script.
key: archive-${{ runner.os }}-${{ github.sha }}
path: |
${{ github.workspace }}/.dist/package
publish:
needs:
- build
permissions:
contents: write
actions: read
id-token: write
timeout-minutes: 60
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- target: walrus
task: walrus
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
persist-credentials: false
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:qemu-v7.0.0
platforms: "arm64"
- name: Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Login DockerHub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.CI_DOCKERHUB_USERNAME }}
password: ${{ secrets.CI_DOCKERHUB_PASSWORD }}
- name: Unarchive Publish Result
timeout-minutes: 5
uses: actions/cache/restore@v3
with:
# restore package resources, e.g. go build result, downloaded UI, entrypoint script.
key: archive-${{ runner.os }}-${{ github.sha }}
path: |
${{ github.workspace }}/.dist/package
- name: Get Metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: "${{ env.REPO }}/${{ matrix.target == matrix.task && matrix.target || format('{0}-{1}', matrix.target, matrix.task) }}"
- name: Package
uses: docker/build-push-action@v5
id: package
with:
push: ${{ github.event_name != 'pull_request' }}
file: .dist/package/${{ matrix.target }}/${{ matrix.task }}/image/Dockerfile
context: .dist/package/${{ matrix.target }}/${{ matrix.task }}/
platforms: "linux/amd64,linux/arm64"
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
# configure build cache,
# ref to https://github.com/moby/buildkit/tree/v0.11.5#registry-push-image-and-cache-separately.
cache-from: |
type=registry,ref=${{ env.REPO }}/build-cache:${{ matrix.target }}-${{ matrix.task }}
cache-to: |
${{ github.event_name != 'pull_request' && format('type=registry,mode=max,oci-mediatypes=false,compression=gzip,ref={0}/build-cache:{1}-{2},ignore-error=true', env.REPO, matrix.target, matrix.task) || '' }}
build-args: |
SERVE_UI_INDEX=${{ startsWith(github.ref, 'refs/tags/') && 'file:///var/lib/walrus/ui' || 'https://walrus-ui-1303613262.cos.ap-guangzhou.myqcloud.com/latest/index.html' }}
- name: Setup Cosign
if: ${{ github.event_name != 'pull_request' }}
uses: sigstore/[email protected]
with:
cosign-release: v2.0.0
- name: Prove
if: ${{ github.event_name != 'pull_request' }}
run: |
set -euo pipefail
# login
cosign login "docker.io" -u "${DOCKERHUB_USERNAME}" -p "${DOCKERHUB_PASSWORD}"
# prove
curl -o slsa-generator --retry 3 --retry-all-errors --retry-delay 3 -sSfL \
"https://github.com/slsa-framework/slsa-github-generator/releases/download/${SLSA_GITHUB_GENERATOR_VERSION}/${SLSA_GITHUB_GENERATOR}"
chmod a+x slsa-generator
predicate_name="predicate.json"
./slsa-generator generate --predicate="${predicate_name}"
cosign attest --predicate="${predicate_name}" \
--type slsaprovenance \
--yes \
"${UNTRUSTED_IMAGE}@${UNTRUSTED_DIGEST}"
env:
COSIGN_EXPERIMENTAL: "1"
SLSA_GITHUB_GENERATOR: "slsa-generator-container-linux-amd64"
SLSA_GITHUB_GENERATOR_VERSION: "v1.5.0"
GITHUB_CONTEXT: "${{ toJSON(github) }}"
UNTRUSTED_IMAGE: "${{ env.REPO }}/${{ matrix.target == matrix.task && matrix.target || format('{0}-{1}', matrix.target, matrix.task) }}"
UNTRUSTED_DIGEST: "${{ steps.package.outputs.digest }}"
DOCKERHUB_USERNAME: "${{ secrets.CI_DOCKERHUB_USERNAME }}"
DOCKERHUB_PASSWORD: "${{ secrets.CI_DOCKERHUB_PASSWORD }}"
continue-on-error: true
# FIXME(thxCode): remove this step after we adjust the walrus-catalog CI.
- name: Upload Assets(CLI)
uses: TencentCloud/cos-action@b0aa648235fb35a1bdd6a77f529eb0ac4c2f1c25
if: ${{ github.event_name != 'pull_request' }}
with:
secret_id: ${{ secrets.CI_TECENTCOS_SECRET_ID }}
secret_key: ${{ secrets.CI_TECENTCOS_SECRET_KEY }}
cos_bucket: ${{ secrets.COS_BUCKET }}
cos_region: ${{ secrets.COS_REGION }}
local_path: .dist/package/${{ matrix.target }}/${{ matrix.task }}/release
remote_path: releases/${{ steps.metadata.outputs.version == 'main' && 'latest' || steps.metadata.outputs.version }}
accelerate: true
clean: false
- name: Release Assets
uses: softprops/action-gh-release@v1
if: ${{ startsWith(github.ref, 'refs/tags/') }}
with:
fail_on_unmatched_files: true
tag_name: ${{ steps.metadata.outputs.version }}
prerelease: ${{ contains(github.ref, 'rc') }}
files: .dist/package/${{ matrix.target }}/${{ matrix.task }}/release/*