Skip to content

Commit bfa2860

Browse files
authored
Build image with ko (#2955)
* Build image with ko * Downgrade to ko v0.11.2 * Use eks-distro-minimal-base-nonroot as base image * Specify ko build options
1 parent 9b1032c commit bfa2860

File tree

6 files changed

+55
-58
lines changed

6 files changed

+55
-58
lines changed

.ko.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defaultBaseImage: public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-nonroot:2022-07-27-1658910674.2
2+
builds:
3+
- env:
4+
- CGO_ENABLED=0
5+
flags:
6+
- -mod=readonly
7+
ldflags:
8+
- -s
9+
- -w
10+
- -X sigs.k8s.io/aws-load-balancer-controller/pkg/version.GitVersion={{.Env.GIT_VERSION}}
11+
- -X sigs.k8s.io/aws-load-balancer-controller/pkg/version.GitCommit={{.Env.GIT_COMMIT}}
12+
- -X sigs.k8s.io/aws-load-balancer-controller/pkg/version.BuildDate={{.Env.BUILD_DATE}}
13+

Dockerfile

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

Makefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))
33

44
# Image URL to use all building/pushing image targets
55
IMG ?= public.ecr.aws/eks/aws-load-balancer-controller:v2.4.6
6+
IMG_PLATFORM ?= linux/amd64,linux/arm64
7+
# ECR doesn't appear to support SPDX SBOM
8+
IMG_SBOM ?= none
9+
610

711
CRD_OPTIONS ?= "crd:crdVersions=v1"
812

@@ -75,13 +79,16 @@ aws-sdk-model-override:
7579
./scripts/aws_sdk_model_override/cleanup.sh ; \
7680
fi
7781

82+
.PHONY: docker-push
83+
docker-push: aws-load-balancer-controller-push
7884

79-
# Push the docker image
80-
docker-push:
81-
docker buildx build . --target bin \
82-
--tag $(IMG) \
83-
--push \
84-
--platform linux/amd64,linux/arm64
85+
.PHONY: aws-load-balancer-controller-push
86+
aws-load-balancer-controller-push: ko
87+
KO_DOCKER_REPO=$(firstword $(subst :, ,${IMG})) \
88+
GIT_VERSION=$(shell git describe --tags --dirty --always) \
89+
GIT_COMMIT=$(shell git rev-parse HEAD) \
90+
BUILD_DATE=$(shell date +%Y-%m-%dT%H:%M:%S%z) \
91+
ko build --tags $(word 2,$(subst :, ,${IMG})) --platform=${IMG_PLATFORM} --bare --sbom ${IMG_SBOM} .
8592

8693
# find or download controller-gen
8794
# download controller-gen if necessary
@@ -134,6 +141,10 @@ else
134141
KUSTOMIZE=$(shell which kustomize)
135142
endif
136143

144+
.PHONY: ko
145+
ko:
146+
hack/install-ko.sh
147+
137148
# preview docs
138149
docs-preview: docs-dependencies
139150
pipenv run mkdocs serve

hack/install-ko.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2022 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
if ! command -v ko &> /dev/null; then
22+
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
23+
go install github.com/google/[email protected]
24+
fi

helm/aws-load-balancer-controller/templates/deployment.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ spec:
153153
value: "{{ $value }}"
154154
{{- end }}
155155
{{- end }}
156-
command:
157-
- /controller
158156
securityContext:
159157
{{- toYaml .Values.securityContext | nindent 10 }}
160158
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"

scripts/ci_e2e_test.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,7 @@ build_push_controller_image() {
7272
fi
7373

7474
echo "build and push docker image ${CONTROLLER_IMAGE_NAME}"
75-
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx create --use
76-
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx inspect --bootstrap
77-
78-
# TODO: the first buildx build sometimes fails on new created builder instance.
79-
# figure out why and remove this retry.
80-
n=0
81-
until [ "$n" -ge 2 ]; do
82-
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build . --target bin \
83-
--tag "${CONTROLLER_IMAGE_NAME}" \
84-
--push \
85-
--progress plain \
86-
--platform linux/amd64 && break
87-
n=$((n + 1))
88-
sleep 2
89-
done
75+
make docker-push IMG=${CONTROLLER_IMAGE_NAME} IMG_PLATFORM=linux/amd64
9076

9177
if [[ $? -ne 0 ]]; then
9278
echo "unable to build and push docker image" >&2

0 commit comments

Comments
 (0)