-
-
Notifications
You must be signed in to change notification settings - Fork 12
215 lines (184 loc) · 8.41 KB
/
images.yaml
File metadata and controls
215 lines (184 loc) · 8.41 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
name: Build images
on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
workflow_dispatch:
env:
DOCKER_REPO: ${{ vars.DOCKERHUB_ORG }}/${{ vars.REPOSITORY_NAME || 'kaniko' }}
permissions: {}
jobs:
build-images:
concurrency:
# If a previous run is ongoing with the same head_ref (it's a run on the
# same PR) then cancel it to save time. If it isn't a PR, only cancel the
# previous run if it's on the same commit SHA and workflow ref. This prevents
# a run for a commit push or release tag from cancelling a previous commit
# push's build, since we want an image built and tagged for each commit.
group: build-images-${{ matrix.image }}-${{ github.ref }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true
permissions:
contents: read # Read the repo contents.
id-token: write # Produce identity token for keyless signing.
packages: write # push to ghcr registry
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image:
- executor
- executor-debug
- executor-slim
- warmer
- bootstrap
include:
- image: executor
target: kaniko-executor
platforms: linux/amd64,linux/arm64,linux/s390x,linux/riscv64,linux/ppc64le
tag: ${{ github.sha }}
release-tag: latest
- image: executor-debug
target: kaniko-debug
platforms: linux/amd64,linux/arm64,linux/s390x,linux/riscv64,linux/ppc64le
tag: ${{ github.sha }}-debug
release-tag: debug
- image: executor-slim
target: kaniko-slim
platforms: linux/amd64,linux/arm64,linux/s390x,linux/riscv64,linux/ppc64le
tag: ${{ github.sha }}-slim
release-tag: slim
- image: warmer
target: kaniko-warmer
platforms: linux/amd64,linux/arm64,linux/s390x,linux/riscv64,linux/ppc64le
tag: ${{ github.sha }}-warmer
release-tag: warmer
- image: bootstrap
target: kaniko-debug-2
platforms: linux/amd64,linux/arm64,linux/s390x,linux/riscv64,linux/ppc64le
tag: ${{ github.sha }}-bootstrap
release-tag: bootstrap
steps:
- name: Harden Runner
uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
with:
egress-policy: audit
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Define build context
id: context
run: |
SHOULD_PUSH=${{ github.event_name != 'pull_request' }}
case "${{ github.ref }}" in
refs/tags/v*)
IMAGE_NAME=ghcr.io/${{ github.repository }}
IS_RELEASE=true
;;
*)
IMAGE_NAME=ghcr.io/${{ github.repository }}-dev
IS_RELEASE=false
;;
esac
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
echo "should_push=$SHOULD_PUSH" >> $GITHUB_OUTPUT
- id: platforms
run: |
if [[ "${{ steps.context.outputs.should_push }}" != "true" ]]; then
echo "platforms=linux/amd64" >> $GITHUB_OUTPUT
else
echo "platforms=${{ matrix.platforms }}" >> $GITHUB_OUTPUT
fi
- if: steps.context.outputs.should_push == 'true'
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
with:
platforms: ${{ matrix.platforms }}
- uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
- name: Set build timestamp
id: build-time
run: echo "now=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- if: steps.context.outputs.should_push == 'true'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
id: build-and-push
with:
context: .
file: ./deploy/Dockerfile
platforms: ${{ steps.platforms.outputs.platforms }}
push: ${{ steps.context.outputs.should_push == 'true' }}
tags: ${{ steps.context.outputs.image_name }}:${{ matrix.tag }}
no-cache-filters: certs
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
cache-from: type=gha
cache-to: type=gha,mode=max
target: ${{ matrix.target }}
annotations: |
org.opencontainers.image.created=${{ steps.build-time.outputs.now }}
org.opencontainers.image.authors=${{ github.actor }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}/#readme
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.title=${{ steps.context.outputs.image_name }}:${{ matrix.release-tag }}
org.opencontainers.image.version=${{ steps.context.outputs.is_release == 'true' && github.ref_name || github.sha }}
# Sign images if not a PR.
- if: steps.context.outputs.should_push == 'true'
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
- if: steps.context.outputs.should_push == 'true'
run: |
cosign sign --yes \
${{ steps.context.outputs.image_name }}@${{ steps.build-and-push.outputs.digest }}
# If a tag push, use crane to add more tags.
- if: steps.context.outputs.is_release == 'true'
uses: imjasonh/setup-crane@6da1ae018866400525525ce74ff892880c099987 # v0.5
- if: steps.context.outputs.is_release == 'true'
name: Apply release tags
run: |
tag=${GITHUB_REF/refs\/tags\//}
# Tag :latest, :debug, :slim
crane cp ${{ steps.context.outputs.image_name }}@${{ steps.build-and-push.outputs.digest }} \
${{ steps.context.outputs.image_name }}:${{ matrix.release-tag }}
if [[ "${{ matrix.release-tag }}" == "latest" ]]; then
# Tag :latest images as :v1.X.Y
crane cp ${{ steps.context.outputs.image_name }}@${{ steps.build-and-push.outputs.digest }} \
${{ steps.context.outputs.image_name }}:${tag}
else
# Or tag :v1.X.Y-debug and :v1.X.Y-slim
crane cp ${{ steps.context.outputs.image_name }}@${{ steps.build-and-push.outputs.digest }} \
${{ steps.context.outputs.image_name }}:${tag}-${{ matrix.release-tag }}
fi
# If a tag push, distribute to other registries too
- if: steps.context.outputs.is_release == 'true'
uses: docker/login-action@v4
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- if: steps.context.outputs.is_release == 'true'
name: Distribute to Docker hub
run: |
tag=${GITHUB_REF/refs\/tags\//}
# Tag :latest, :debug, :slim
crane cp ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }} \
${{ env.DOCKER_REPO }}:${{ matrix.release-tag }}
if [[ "${{ matrix.release-tag }}" == "latest" ]]; then
crane cp ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }} \
${{ env.DOCKER_REPO }}:${tag}
else
crane cp ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }} \
${{ env.DOCKER_REPO }}:${tag}-${{ matrix.release-tag }}
fi
- if: steps.context.outputs.is_release == 'true'
name: Sign Docker Hub images
run: |
cosign sign --yes \
--sign-container-identity ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }} \
${{ env.DOCKER_REPO }}@${{ steps.build-and-push.outputs.digest }}