1
0
mirror of https://github.com/ko-build/ko.git synced 2025-02-13 19:42:26 +02:00

74 Commits

Author SHA1 Message Date
Jason Hall
729419aebb
Add 'ko build' as a preferred alias for 'ko publish' (#456)
* Add 'ko build' as a preferred alias for 'ko publish'

* rm ko_publish.md
2021-10-05 08:48:57 -07:00
Jason Hall
5ac3ef93f7
Clean filepath from zip before creating tempdir (#459) 2021-10-01 14:20:21 -04:00
Jason Hall
b9cd759f25
Don't log the value of --password if given (#458) 2021-10-01 14:19:26 -04:00
jonjohnsonjr
45467f076b
Do not require docker installed for tests (#438) 2021-09-20 07:07:56 -04:00
Jason Hall
35a4d2c28e
Warn that watch mode is deprecated (#434)
Also update generated markdown docs, and omit unnecessary autogenerated
bits.
2021-09-13 10:30:28 -07:00
Halvard Skogsrud
1fcfd75417
Use working directory and build config dir (#427)
* Use working directory and build config `dir`

Use the working directory from `BuildOptions` to load `.ko.yaml`.

Also, use the `dir` build config field to load package information,
instead of assuming that `go.mod` is in the current working directory.

This removes the `init()` function from `./pkg/commands/config.go`.

And avoids the global viper instance, which caused some Heisenbugs (and
associated hair loss).

Fixes: #422, #424

* Return error instead of log.Fatal

`log.Fatal` is no longer needed in `loadConfig()`, since it's no longer
an `init()` function.

Also removed `log.Fatal` from `createBuildConfigMap()`.
2021-08-27 09:55:39 -07:00
Halvard Skogsrud
29fccb0832
Speed up base image unit test with local registry (#429)
Also follow my own advice to `defer Close()` 😇
2021-08-27 09:52:01 -07:00
Halvard Skogsrud
ae594dcc74
Set build config via BuildOptions (#421)
* Set build config via BuildOptions

Enables programmatically overriding build configs when ko is
embedded in another tool.

Related: #340, #419

* Use local registry for base images in unit tests

Tests create a local registry (using ggcr) with a dummy base image. This
speeds up tests, since they don't need to hit gcr.io to fetch the
default distroless base image.

* Update function comment to refer to random image
2021-08-26 09:33:01 -07:00
Jason Hall
780c281292
Generate Markdown docs (#414)
* Generate Markdown docs

This is largely copied from similar work in go-containerregistry

This required moving the Root command definition out of main() into a
place where it could be referenced from the gendoc tooling.

* fix boilerplate

* moar fix boilerplate

* update cmd/ko/main.go

* set -j to GOMAXPROCS at runtime

* rebase on cli-runtime change

* remove trailing whitespace
2021-08-11 13:54:13 -07:00
Jason Hall
466dbab6c4
Remove dependency on cli-runtime (#413)
* first pass: kubectl flags must be passed after '--'

* add warning when using non-separated flags

* mark flags as deprecated

* drop defaultCacheDir and homedir dependency
2021-08-10 13:57:23 -04:00
Jason Hall
8c7b9cbb8b
Implement ko deps (#403)
* Implement ko deps

* actually add deps.go

* specify auth, useragent, platform

* stop reading tar if the context is cancelled

* chmod to the file's perms

* remove support for --platform, modules don't care about build tags

* fix copyright boilerplate

* drop fs dependency

* udpate module integration test to newer Go versions

* use entrypoint to identify the binary

* fix gosec finding, some style comments

* revert modules integration test change
2021-07-30 13:19:40 -04:00
Jason Hall
26d03e92c2
Annotate images with base image information (#354)
* WIP: annotate base images

* remove TODO

* .

* Annotate with base index digest, if based on an index

* use correct new proposed annotation
2021-07-20 15:06:08 -05:00
Halvard Skogsrud
8295e25f7d
Enable overriding docker client (#378)
When embedding ko, it may be necessary to override the docker client.

This adds a PublishOption to inject a docker client created elsewhere.
Ko will use this client to interact with the docker daemon.

Context: https://github.com/GoogleContainerTools/skaffold/pull/6054#discussion_r662230195
2021-07-15 07:10:52 -07:00
Matthias Diester
ab4d264103
Add support for Go build flags (#340)
There are use cases, where multiple Go build flags need to be set. However, the
environment variable to pass flags to Go build has some limits for `ldFlags`.

Add GoReleaser inspired configuration section to `.ko.yaml` to support setting
specific Go build and ldFlags to be used by the build. Like GoReleaser the
content of the configuration can use Go templates. Currently, only a section
for environment variables is included.

In order to reduce dependency overhead, only the respective config structs from
https://github.com/goreleaser/goreleaser/blob/master/pkg/config/config.go are
used internally to load from `.ko.yaml`.
2021-07-02 08:40:56 -07:00
Simon Kirsten
ee23538378
Add KO_DATA_DATE_EPOCH env var to set the modification time for files in kodata (#372)
* Add KO_DATA_DATE_EPOCH env var

* Add documentation for KO_DATA_DATE_EPOCH env var
2021-06-15 12:50:35 -07:00
Halvard Skogsrud
2ba8bb26d1
Enable setting the working dir for the go tool (#365)
This change adds a `WorkingDirectory` field to `options.BuildOptions`,
but doesn't expose this as a CLI flag. The default zero value means the
current working directory. The value is used as the directory for
executing `go` tool commands.

When embedding ko in other tools, it is sometimes necessary to set the
working directory for executing the `go` tool, instead of assuming the
current process working directory.

An example of where this is required from Skaffold:
https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices

In this example, the working directory doesn't contain either `go.mod`
or any Go files. The `skaffold.yaml` configuration file specifies
a `context` field for each image, which is the directory where the `go`
tool can find package information.
2021-06-10 08:29:30 -07:00
jonjohnsonjr
82e899db0c
Look for ko.local in the daemon (#371)
* Look for ko.local in the daemon

* Update README
2021-06-09 09:20:45 -07:00
jonjohnsonjr
23ecf4753b
Propagate --insecure-registry to base image (#370) 2021-06-01 09:47:30 -07:00
Halvard Skogsrud
d6b3a3cba3
Enable embedding of ko publish (#348)
- Export functions and a variable to enable embedding of ko's
  `publish` functionality to be embedded in other tools.

  See https://github.com/GoogleContainerTools/skaffold/pull/5611

- Remove DockerRepo PublishOption and flag.

  This removes the `DockerRepo` config option and `--docker-repo`
  flag from the PR.

  New PR with the extracted config option:
  https://github.com/google/ko/pull/351

- Fix copyright headers for boilerplate check.

- Use DockerRepo PublishOption instead of env var.

- Override defaultBaseImage using BuildOptions.

  Remove exported package global SetDefaultBaseImage and instead
  allow programmatic override of the default base image using
  the field `BaseImage` in `options.BuildOptions`.

  Also fix copyright header years.

- Add BuildOptions parameter to getBaseImage

  This enables access to BaseImage for programmatically overriding
  the default base image from `.ko.yaml`.

- Add UserAgent to BuildOptions and PublishOptions

  This enables programmatically overriding the `User-Agent` HTTP
  request header for both pulling the base image and pushing the
  built image.

- Rename MakeBuilder to NewBuilder and MakePublisher to NewPublisher.

  For more idiomatic constructor function names.
2021-05-25 11:44:52 -07:00
Chun-Hung Hsiao
bc92184f85
Add a tag-only flag to publisher. (#332)
Co-authored-by: chhsia0 <chhsiao@mesosphere.io>
2021-05-17 08:26:15 -07:00
Halvard Skogsrud
a68d0ab75f
Enable override of daemon publisher local domain (#362)
* Enable override of daemon publisher local domain

Add a `LocalDomain` field to `PublishOptions`, but no flag (yet?).

This allows use of a domain (base repo) other than `ko.local` for images
that are side-loaded to the local Docker daemon.

An alternative implementation would be to add a boolean field that
indicates that `ko publish` should use the value of the `KO_DOCKER_REPO`
environment variable (or the `DockerRepo` field in `PublishOptions`) as
the base name for images side-loaded to the local Docker daemon. I'd be
happy to get feedback on which option would work best.

* Restore NewDaemon tags positional arg
2021-05-17 08:25:47 -07:00
Halvard Skogsrud
516cdeec7d
Add flag and PublishOption for destination repo (#351)
* Add flag and PublishOption for destination repo

This enables programmatically setting the destination image repository
when embedding ko's `publish` functionality in other tools.

See https://github.com/google/ko/pull/348

* Set DockerRepo PublishOption from KO_DOCKER_REPO

This enables programmatically setting the destination image repository
and avoids exposing a flag.

* Update comment on DockerRepo option

* Fix readme and copyright headers
2021-04-30 13:53:00 -04:00
Jason Hall
29cd8e09e9
Use cobra's RunE wherever possible (#343) 2021-04-22 12:37:42 -04:00
Jason Hall
5eef982548
Merge pull request #313 from zhouhaibing089/update-bare-comment
options: update --bare help message
2021-04-07 20:50:16 -04:00
Jason Hall
f7df810619
Add --image-label to add labels to built images (#324) 2021-03-03 10:03:31 -08:00
zhouhaibing089
b27ed4eb69 options: update --bare help message
The current `--bare` help message is a little bit confusing: It says
that it will not work with `--tags` properly, but in fact, I would
assume it means that it may not work properly instead.

With `--bare`, the name will be `${KO_DOCKER_REPO}:<tag>`.
2021-02-18 18:17:15 -08:00
jonjohnsonjr
34568cac73
Use remote.WithUserAgent where possible (#294)
This was using remote.WithTransport to set it manually, and this is much
simpler (also annotates with the go-containerregistry version). This is
really nice because it will give us at least some version information
where we had none before (for non-releases).

Before:

ko
ko/(devel)
ko/v0.7.0

After:

ko go-containerregistry/v0.4.0
ko/(devel) go-containerregistry/v0.4.0
ko/v0.7.0 go-containerregistry/v0.4.0
2021-01-18 11:11:16 -08:00
Jon Johnson
6586a72f8a Always use "strict" mode
We dropped this flag, so we're always in non-strict mode by default,
so if there is a ko:// reference that fails to build, we don't error
out. This drops some guards so that we are always in strict mode and
only build ko:// things.
2020-12-22 14:00:31 -08:00
jonjohnsonjr
7e3245343a
Allow comma-separated list of platforms (#259)
* Allow comma-separated list of platforms

* Parse platform spec once

* Update --platform docs in README

* Update pkg/build/gobuild_test.go

Co-authored-by: Matt Moore <mattmoor@vmware.com>

* Return err for bad defaulting for --platform

Also respect GOARM as variant if the goarch is arm.

* Refactor platform matching

* Update README.md to mention GOARM

* Fix travis test

Co-authored-by: Matt Moore <mattmoor@vmware.com>
2020-12-21 16:53:00 -08:00
jonjohnsonjr
522c37c4e0
Add ctx everywhere (#268)
* Add ctx to publish.Interface

I noticed that hitting ctrl-C didn't work when pushing images, this
should fix that.

* Use context everywhere that makes sense
2020-12-21 11:47:05 -08:00
jonjohnsonjr
b84301964a
Make --watch work with ko:// (#250)
The dep-notify package doesn't know anything about ko, so we need to
trim the strict prefix before sending import paths over to it.
2020-11-20 13:12:19 -08:00
Jon Johnson
c183e84439 Stop using filepath.Join in publisher 2020-11-17 09:33:56 -08:00
Matt Moore
79beb3b015
Refactor the publish.Namer, add --bare option for image naming (#234)
* Refactor the publish.Namer to produce the full repo name.

* Add --naked to have image publishing use ${KO_DOCKER_REPO}:tag

* Change flag name, add disclaimer
2020-11-03 13:47:36 -08:00
Jason Hall
d767708246
IsSupportedReference returns descriptive error (#233)
This can be useful to determine what they need to do to make a ko
publish work.
2020-10-31 09:55:28 -07:00
Markus Thömmes
695b39f9f4 Fix things pointed out by golangci-lint 2020-10-13 15:27:59 +02:00
Jason Hall
e780390edb
Avoid panic caused by MultiPublisher (#216)
MultiPublisher now returns an error when it's configured with no
publishers, and resolver.go now appends a nop publisher when it's
configured not to publish, that simulates a publish without actually
pushing any images.

.
2020-10-06 06:45:25 -07:00
Jason Hall
d7b989a9df
Remove docs for Strict Mode and --strict flag (#210) 2020-09-30 11:00:36 -07:00
jonjohnsonjr
4a4d1b02bd
Revive progress and warning logs (#203)
These got dropped when we pulled in:
https://github.com/google/go-containerregistry/pull/481

Which doesn't log by default, and requires opting in.
2020-09-25 11:50:20 -07:00
Matt Moore
d48767339f
Fix base image resolution (#201) 2020-09-25 10:20:33 -07:00
Matt Moore
33e66aca49
Remove deprecated things. (#162)
Fixes: https://github.com/google/ko/issues/158
Fixes: https://github.com/google/ko/issues/160
2020-09-24 16:14:58 -07:00
jonjohnsonjr
8b52ec2374
Multi-platform ko (#38)
🦜
2020-09-24 15:58:08 -07:00
Markus Thömmes
1aa3b3793e
Allow images to be loaded into kind using 'kind.local'. (#180)
* Allow images to be loaded into kind using 'kind.local'.

* Add documentation for kind.
2020-09-04 08:32:26 -07:00
Markus Thömmes
ecce857be6
Some small nits around the codebase to make linters happy. (#181) 2020-08-10 08:21:31 -07:00
Matt Moore
d45c527750
This adds the deprecation notices for ko:// and nonroot (#161)
* Add a deprecation notice when `defaultBaseImage` is not specified.

Related: https://github.com/google/ko/issues/160

* Add a deprecation notice when `ko://` is not specified.

Related: https://github.com/google/ko/issues/158

* Add a sample import path.
2020-05-03 18:42:51 -07:00
Matt Moore
f45bc13ded
Viper keys are case insensitive. (#150)
* Viper keys are case insensitive.

This fixes an issue where import paths with uppercase (github.com/GoogleCloudPlatform 👀) were being canonicalized by Viper to all lowercase and the baseImageOverrides in `.ko.yaml` were failing to properly identify the base image.

I hit this in: https://github.com/tektoncd/pipeline/pull/2435 trying to opt some of the GCP images out of `:nonroot`.

This also adds some logging to a place where I see a lot of folks have issues with `ko` where we swallow an error.  I hit it experimenting with variants on the `ko publish` import path, and added the logging to debug.

* Drop the new log statement
2020-04-20 09:13:33 -07:00
jonjohnsonjr
3c6a907da9
Add additional output formats (tarball and layout) (#134)
* Create a MultiPublisher

MultiPublisher mimics io.MultiWriter in that it will publish an image to
multiple publish.Interface implementations.

* Add publish.{Tarball,Layout}Publisher

This adds support for publishing in the tarball format and to an OCI
image layout.

The tarball format isn't great, yet. It only supports writing once
instead of appending.

* Consolidate options

These were spread all over the place for no reasons. Now all the
publisher related options are grouped together.

* Add options for tarball/layout

Adds --oci-layout-path, --tarball, and --push flags.

--push=false will disable the default behavior of publishing to a
registry.

* go mod vendor

* Add Close method to publish.Interface

This allows us to defer writing to the tarball until we've collected all
the images that have been published.

* Fix tests
2020-02-19 09:30:01 -08:00
jonjohnsonjr
cfd680de28
Deterministically fail ko {apply, create} (#133)
When resolving files, we would just log.Fatal if we encountered an
error. This seems to be racy and causes ko to exit with a 0 error code
when it shouldn't. To fix this, we synchronize the builder goroutines
with the kubectl go routine and exit with an error if either of them
failed.

This fix also happened to fix a goroutine leak. If the kubectl goroutine
failed, we never properly cancelled the builds, which would happily
conitnue compiling packages and consuming resources.
2020-02-11 10:44:25 -08:00
jonjohnsonjr
c3a657a04b
Set AutomaticEnv for viper (#131)
This allows viper configuration to be set using environment variables
instead of just with a config file.
2020-02-06 13:51:22 -08:00
Daniel Helfand
2e28671384 add kubectl check for ko delete, apply, and create (#120) 2020-01-16 13:27:43 -08:00
jonjohnsonjr
b7e1a7fdbc
Update ggcr dependency (#119)
* Update ggcr dependency

I had to move genericclioptions to k8s.io/cli-runtime

* bump client-go

* usePersistentConfig=false
2020-01-15 13:16:11 -08:00