Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build image with ko #2955

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It failed for me with the following error:

go: downloading github.com/go-openapi/analysis v0.21.3
../../go/pkg/mod/github.com/go-openapi/validate@v0.22.0/spec.go:23:2: github.com/go-openapi/analysis@v0.21.3: verifying module: checksum mismatch
	downloaded: h1:vR88pR69D/jGh02vPbT4qoxiG+p9e5uT75JJG3O1JIU=
	sum.golang.org: h1:CPEa+B2oYCkb+lIKB4xP6Ork8Gvh0GNg9dm/twI3+QA=

I was able to install v0.11.2 and run the tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're apparently not the first to run across this. I found go-openapi/analysis#81

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I back off to v0.11.2?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets back off to v0.11.2, we can update in future

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a standard entrypoint for ko built container images?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. See the last sentence of https://ko.build/get-started

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The entrypoint change will introduce backwards incompatibility with the existing manifests, we will release note it.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this not affect the multi-arch tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code specified --platform linux/amd64 so I preserved that behavior.


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