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

Use ko to build container image #19

Merged
merged 1 commit into from
Aug 19, 2021
Merged

Use ko to build container image #19

merged 1 commit into from
Aug 19, 2021

Conversation

scothis
Copy link
Contributor

@scothis scothis commented Aug 19, 2021

ko is a tool that can build and deploy k8s resources that reference
go paths.

https://github.com/google/ko

ko works by finding ko:// references in the k8s yaml that point at a
go compile target, the built binary is placed into the base image and
pushed to an image registry specified by the KO_DOCKER_REPO env var. A
digested reference to the pushed image is substituted into the yaml
replacing the ko://... reference.

In this case, we can replace direct dependencies on the kubectl and
docker CLIs and the Docker daemon. ko also makes it much easier to
produce multi-platform/architecture images for which there is a
compatible base image (gcr.io/distroless/static:nonroot by default) and
can be cross compiled by go.

Signed-off-by: Scott Andrews andrewssc@vmware.com

`ko` is a tool that can build and deploy k8s resources that reference
go paths which are build and transparently substituted into the
resulting resources.

ko works by finding `ko://` references in the k8s yaml that point at a
go compile target, the built binary is placed into the base image and
pushed to an image registry specified by the KO_DOCKER_REPO env var. A
digested reference to the pushed image is substituted into the yaml
replacing the `ko://...` reference.

https://github.com/google/ko

In this case, we can replace direct dependencies on the kubectl and
docker CLIs and the Docker daemon. ko also makes it much easier to
produce multi-platform/architecture images for which there is a
compatible base image (gcr.io/distroless/static:nonroot by default) and
can be cross compiled by go.

Signed-off-by: Scott Andrews <andrewssc@vmware.com>
@scothis scothis requested a review from a team August 19, 2021 14:54
@@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
controller-gen.kubebuilder.io/version: v0.6.2
Copy link
Member

Choose a reason for hiding this comment

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

This is an unrelated change, right?
I think we need a check in the CI to ensure make generate and make manifests commands are run.
For now, let this change go with this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly, 👍

Copy link
Member

Choose a reason for hiding this comment

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

Created PR to add the check: #20

@@ -67,23 +63,16 @@ build: generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
Copy link
Member

Choose a reason for hiding this comment

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

Do we need an equivalent ko command to build an image here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ko apply will:

  • build images
  • publish images to the registry
  • substitute the image into the yaml
  • apply the yaml to the cluster

Copy link
Member

Choose a reason for hiding this comment

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

Ok 👍

I am new to this tool. Thanks for the explanation.

docker build -t ${IMG} .

docker-push: ## Push docker image with the manager.
docker push ${IMG}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need an equivalent ko command to push the image here?

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
Member

@baijum baijum left a comment

Choose a reason for hiding this comment

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

LGTM

@scothis scothis merged commit ad1357d into servicebinding:main Aug 19, 2021
@scothis scothis deleted the ko branch August 19, 2021 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants