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 47
192 lines (183 loc) · 6.46 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
name: CI
permissions:
contents: read
pull-requests: read
actions: read
env:
REPO: "sealio"
VERSION: "${{ github.ref_name }}"
BUILD_PLATFORMS: "linux/amd64,linux/arm64"
PARALLELIZE: "false"
GO_VERSION: "1.19.12"
defaults:
run:
shell: bash
on:
push:
branches:
- "main"
- "release/*"
tags:
- "v*.*.*"
pull_request:
branches:
- "main"
- "release/*"
workflow_dispatch: {}
jobs:
skip:
timeout-minutes: 5
runs-on: ubuntu-22.04
permissions:
contents: read
pull-requests: read
actions: write
outputs:
should: ${{ steps.duplicate.outputs.should_skip }}
steps:
- name: Check Duplicate
id: duplicate
uses: fkirc/skip-duplicate-actions@v5
with:
github_token: "${{ github.token }}"
paths_ignore: '["**.md", "**.mdx", "**.png", "**.jpg"]'
do_not_skip: '["workflow_dispatch", "push"]'
continue-on-error: true
build:
needs:
- skip
timeout-minutes: 60
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
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@v4
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:
CI_CHECK: "${{ needs.skip.outputs.should != 'true' }}"
LINT_DIRTY: "true"
PACKAGE_BUILD: "false"
SEAL_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: read
actions: read
id-token: write
timeout-minutes: 20
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- target: seal
task: server
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
persist-credentials: false
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
with:
image: tonistiigi/binfmt:qemu-v7.0.0
platforms: "arm64"
- name: Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Login DockerHub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
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@v4
with:
images: ${{ env.REPO }}/${{ matrix.target }}-${{ matrix.task }}
- name: Package
uses: docker/build-push-action@v4
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: ${{ env.BUILD_PLATFORMS }}
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/seal/ui' || 'https://seal-ui-1303613262.cos.ap-guangzhou.myqcloud.com/latest/index.html' }}
SERVE_TEMPLATE_REFER=${{ startsWith(github.ref, 'refs/tags/') && 'release' || 'main' }}
- 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 }}"
UNTRUSTED_DIGEST: "${{ steps.package.outputs.digest }}"
DOCKERHUB_USERNAME: "${{ secrets.CI_DOCKERHUB_USERNAME }}"
DOCKERHUB_PASSWORD: "${{ secrets.CI_DOCKERHUB_PASSWORD }}"
continue-on-error: true