Skip to content

Commit

Permalink
Build image with ko
Browse files Browse the repository at this point in the history
  • Loading branch information
johngmyers committed Jan 12, 2023
1 parent a92e689 commit caa7140
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 58 deletions.
35 changes: 0 additions & 35 deletions Dockerfile

This file was deleted.

19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))

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


CRD_OPTIONS ?= "crd:crdVersions=v1"

Expand Down Expand Up @@ -74,13 +78,12 @@ aws-sdk-model-override:
./scripts/aws_sdk_model_override/cleanup.sh ; \
fi

.PHONY: docker-push
docker-push: aws-load-balancer-controller-push

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

# find or download controller-gen
# download controller-gen if necessary
Expand Down Expand Up @@ -115,6 +118,10 @@ else
KUSTOMIZE=$(shell which kustomize)
endif

.PHONY: ko
ko:
hack/install-ko.sh

# preview docs
docs-preview: docs-dependencies
pipenv run mkdocs serve
Expand Down
24 changes: 24 additions & 0 deletions hack/install-ko.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# Copyright 2022 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

if ! command -v ko &> /dev/null; then
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
go install github.com/google/ko@v0.12.0
fi
2 changes: 0 additions & 2 deletions helm/aws-load-balancer-controller/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ spec:
value: "{{ $value }}"
{{- end }}
{{- end }}
command:
- /controller
securityContext:
{{- toYaml .Values.securityContext | nindent 10 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Expand Down
16 changes: 1 addition & 15 deletions scripts/ci_e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,7 @@ build_push_controller_image() {
fi

echo "build and push docker image ${CONTROLLER_IMAGE_NAME}"
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx create --use
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx inspect --bootstrap

# TODO: the first buildx build sometimes fails on new created builder instance.
# figure out why and remove this retry.
n=0
until [ "$n" -ge 2 ]; do
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build . --target bin \
--tag "${CONTROLLER_IMAGE_NAME}" \
--push \
--progress plain \
--platform linux/amd64 && break
n=$((n + 1))
sleep 2
done
make docker-push IMG=${CONTROLLER_IMAGE_NAME} IMG_PLATFORM=linux/amd64

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

0 comments on commit caa7140

Please sign in to comment.