Skip to content

Commit 03345c8

Browse files
committed
Use KO for building and pushing images
This uses the ko tool to build and push images to ghcr.io. Since building with docker has some issues lately. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent c6a7841 commit 03345c8

File tree

1 file changed

+54
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)