-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
`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>
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly, 👍
There was a problem hiding this comment.
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} . |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ko
is a tool that can build and deploy k8s resources that referencego paths.
https://github.com/google/ko
ko works by finding
ko://
references in the k8s yaml that point at ago 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