Skip to content

Commit 880ef61

Browse files
committed
Use KO for building and pushing images
This uses the ko tool to build and push images to ghcr.io. Building with docker was crashing when compiling and is much slower than ko. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent c6a7841 commit 880ef61

File tree

2 files changed

+54
-121
lines changed

2 files changed

+54
-121
lines changed

.github/workflows/container.yaml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Create and publish a Docker image to ghcr on main and nightly with ko
2+
3+
on:
4+
push:
5+
paths:
6+
- "**.go"
7+
- "**.yaml"
8+
pull_request:
9+
paths:
10+
- "**.go"
11+
- "**.yaml"
12+
env:
13+
PLATFORMS: linux/amd64 linux/arm64 linux/ppc64le
14+
15+
jobs:
16+
build-and-push-image:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version-file: "go.mod"
34+
35+
- uses: ko-build/[email protected]
36+
37+
- name: Build and push images
38+
shell: bash
39+
run: |
40+
set -x
41+
releaseBranchFormat='release-v'
42+
if [[ ${{ github.ref_name }} == ${releaseBranchFormat}* ]]; then
43+
tag="${${{ github.ref_name }}#*-}"
44+
elif [[ ${{ github.ref }} == refs/pull/* ]]; then
45+
tag=pr-$(echo ${{ github.ref }} | cut -c11-|sed 's,/merge,,')
46+
else
47+
tag=$(echo ${{ github.ref }} | cut -c12-)
48+
fi
49+
50+
for platform in ${{ env.PLATFORMS }};do
51+
for image in ./cmd/*;do
52+
ko build -B -t "${tag}" --platform="${platform}" "${image}"
53+
done
54+
done

.github/workflows/ghcr.yaml

-121
This file was deleted.

0 commit comments

Comments
 (0)