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

Improve ko run #76

Merged
merged 1 commit into from
Dec 6, 2019
Merged

Conversation

jonjohnsonjr
Copy link
Collaborator

@jonjohnsonjr jonjohnsonjr commented Aug 16, 2019

Shift the UX closer to go run than kubectl run.

This also adds some flags to make ko run spin up a pod, attach logs, and automatically clean itself up.

This drops the ability to override kubectl flags, but if you're going to do that I'd say just use some yaml 🤷‍♂.

Edit: Matt pointed out that you can just do kubectl run --name=$(ko publish IMPORTPATH) if you want to control flags, which is really nice. I'm happy with keeping ko run as just easy defaults.

Fixes #5

$ ko run ./cmd/ko -- run -h
2019/08/16 11:25:06 Building github.com/google/ko/cmd/ko
2019/08/16 11:25:12 Using base gcr.io/distroless/static:latest for github.com/google/ko/cmd/ko
2019/08/16 11:25:13 Publishing gcr.io/jonjohnson-test/ko/ko-099ba5bcefdead87f92606265fb99ac0:latest
2019/08/16 11:25:13 existing blob: sha256:72164b581b02b1eb297b403bcc8fc1bfa245cb52e103a3a525a0835a58ff58e2
2019/08/16 11:25:13 existing blob: sha256:e8d8785a314f385d3675a017f4e2df1707c528c06e7a7989663fdab4900bd8ff
2019/08/16 11:25:15 pushed blob: sha256:0fae946271ba011f82900b97d708352ba63d25a49e12e6a9e80779605b053400
2019/08/16 11:25:17 pushed blob: sha256:1519142143763d5f96d3cbb4b57d725a71f3c12e924b4492b3a0a45abbc5c530
2019/08/16 11:25:18 gcr.io/jonjohnson-test/ko/ko-099ba5bcefdead87f92606265fb99ac0:latest: digest: sha256:8c6a1882da175b22a7ae8dbc05c804b7538fd8c9a914c97b81a731f8a58d3f3c size: 751
2019/08/16 11:25:18 Published gcr.io/jonjohnson-test/ko/ko-099ba5bcefdead87f92606265fb99ac0@sha256:8c6a1882da175b22a7ae8dbc05c804b7538fd8c9a914c97b81a731f8a58d3f3c
2019/08/16 11:25:18 Running "github.com/google/ko/cmd/ko"
2019/08/16 11:25:19 $ kubectl run ko-099ba5bcefdead87f92606265fb99ac0 --image gcr.io/jonjohnson-test/ko/ko-099ba5bcefdead87f92606265fb99ac0@sha256:8c6a1882da175b22a7ae8dbc05c804b7538fd8c9a914c97b81a731f8a58d3f3c --generator=run-pod/v1 --attach --rm --restart=Never --log-flush-frequency=1s -- run -h
This sub-command combines "ko publish" and "kubectl run" to support containerizing and running Go binaries on Kubernetes in a single command.

Usage:
  ko run IMPORTPATH [flags]

Examples:

  # Publish the --image and run it on Kubernetes as:
  #   ${KO_DOCKER_REPO}/<package name>-<hash of import path>
  # When KO_DOCKER_REPO is ko.local, it is the same as if
  # --local and --preserve-import-paths were passed.
  ko run github.com/foo/bar/cmd/baz

  # This supports relative import paths as well.
  ko run ./cmd/baz

Flags:
  -B, --base-import-paths       Whether to use the base path without MD5 hash after KO_DOCKER_REPO.
      --disable-optimizations   Disable optimizations when building Go code. Useful when you want to interactively debug the created container.
  -h, --help                    help for run
      --insecure-registry       Whether to skip TLS verification on the registry
  -L, --local                   Whether to publish images to a local docker daemon vs. a registry.
  -P, --preserve-import-paths   Whether to preserve the full import path after KO_DOCKER_REPO.
  -t, --tags strings            Which tags to use for the produced image instead of the default 'latest' tag. (default [latest])
pod "ko-099ba5bcefdead87f92606265fb99ac0" deleted

@jonjohnsonjr
Copy link
Collaborator Author

This PR made debugging google/go-containerregistry#594 about 100x easier.

I was able to diagnose what was going on in basically 60 seconds with:

$ ko run ./cmd/gcrane/ -- cp -v ubuntu gcr.io/jonjohnson-test/ubuntu:copied

Make it more like go run.
@jonjohnsonjr jonjohnsonjr merged commit 835dcfb into ko-build:master Dec 6, 2019
@jonjohnsonjr jonjohnsonjr deleted the better-ko-run branch December 6, 2019 18:52
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.

ko run fails when there is a ko flag
2 participants