Skip to content

Commit a349e3d

Browse files
authored
Add GitHub action workflow for publishing latest spark-operator and kubectl images (#2710)
Signed-off-by: Yi Chen <[email protected]>
1 parent 501c8c9 commit a349e3d

File tree

1 file changed

+263
-0
lines changed

1 file changed

+263
-0
lines changed
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
name: Release Latest Images
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.actor }}
13+
cancel-in-progress: true
14+
15+
env:
16+
IMAGE_REGISTRY: ghcr.io
17+
OPERATOR_IMAGE_REPOSITORY: ${{ github.repository }}/controller
18+
KUBECTL_IMAGE_REPOSITORY: ${{ github.repository }}/kubectl
19+
KUBECTL_VERSION: 1.33.2
20+
21+
jobs:
22+
build_operator_images:
23+
runs-on: ubuntu-latest
24+
25+
permissions:
26+
contents: read
27+
packages: write
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
platform:
33+
- linux/amd64
34+
- linux/arm64
35+
36+
steps:
37+
- name: Prepare
38+
run: |
39+
platform=${{ matrix.platform }}
40+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
41+
42+
- name: Checkout source code
43+
uses: actions/checkout@v5
44+
45+
- name: Docker meta
46+
id: meta
47+
uses: docker/metadata-action@v5
48+
with:
49+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.OPERATOR_IMAGE_REPOSITORY }}
50+
tags: |
51+
type=raw,pattern={{version}},value=latest
52+
53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v3
55+
56+
- name: Set up Docker buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
- name: Login to container registry
60+
uses: docker/login-action@v3
61+
with:
62+
registry: ${{ env.IMAGE_REGISTRY }}
63+
username: ${{ github.actor }}
64+
password: ${{ secrets.GITHUB_TOKEN }}
65+
66+
- name: Build and push by digest
67+
id: build
68+
uses: docker/build-push-action@v6
69+
with:
70+
platforms: ${{ matrix.platform }}
71+
labels: ${{ steps.meta.outputs.labels }}
72+
outputs: type=image,name=${{ env.IMAGE_REGISTRY }}/${{ env.OPERATOR_IMAGE_REPOSITORY }},push-by-digest=true,name-canonical=true,push=true
73+
74+
- name: Export digest
75+
run: |
76+
mkdir -p /tmp/digests
77+
digest="${{ steps.build.outputs.digest }}"
78+
touch "/tmp/digests/${digest#sha256:}"
79+
80+
- name: Upload digest
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: digests-operator-${{ env.PLATFORM_PAIR }}
84+
path: /tmp/digests/*
85+
if-no-files-found: error
86+
retention-days: 1
87+
88+
build_kubectl_images:
89+
runs-on: ubuntu-latest
90+
91+
permissions:
92+
contents: read
93+
packages: write
94+
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
platform:
99+
- linux/amd64
100+
- linux/arm64
101+
102+
steps:
103+
- name: Prepare
104+
run: |
105+
platform=${{ matrix.platform }}
106+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
107+
108+
- name: Checkout source code
109+
uses: actions/checkout@v5
110+
111+
- name: Docker meta
112+
id: meta
113+
uses: docker/metadata-action@v5
114+
with:
115+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.KUBECTL_IMAGE_REPOSITORY }}
116+
tags: |
117+
type=raw,value=latest
118+
119+
- name: Set up QEMU
120+
uses: docker/setup-qemu-action@v3
121+
122+
- name: Set up Docker buildx
123+
uses: docker/setup-buildx-action@v3
124+
125+
- name: Login to container registry
126+
uses: docker/login-action@v3
127+
with:
128+
registry: ${{ env.IMAGE_REGISTRY }}
129+
username: ${{ github.actor }}
130+
password: ${{ secrets.GITHUB_TOKEN }}
131+
132+
- name: Build and push by digest
133+
id: build
134+
uses: docker/build-push-action@v6
135+
with:
136+
file: docker/Dockerfile.kubectl
137+
platforms: ${{ matrix.platform }}
138+
build-args: |
139+
KUBECTL_VERSION=${{ env.KUBECTL_VERSION }}
140+
labels: ${{ steps.meta.outputs.labels }}
141+
outputs: type=image,name=${{ env.IMAGE_REGISTRY }}/${{ env.KUBECTL_IMAGE_REPOSITORY }},push-by-digest=true,name-canonical=true,push=true
142+
143+
- name: Export digest
144+
run: |
145+
mkdir -p /tmp/digests
146+
digest="${{ steps.build.outputs.digest }}"
147+
touch "/tmp/digests/${digest#sha256:}"
148+
149+
- name: Upload digest
150+
uses: actions/upload-artifact@v4
151+
with:
152+
name: digests-kubectl-${{ env.PLATFORM_PAIR }}
153+
path: /tmp/digests/*
154+
if-no-files-found: error
155+
retention-days: 1
156+
157+
release_operator_images:
158+
needs:
159+
- build_operator_images
160+
161+
runs-on: ubuntu-latest
162+
163+
permissions:
164+
contents: read
165+
packages: write
166+
167+
steps:
168+
- name: Checkout source code
169+
uses: actions/checkout@v5
170+
171+
- name: Read version from VERSION file
172+
run: |
173+
VERSION=$(cat VERSION)
174+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
175+
176+
- name: Docker meta
177+
id: meta
178+
uses: docker/metadata-action@v5
179+
with:
180+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.OPERATOR_IMAGE_REPOSITORY }}
181+
tags: |
182+
type=raw,value=latest
183+
184+
- name: Download digests
185+
uses: actions/download-artifact@v5
186+
with:
187+
path: /tmp/digests
188+
pattern: digests-operator-*
189+
merge-multiple: true
190+
191+
- name: Set up Docker buildx
192+
uses: docker/setup-buildx-action@v3
193+
194+
- name: Login to container registry
195+
uses: docker/login-action@v3
196+
with:
197+
registry: ${{ env.IMAGE_REGISTRY }}
198+
username: ${{ github.actor }}
199+
password: ${{ secrets.GITHUB_TOKEN }}
200+
201+
- name: Create manifest list and push
202+
working-directory: /tmp/digests
203+
run: |
204+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
205+
$(printf '${{ env.IMAGE_REGISTRY }}/${{ env.OPERATOR_IMAGE_REPOSITORY }}@sha256:%s ' *)
206+
207+
- name: Inspect image
208+
run: |
209+
docker buildx imagetools inspect ${{ env.IMAGE_REGISTRY }}/${{ env.OPERATOR_IMAGE_REPOSITORY }}:${{ steps.meta.outputs.version }}
210+
211+
release_kubectl_images:
212+
needs:
213+
- build_kubectl_images
214+
215+
runs-on: ubuntu-latest
216+
217+
permissions:
218+
contents: read
219+
packages: write
220+
221+
steps:
222+
- name: Checkout source code
223+
uses: actions/checkout@v5
224+
225+
- name: Read version from VERSION file
226+
run: |
227+
VERSION=$(cat VERSION)
228+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
229+
230+
- name: Docker meta
231+
id: meta
232+
uses: docker/metadata-action@v5
233+
with:
234+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.KUBECTL_IMAGE_REPOSITORY }}
235+
tags: |
236+
type=raw,value=latest
237+
238+
- name: Download digests
239+
uses: actions/download-artifact@v5
240+
with:
241+
path: /tmp/digests
242+
pattern: digests-kubectl-*
243+
merge-multiple: true
244+
245+
- name: Set up Docker buildx
246+
uses: docker/setup-buildx-action@v3
247+
248+
- name: Login to container registry
249+
uses: docker/login-action@v3
250+
with:
251+
registry: ${{ env.IMAGE_REGISTRY }}
252+
username: ${{ github.actor }}
253+
password: ${{ secrets.GITHUB_TOKEN }}
254+
255+
- name: Create manifest list and push
256+
working-directory: /tmp/digests
257+
run: |
258+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
259+
$(printf '${{ env.IMAGE_REGISTRY }}/${{ env.KUBECTL_IMAGE_REPOSITORY }}@sha256:%s ' *)
260+
261+
- name: Inspect image
262+
run: |
263+
docker buildx imagetools inspect ${{ env.IMAGE_REGISTRY }}/${{ env.KUBECTL_IMAGE_REPOSITORY }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)