Skip to content

Commit 38191d8

Browse files
committed
[ci] replace Docker with ko for image build and push
Signed-off-by: Moshe Vayner <moshe@vayner.me>
1 parent ee8fb3b commit 38191d8

8 files changed

Lines changed: 62 additions & 92 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ jobs:
6767
dl.k8s.io:443
6868
get.helm.sh:443
6969
githubapp.com:443
70-
7170
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7271
with:
7372
fetch-depth: 0
@@ -95,7 +94,7 @@ jobs:
9594
- name: Build
9695
run: mise run build
9796

98-
docker-build:
97+
ko-build:
9998
runs-on: ubuntu-latest
10099
steps:
101100
- name: Harden Runner
@@ -118,24 +117,17 @@ jobs:
118117
dl.k8s.io:443
119118
get.helm.sh:443
120119
githubapp.com:443
120+
cgr.dev:443
121+
mise.jdx.dev:443
122+
mise-versions.jdx.dev:443
121123
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
122124
with:
123125
fetch-depth: 0
124-
- name: Docker Meta
125-
id: meta
126-
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
127-
with:
128-
images: |
129-
linode/linode-cloud-controller-manager
130-
tags: |
131-
type=raw,value=pr-${{ github.event.pull_request.number }},enable=${{ github.event_name == 'pull_request' }}
132-
type=raw,value=latest,enable=${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
133-
- name: Build Dockerfile
134-
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
126+
127+
- name: Set up Mise
128+
uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
135129
with:
136-
context: .
137-
push: false
138-
tags: ${{ steps.meta.outputs.tags }}
139-
labels: ${{ steps.meta.outputs.labels }}
140-
build-args: |
141-
REV=${{ github.ref_name }}
130+
install_args: go ko
131+
132+
- name: Validate ko image build
133+
run: mise run ko-build

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ jobs:
9696
env:
9797
GITHUB_TOKEN: ${{ secrets.github_token }}
9898
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
99-
IMG: linode/linode-cloud-controller-manager:${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'latest' || format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
99+
KO_DOCKER_REPO: docker.io/linode/linode-cloud-controller-manager
100+
IMAGE_TAGS: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'latest' || format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
101+
IMG: docker.io/linode/linode-cloud-controller-manager:${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'latest' || format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
100102
LINODE_REGION: us-lax
101103
LINODE_CONTROL_PLANE_MACHINE_TYPE: g6-standard-2
102104
LINODE_MACHINE_TYPE: g6-standard-2

.github/workflows/release.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,20 @@ jobs:
2929
with:
3030
files: |
3131
./release/helm-chart-${{ github.ref_name }}.tgz
32-
- name: Docker Meta
33-
id: meta
34-
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
32+
33+
- name: Set up Mise
34+
uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0
3535
with:
36-
images: |
37-
linode/linode-cloud-controller-manager
38-
tags: |
39-
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
40-
type=semver,pattern={{raw}},value=${{ github.ref_name }}
36+
install_args: go ko
37+
4138
- name: Login to Docker Hub
4239
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
4340
with:
4441
username: ${{ secrets.DOCKER_USERNAME }}
4542
password: ${{ secrets.DOCKER_PASSWORD }}
46-
- name: Build and Push to Docker Hub
47-
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
48-
with:
49-
context: .
50-
push: true
51-
tags: ${{ steps.meta.outputs.tags }}
52-
labels: ${{ steps.meta.outputs.labels }}
43+
44+
- name: Build and Push to Docker Hub with ko
45+
run: mise run ko-publish
46+
env:
47+
KO_DOCKER_REPO: docker.io/linode/linode-cloud-controller-manager
48+
IMAGE_TAGS: ${{ github.ref_name }}

.ko.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defaultBaseImage: gcr.io/distroless/static:nonroot
2+
defaultPlatforms:
3+
- linux/arm64
4+
- linux/amd64
5+

Dockerfile

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

Makefile

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
IMG ?= linode/linode-cloud-controller-manager:canary
1+
KO_DOCKER_REPO ?= docker.io/linode/linode-cloud-controller-manager
2+
IMAGE_TAGS ?= canary
3+
IMG ?= $(KO_DOCKER_REPO):canary
24
RELEASE_DIR ?= release
35
PLATFORM ?= linux/amd64
46

@@ -95,23 +97,20 @@ release:
9597
tar -czvf ./$(RELEASE_DIR)/helm-chart-$(IMAGE_VERSION).tgz -C ./deploy/chart .
9698

9799
.PHONY: imgname
98-
# print the Docker image name that will be used
100+
# print the container image name that will be used
99101
# useful for subsequently defining it on the shell
100102
imgname:
101103
echo IMG=${IMG}
102104

103-
.PHONY: docker-build
104-
# we cross compile the binary for linux, then build a container
105-
docker-build: build-linux
106-
DOCKER_BUILDKIT=1 docker build --platform=$(PLATFORM) --tag ${IMG} .
105+
.PHONY: ko-build
106+
# build the container image locally without pushing it to a registry
107+
ko-build:
108+
CGO_ENABLED=0 ko build --local --bare --tags "$(IMAGE_TAGS)" --platform=$(PLATFORM) .
107109

108-
.PHONY: docker-push
109-
# must run the docker build before pushing the image
110-
docker-push:
111-
docker push ${IMG}
112-
113-
.PHONY: build-and-push
114-
build-and-push: docker-build docker-push
110+
.PHONY: ko-publish
111+
# build the container image and publish it to the registry named by IMG
112+
ko-publish:
113+
CGO_ENABLED=0 KO_DOCKER_REPO="$(KO_DOCKER_REPO)" ko build --bare --tags "$(IMAGE_TAGS)" --platform=$(PLATFORM) .
115114

116115
.PHONY: run
117116
# run the ccm locally, really only makes sense on linux anyway
@@ -135,7 +134,7 @@ run-debug: build
135134
#####################################################################
136135

137136
.PHONY: mgmt-and-capl-cluster
138-
mgmt-and-capl-cluster: build-and-push mgmt-cluster
137+
mgmt-and-capl-cluster: ko-publish mgmt-cluster
139138
$(MAKE) -j2 capl-ipv6-cluster capl-cluster
140139

141140
.PHONY: capl-cluster

docs/development/README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,37 @@ cd $(go env GOPATH)/src/github.com/linode/linode-cloud-controller-manager
5353

5454
#### Build Binary
5555

56-
Use the following Make targets to build and run a local binary:
56+
Use the following mise tasks to build and run a local binary:
5757

5858
```bash
5959
# Build the binary
60-
make build
60+
mise run build
6161

6262
# Run the binary
63-
make run
63+
mise run run
6464

6565
# You can also run the binary directly to pass additional args
6666
dist/linode-cloud-controller-manager
6767
```
6868

69-
#### Building Docker Images
69+
#### Building Container Images
7070

71-
These targets still rely on a system Docker installation in this first migration phase.
71+
The local image build task loads the built image into your local Docker-compatible daemon.
7272

73-
To build and push a Docker image:
73+
To build and push an image with ko:
7474

7575
```bash
76-
# Set the repo/image:tag with the TAG environment variable
77-
# Then run the docker-build make target
78-
IMG=linode/linode-cloud-controller-manager:canary make docker-build
76+
# Build locally into your Docker-compatible daemon
77+
IMAGE_TAGS=canary mise run ko-build
7978

80-
# Push Image
81-
IMG=linode/linode-cloud-controller-manager:canary make docker-push
79+
# Publish Image
80+
KO_DOCKER_REPO=docker.io/linode/linode-cloud-controller-manager IMAGE_TAGS=canary mise run ko-publish
8281
```
8382

84-
To run the Docker image:
83+
To run the locally built image after `ko-build`:
8584

8685
```bash
87-
docker run -ti linode/linode-cloud-controller-manager:canary
86+
docker run -ti ko.local/github.com/linode/linode-cloud-controller-manager:canary
8887
```
8988

9089
### Managing Dependencies

mise.toml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ kustomize = "5.8.1"
1414
kind = "0.31.0"
1515
ctlptl = "0.9.0"
1616
clusterctl = "1.8.5"
17+
ko = "0.19.1"
1718
"go:github.com/kyverno/chainsaw" = "0.2.15"
1819
"go:github.com/golang/mock/mockgen" = "1.6.0"
1920
yq = "4.52.2"
@@ -32,13 +33,13 @@ run = "make clean"
3233
description = "Generate code"
3334
run = "make codegen"
3435

35-
[tasks.docker-build]
36-
description = "Build the Docker image with the current Make target"
37-
run = "make docker-build"
36+
[tasks.ko-build]
37+
description = "Build the container image locally with ko"
38+
run = "make ko-build"
3839

39-
[tasks.docker-push]
40-
description = "Push the Docker image built by the current Make target"
41-
run = "make docker-push"
40+
[tasks.ko-publish]
41+
description = "Build and publish the container image with ko"
42+
run = "make ko-publish"
4243

4344
[tasks.fmt]
4445
description = "Run go fmt"
@@ -120,8 +121,3 @@ run = "make run-debug"
120121
[tasks.test]
121122
description = "Run unit tests"
122123
run = "make test"
123-
124-
125-
126-
127-

0 commit comments

Comments
 (0)