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

Build image with ko #2955

merged 4 commits into from
Jan 24, 2023

Conversation

johngmyers
Copy link
Contributor

Issue

N/A

Description

Uses ko to build the LBC image.

Reduces build time significantly and increases build reliability. Previously builds would take 15 minutes to over 2 hours and would fail about 3 out of 4 times, both because of the go mod download in the Dockerfile.

Checklist

  • N/A Added tests that cover your change (if possible)
  • N/A Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 3, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 3, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jan 3, 2023

Codecov Report

Base: 54.07% // Head: 54.01% // Decreases project coverage by -0.06% ⚠️

Coverage data is based on head (28b7f84) compared to base (a92e689).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2955      +/-   ##
==========================================
- Coverage   54.07%   54.01%   -0.06%     
==========================================
  Files         144      144              
  Lines        8301     8312      +11     
==========================================
+ Hits         4489     4490       +1     
- Misses       3484     3494      +10     
  Partials      328      328              
Impacted Files Coverage Δ
pkg/config/controller_config.go 15.38% <0.00%> (-2.48%) ⬇️
pkg/ingress/model_builder.go 63.90% <0.00%> (-0.32%) ⬇️
pkg/service/model_builder.go 88.29% <0.00%> (+0.12%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@johngmyers
Copy link
Contributor Author

/retest

@olemarkus
Copy link
Contributor

I strongly support this! Building LBC is a bit prohibitive right now.

@kishorj
Copy link
Collaborator

kishorj commented Jan 11, 2023

Thanks for the contribution, I will look into this changes post the v2.4.6 patch release.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 12, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 12, 2023
@johngmyers
Copy link
Contributor Author

/retest

Copy link
Collaborator

@kishorj kishorj left a comment

Choose a reason for hiding this comment

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

I have two items I'm trying to work through at the moment:

  1. ability to save to tarball, the --tarball flag to build command appears to be the way to go
  2. Configuring a base image. The ko build appears to use a debian based image, I'm not certain if there is a fixed image per ko version, or it depends on the latest one available at the time of the build. I'm also interested to see how we can address the base image CVEs.


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

@@ -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.

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.

@johngmyers
Copy link
Contributor Author

The base image is cgr.dev/chainguard/static and it takes what is the latest at the time of build.

Information on overriding the base image is at https://ko.build/configuration/#overriding-base-images

I doubt we'd be faster at fixing CVEs than Chainguard.

@johngmyers
Copy link
Contributor Author

Did you want a make target to create a tarball? Should that be instead of or in addition to pushing to a registry?

@kishorj
Copy link
Collaborator

kishorj commented Jan 21, 2023

The base image is cgr.dev/chainguard/static and it takes what is the latest at the time of build.

Information on overriding the base image is at https://ko.build/configuration/#overriding-base-images

I doubt we'd be faster at fixing CVEs than Chainguard.

Lets use public.ecr.aws/eks-distro-build-tooling/eks-distro-minimal-base-nonroot:2022-07-27-1658910674.2 as the base image. Since the base image is internal, it will help us meet the SLAs for addressing the CVEs.

@kishorj
Copy link
Collaborator

kishorj commented Jan 21, 2023

Did you want a make target to create a tarball? Should that be instead of or in addition to pushing to a registry?

This is a separate requirement for publishing the official ECR images. We can revisit it when it is time to publish the v2.5.0 images.

@kishorj
Copy link
Collaborator

kishorj commented Jan 21, 2023

Please preserve the existing ldflags and the build flags to the extent possible/necessary, especially the version information.

@johngmyers
Copy link
Contributor Author

Is there any particular reason to use CGO? It doesn't appear to be needed.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 21, 2023
@johngmyers
Copy link
Contributor Author

This configuration removes a whole swath of attack surface by disabling CGO.

@kishorj
Copy link
Collaborator

kishorj commented Jan 24, 2023

Is there any particular reason to use CGO? It doesn't appear to be needed.

We don't need, lets remove it

@kishorj kishorj added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jan 24, 2023
@kishorj
Copy link
Collaborator

kishorj commented Jan 24, 2023

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: johngmyers, kishorj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 24, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 24, 2023
@k8s-ci-robot k8s-ci-robot merged commit bfa2860 into kubernetes-sigs:main Jan 24, 2023
@johngmyers johngmyers deleted the ko branch January 24, 2023 01:59
@johngmyers johngmyers mentioned this pull request Aug 23, 2023
12 tasks
Timothy-Dougherty pushed a commit to adammw/aws-load-balancer-controller that referenced this pull request Nov 9, 2023
* Build image with ko

* Downgrade to ko v0.11.2

* Use eks-distro-minimal-base-nonroot as base image

* Specify ko build options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants