1
0
mirror of https://github.com/ko-build/ko.git synced 2025-07-06 23:36:54 +02:00
Commit Graph

35 Commits

Author SHA1 Message Date
691da5afb6 Use sync.Map to cache base image lookups (#712) 2022-05-25 12:42:45 -04:00
84356b8b0b Bump ecr-login dep and update WithLogger callsite (#658) 2022-04-13 13:13:18 -04:00
3fc720f912 Update ecr-login dependency to allow us to avoid logspam (#586) 2022-02-16 15:33:47 -05:00
f8d0aca1ab Log base image@digest when building (#592)
* Log base image@digest when building

* Only log full digest if the original base wasn't already specified by digest

* Remove redundant image ref
2022-02-11 10:39:19 -05:00
89ede9110a Include cred helpers in keychain (#581)
This adds implicit support for Google, Amazon, Azure and GitHub
container registries if the environment provides credentials.

Binary size increases from 22 MB -> 26 MB
2022-02-08 15:20:31 -05:00
5f733f9ac6 Support partial platform matching for osversion only (#572)
* Support partial platform matching for osversion only

* Add doc comment

* lint fixes

* pick up Platform.String and v1.ParsePlatform

* go mod tidy && go mod vendor
2022-01-27 17:06:35 -05:00
c67fb03b79 Pre-parse platform string with StringSliceVar (#551)
* Pre-parse platform string with StringSliceVar

This allows users to declare --platform multiple times and have the
values appended, i.e.:
  ko build --platform=linux/amd64 --platform=linux/arm64
is equivalent to
  ko build --platform=linux/amd64,linux/arm64

As a side effect, platformMatcher.spec and gobuildOpener.platforms are
now of type []string (instead of string) to maintain structure of
information from flag parsing.

* Adjust comments and styling for clarity.

* The flag --platform is now of type strings.

Internally cobra/pflag defines StringSliceVar as "strings" whereas
StringVar is defined as "string".

This change is updated by running hack/update-codegen.sh script.

* Add backwards compatibility for WithPlatforms function signature

Update comments to reflect implementation as well.

* Fix syntax failure on unit test
2022-01-04 14:19:52 -05:00
33fa766168 Support osversion when selecting base images (#536)
* Support osversion when selecting base images

Use this in e2e tests.

Also clean up usage of bo.Platform vs a new platform var.

* use correct osversion
2021-12-15 16:08:27 -05:00
ad0607f0a1 Cache base image metadata in-memory (#525)
This saves a roundtrip to the registry if we ever use the same base
image for multiple builds in a single invocation.

This also sets us up for using an on-disk cache for image metadata to
speed things up even further.
2021-12-08 09:28:15 -05:00
0015a81537 Enforce more lint checks, fix findings (#492) 2021-11-05 10:26:09 -07:00
1e46fdebd5 Use signal.NotifyContext and cmd.Context (#482) 2021-11-02 17:15:25 -04:00
103ff5b2a8 Use build config Dir for all go tool commands
Ensure that the directory specified in build configs in `.ko.yaml` is
used to:

1. Load module information
2. Resolve local paths to Go import paths
3. Working directory for compilation

The change achieves this by introducing `gobuilds`, which contains a
map of import path to `build.Interface` instances. Each entry maps to a
`builds` entry from `.ko.yaml`. `gobuilds` dispatches to the builder
instances based on the requested import path, and falls back to a
default builder if there's no match.

Thanks to @jonjohnsonjr for the suggestions in
https://github.com/google/ko/issues/422#issuecomment-909408527

Also removes mutable globals in the `commands` package.

Fixes: #422
2021-10-27 08:22:23 +11:00
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
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
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
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
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
23ecf4753b Propagate --insecure-registry to base image (#370) 2021-06-01 09:47:30 -07:00
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
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
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
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
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
d48767339f Fix base image resolution (#201) 2020-09-25 10:20:33 -07:00
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
8b52ec2374 Multi-platform ko (#38)
🦜
2020-09-24 15:58:08 -07:00
ecce857be6 Some small nits around the codebase to make linters happy. (#181) 2020-08-10 08:21:31 -07:00
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
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
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
d24b60a88f Set UA to something ko-specific (#116) 2019-12-13 15:08:52 -08:00
1c54dd6b3e Add context to go build (#105) 2019-11-09 09:23:09 -08:00
116114f1f9 Bump ggcr depenency (#41)
* Update ggcr dependency

* Update kode

Fixed remote.Write interface change.

Drop name.WeakValidation (now default).
2019-06-21 13:15:10 -07:00
cef9764e3d Return better error messages (#33)
This hoists the publisher creation out of the loop for `ko publish` to
avoid needlessly resolving credentials multiple times.

This pulls the publisher creation outside of resolveFilesToWriter so we
can fail earlier if e.g. KO_DOCKER_REPO is unset, otherwise we start up
the kubectl goroutine and it would asynchronously fail with:

  error: no objects passed to apply
2019-04-30 13:08:54 -05:00
6f9fb7f753 Move ko commands to pkg/commands (#29)
* Move commands to pkg/commands and split into files.
2019-04-26 15:56:15 -07:00