Skip to content

Commit 86b3fcf

Browse files
committed
build: Use ko for building OCI image
1 parent 345a7e2 commit 86b3fcf

File tree

13 files changed

+251
-376
lines changed

13 files changed

+251
-376
lines changed

.github/workflows/checks.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@ jobs:
151151
fail_on_error: true
152152
reporter: github-pr-review
153153

154-
lint-dockerfile:
155-
runs-on: ubuntu-22.04
156-
steps:
157-
- name: Check out code
158-
uses: actions/checkout@v4
159-
160-
- name: actionlint
161-
uses: reviewdog/action-hadolint@v1
162-
with:
163-
fail_on_error: true
164-
reporter: github-pr-review
165-
166154
pre-commit:
167155
runs-on: ubuntu-22.04
168156
defaults:
@@ -254,7 +242,7 @@ jobs:
254242
devbox run -- \
255243
kind load docker-image \
256244
--name chart-testing \
257-
"$(devbox run -- gojq -r '.[] | select(.type == "Docker Image" and .goos == "linux" and .goarch == "amd64").name' dist/artifacts.json)"
245+
"ko.local/capi-runtime-extensions:$(devbox run -- gojq -r .version dist/metadata.json)"
258246
259247
- if: steps.list-changed.outputs.changed == 'true'
260248
name: Setup Cluster API and cert-manager
@@ -270,7 +258,7 @@ jobs:
270258
devbox run -- \
271259
ct install \
272260
--config charts/ct-config.yaml \
273-
--helm-extra-set-args "--set=image.tag=$(devbox run -- jq -r .version dist/metadata.json)"
261+
--helm-extra-set-args "--set-string image.repository=ko.local/capi-runtime-extensions --set-string image.tag=$(devbox run -- gojq -r .version dist/metadata.json)"
274262
env:
275263
KUBECONFIG: ct-kind-kubeconfig
276264

.goreleaser.yml

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,58 +49,47 @@ builds:
4949
- arm64
5050
mod_timestamp: '{{ .CommitTimestamp }}'
5151
hooks:
52-
post:
53-
- cmd: make SKIP_UPX={{ if index .Env "SKIP_UPX" }}{{ .Env.SKIP_UPX }}{{ else }}{{ .IsSnapshot }}{{ end }} GOOS={{ .Os }} GOARCH={{ .Arch }} UPX_TARGET={{ .Path }} upx
52+
post: |
53+
sh -ec 'if [ {{ .IsSnapshot }} == true ] && [ {{ .Runtime.Goarch }} == {{ .Arch }} ]; then
54+
env GOOS=linux GOARCH={{ .Arch }} \
55+
SOURCE_DATE_EPOCH=$(date +%s) \
56+
KO_DOCKER_REPO=ko.local/capi-runtime-extensions \
57+
ko build \
58+
--bare \
59+
-t {{ .Version }} \
60+
./cmd
61+
fi'
5462
archives:
5563
- name_template: '{{ .ProjectName }}_v{{trimprefix .Version "v"}}_{{ .Os }}_{{ .Arch }}'
5664
rlcp: true
5765
builds:
5866
- capi-runtime-extensions
59-
dockers:
60-
- image_templates:
61-
# Specify the image tag including `-amd64` suffix if the build is not a snapshot build or is not being built on
62-
# arm64 machine. This allows for using the snapshot image build without the architecture specific suffix
63-
# consistently on local machines, i.e. can always use `ghcr.io/d2iq-labs/capi-runtime-extensions:v<VERSION>` on the machine the snapshot
64-
# is built on.
65-
#
66-
# For a release build the `-amd64` suffix will always be included and the `docker_manifests` specification below
67-
# will create the final multiplatform manifest to be pushed to the registry.
68-
- ghcr.io/d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "amd64")) }}-amd64{{ end }}
69-
use: buildx
70-
dockerfile: Dockerfile
71-
build_flag_templates:
72-
- "--platform=linux/amd64"
73-
- "--pull"
74-
- "--label=org.opencontainers.image.created={{.Date}}"
75-
- "--label=org.opencontainers.image.title={{.ProjectName}}"
76-
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
77-
- "--label=org.opencontainers.image.version={{.Version}}"
78-
- "--label=org.opencontainers.image.source={{.GitURL}}"
79-
- image_templates:
80-
# Specify the image tag including `-amd64v8` suffix if the build is not a snapshot build or is not being built on
81-
# arm64 machine. This allows for using the snapshot image build without the architecture specific suffix
82-
# consistently on local machines, i.e. can always use `ghcr.io/d2iq-labs/capi-runtime-extensions:v<VERSION>` on the machine the snapshot
83-
# is built on.
84-
#
85-
# For a release build the `-amd64v8` suffix will always be included and the `docker_manifests` specification below
86-
# will create the final multiplatform manifest to be pushed to the registry.
87-
- ghcr.io/d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}{{ if or (not .IsSnapshot) (not (eq .Runtime.Goarch "arm64")) }}-arm64v8{{ end }}
88-
use: buildx
89-
goarch: arm64
90-
dockerfile: Dockerfile
91-
build_flag_templates:
92-
- "--platform=linux/arm64"
93-
- "--pull"
94-
- "--label=org.opencontainers.image.created={{.Date}}"
95-
- "--label=org.opencontainers.image.title={{.ProjectName}}"
96-
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
97-
- "--label=org.opencontainers.image.version={{.Version}}"
98-
- "--label=org.opencontainers.image.source={{.GitURL}}"
99-
docker_manifests:
100-
- name_template: ghcr.io/d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}
101-
image_templates:
102-
- ghcr.io/d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}-amd64
103-
- ghcr.io/d2iq-labs/{{.ProjectName}}:v{{trimprefix .Version "v"}}-arm64v8
67+
kos:
68+
- id: capi-runtime-extensions
69+
build: capi-runtime-extensions
70+
ldflags:
71+
- -s
72+
- -w
73+
- -X 'k8s.io/component-base/version.buildDate={{ .CommitDate }}'
74+
- -X 'k8s.io/component-base/version.gitCommit={{ .FullCommit }}'
75+
- -X 'k8s.io/component-base/version.gitTreeState={{ .Env.GIT_TREE_STATE }}'
76+
- -X 'k8s.io/component-base/version.gitVersion=v{{ trimprefix .Version "v" }}'
77+
- -X 'k8s.io/component-base/version.major={{ .Major }}'
78+
- -X 'k8s.io/component-base/version.minor={{ .Minor }}'
79+
- -X 'k8s.io/component-base/version/verflag.programName={{ .ProjectName }}'
80+
labels:
81+
org.opencontainers.image.created: "{{ .CommitDate }}"
82+
org.opencontainers.image.title: capi-runtime-extensions
83+
org.opencontainers.image.revision: "{{ .FullCommit }}"
84+
org.opencontainers.image.version: v{{trimprefix .Version "v"}}
85+
org.opencontainers.image.source: "{{ .GitURL }}"
86+
platforms:
87+
- linux/amd64
88+
- linux/arm64
89+
repository: '{{ envOrDefault "KO_DOCKER_REPO" "ghcr.io/d2iq-labs/capi-runtime-extensions" }}'
90+
bare: true
91+
tags:
92+
- v{{trimprefix .Version "v"}}
10493
checksum:
10594
name_template: 'checksums.txt'
10695
snapshot:

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ repos:
7373
hooks:
7474
- id: actionlint-system
7575
stages: [commit]
76-
- repo: https://github.com/hadolint/hadolint
77-
rev: v2.12.1-beta
78-
hooks:
79-
- id: hadolint
8076
- repo: https://github.com/jorisroovers/gitlint
8177
rev: v0.19.1
8278
hooks:

Dockerfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

devbox.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"packages": [
33
"actionlint@latest",
4-
"chart-testing@3.8.0",
4+
"chart-testing@latest",
55
"clusterctl@latest",
66
"coreutils@latest",
77
"crane@latest",
@@ -17,10 +17,10 @@
1717
"golines@latest",
1818
"goreleaser@latest",
1919
"gotestsum@latest",
20-
"hadolint@latest",
2120
"helm-docs@latest",
22-
"hugo@0.117.0",
21+
"hugo@latest",
2322
"kind@latest",
23+
"ko@latest",
2424
"kubebuilder@latest",
2525
"kubectl@latest",
2626
"kubernetes-controller-tools@latest",
@@ -29,7 +29,6 @@
2929
"pre-commit@latest",
3030
"rsync@latest",
3131
"shfmt@latest",
32-
"upx@latest",
3332
"yamale@latest",
3433
"yamllint@latest",
3534
"path:./hack/flakes#go-mod-upgrade",

0 commit comments

Comments
 (0)