Skip to content

Instantly share code, notes, and snippets.

@samlaf
Last active May 27, 2024 05:21
Show Gist options
  • Save samlaf/acc7a766df30e2a01276bbb1a1313942 to your computer and use it in GitHub Desktop.
Save samlaf/acc7a766df30e2a01276bbb1a1313942 to your computer and use it in GitHub Desktop.
Ko build flags

Ko has different build flags to change the docker image repo path: https://ko.build/reference/ko_build/

We have an example repo with dir cmd/hello-k8s/main.go.

ko command flags, and their resulting published image

Realized options and results are already described in https://ko.build/configuration/#naming-images

  1. no flags
KO_DOCKER_REPO=ghcr.io/samlaf ko build cmd/hello-k8s/main.go

Creates

image
  1. --bare this will only work if repo name is an actual repo
KO_DOCKER_REPO=ghcr.io/samlaf/hello-k8s ko build --bare cmd/hello-k8s/main.go        
  1. --base-import-paths
KO_DOCKER_REPO=ghcr.io/samlaf ko build --base-import-paths cmd/hello-k8s/main.go
image
  1. --preserve-import-paths
KO_DOCKER_REPO=ghcr.io/samlaf ko build --preserve-import-paths cmd/hello-k8s/main.go
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment