Skip to content

Commit caa7140

Browse files
committed
Build image with ko
1 parent a92e689 commit caa7140

File tree

5 files changed

+38
-58
lines changed

5 files changed

+38
-58
lines changed

Dockerfile

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

Makefile

Lines changed: 13 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

@@ -74,13 +78,12 @@ aws-sdk-model-override:
7478
./scripts/aws_sdk_model_override/cleanup.sh ; \
7579
fi
7680

81+
.PHONY: docker-push
82+
docker-push: aws-load-balancer-controller-push
7783

78-
# Push the docker image
79-
docker-push:
80-
docker buildx build . --target bin \
81-
--tag $(IMG) \
82-
--push \
83-
--platform linux/amd64,linux/arm64
84+
.PHONY: aws-load-balancer-controller-push
85+
aws-load-balancer-controller-push: ko
86+
KO_DOCKER_REPO=$(firstword $(subst :, ,${IMG})) ko build --tags $(word 2,$(subst :, ,${IMG})) --platform=${IMG_PLATFORM} --bare --sbom ${IMG_SBOM} .
8487

8588
# find or download controller-gen
8689
# download controller-gen if necessary
@@ -115,6 +118,10 @@ else
115118
KUSTOMIZE=$(shell which kustomize)
116119
endif
117120

121+
.PHONY: ko
122+
ko:
123+
hack/install-ko.sh
124+
118125
# preview docs
119126
docs-preview: docs-dependencies
120127
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)