1
0
mirror of https://github.com/ko-build/ko.git synced 2025-02-01 19:14:40 +02:00

160 Commits

Author SHA1 Message Date
Jon Johnson
73a4629033 Always clean Dir for packages.Load 2021-12-20 08:39:16 +11:00
Jason Hall
8135bf22e9
Set config creation time without mutating (#524)
* Set config creation time without mutating

* only set creation time if set

* drop creationTime from buildLayer entirely
2021-12-16 14:07:15 -05:00
Jason Hall
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
Steve Coffman
6cc2d7fc64
Fix #530 Hanging behavior with ASDF installed Go on Darwin (#548)
Signed-off-by: Steve Coffman <steve@khanacademy.org>
2021-12-15 11:38:01 -08:00
jonjohnsonjr
5a13603eef
Fix tarball publisher ctx handling (#545)
Previously, we'd use the ctx from the Build invocation, but because
remote stashes the remote.WithContext option, when we later go to fetch
the actual base image to write it out to a tarball, it will fail because
the Build ctx was cancelled.

For whatever reason, NewGo takes a ctx, so this change propagates the
badness from remote so we can use the NewGo ctx when we fetch base
images.
2021-12-14 15:30:01 -08:00
Antoine Cotten
66a77a91e7
Fix handling of 'has' selectors (#473)
* Add tests to surface issue 467

* Fall back to empty map if object has no labels
2021-12-14 13:20:30 -08:00
Chris Suszynski
84e8ab637e
Allow to customize publish.Namer (#477)
* Allow to customize publish.Namer

Fixes #476

* Removing a CLI flag for path separator

* Removing ImageNameSeparator option after review
2021-12-14 13:19:14 -08:00
Matt Moore
a56047a2a1
Filter out nil addendum before constructing index. (#546)
In the PR where we added concurrency we used a fixed length array to store
addendum to preserve the ordering from the base image when constructing the
final index.  However, with `--platform=...` this list may be filtered, which
gives us `nil` entries in our addendum.

This filters `nil` entries prior to constructing the index.

Fixes: https://github.com/google/ko/issues/544
2021-12-14 11:00:18 -08:00
jonjohnsonjr
2502eb9d47
Build each platform concurrently (#527)
* Build each platform concurrently

At least on my machine, this is slightly faster on a cold build and
saves significant time on a warm build.

* Plumb --jobs down to multi-arch

* Add deprecation warning for build.Limiter
2021-12-09 11:02:14 -08:00
jonjohnsonjr
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
jonjohnsonjr
54cddccd1c
Introduce KOCACHE (#269)
* Introduce KOCACHE

Cache binaries under $KOCACHE/<import path>/<platform>

Cache metdata mapping buildid to diffid and diffid to descriptor.

* Point TODO at issue

* Split layerCache into separate file

This makes things a little cleaner by having a single place that calls
buildLayer and passing a thunk down into the cache logic to call that on
a cache miss.

Also, remove the debug logging to make the code easier to follow (if you
need to recompile anyway, it's easy enough to add log lines).

* Move cached output to $KOCACHE/bin
2021-12-08 08:47:26 -05:00
darklore
6ff346909c
Use default completion command provided by cobra. (#522)
* Use default `completion` command provided by cobra.

`cobra` provides default `completion` subcommand.
It supports bash, zsh, fish, and powershell by default.

* update docs
2021-12-05 09:00:38 -05:00
Markus Thömmes
d91d7a45e8
Update golangci-lint and fix issues (#519) 2021-11-25 10:27:40 -05:00
Matt Moore
5787600e92
Normalize the package hash to hex. (#512)
We were emitting package checksum hashes as `h1:{base64}`.  `h1:` is a prefix that indicates "Hash 1", which is a SHA-256 based hash of the files, which is then base64 encoded as the suffix.

This change detects/strips the `h1:` prefix and re-encodes the base64 data as hex.
2021-11-23 09:34:43 -05:00
Matt Moore
3edb68b273
Connect SBOMs with SPDX support. (#511)
* Connect SBOMs with SPDX support.

This combines Jason's SPDX stuff and my SBOM stuff to support
SPDX-based SBOMs by default instead of our `go version -m`
invention.

* Make ko deps use SPDX by default
2021-11-22 17:19:43 -05:00
Jason Hall
af2ff52a11
Generate ko deps in SPDX format (#507)
* WIP: generate ko deps in SPDX format

- copy out a bunch of BuildInfo stuff that will land in 1.18

* review comments

* have deps take --sbom flag more like Matt's new publish-time flag
2021-11-22 15:32:29 -05:00
Matt Moore
6d0691330a
Add support for writing SBOMs when the build.Result is oci.Signed*. (#506)
This adds functionality that enables the default publisher to
publish SBOMs (and later signatures and attestations) when the
`build.Result` is an `oci.SignedEntity`.

This also changes the `gobuild` logic to start producing
`oci.Signed*` as its `build.Result`s, so when executed we get an
SBOM for each architecture image.

For example, see the "Published SBOM" lines below:

```shell
2021/11/19 19:24:50 Using base gcr.io/distroless/static:nonroot for github.com/google/ko
2021/11/19 19:24:51 Building github.com/google/ko for linux/amd64
2021/11/19 19:24:52 Building github.com/google/ko for linux/arm64
2021/11/19 19:24:57 Publishing ghcr.io/mattmoor/ko:latest
2021/11/19 19:24:58 existing blob: sha256:c78c74e7bb4a511f7d31061fbf140d55d5549a62d33cdbdf0c57ffe43603bbeb
2021/11/19 19:24:58 existing blob: sha256:4aa59d0bf53d4190174fbbfa3e9b15fdab72e5a95077025abfa8435ccafa2920
2021/11/19 19:24:58 ghcr.io/mattmoor/ko:sha256-d2bc030f5ed083d5e6a30a7969c9a8e599511b8d7a6e20695bf5ea029b6e2c3f.sbom: digest: sha256:c67ec671aaa82902e619883a7ac7486e6f9af36653449e2eb030ba273fe5a022 size: 348
2021/11/19 19:24:58 Published SBOM ghcr.io/mattmoor/ko:sha256-d2bc030f5ed083d5e6a30a7969c9a8e599511b8d7a6e20695bf5ea029b6e2c3f.sbom
2021/11/19 19:24:58 existing blob: sha256:c78c74e7bb4a511f7d31061fbf140d55d5549a62d33cdbdf0c57ffe43603bbeb
2021/11/19 19:24:58 existing blob: sha256:4aa59d0bf53d4190174fbbfa3e9b15fdab72e5a95077025abfa8435ccafa2920
2021/11/19 19:24:59 ghcr.io/mattmoor/ko:sha256-b74c230f20efd94981e5fd823bacc23cbd71055a1b3b6a0893152b398c67743b.sbom: digest: sha256:c67ec671aaa82902e619883a7ac7486e6f9af36653449e2eb030ba273fe5a022 size: 348
2021/11/19 19:24:59 Published SBOM ghcr.io/mattmoor/ko:sha256-b74c230f20efd94981e5fd823bacc23cbd71055a1b3b6a0893152b398c67743b.sbom
2021/11/19 19:24:59 existing blob: sha256:3f7e3c6765a6abc682cd40ea256fbea5c1d4debbc07659efbc0dedc13eee0da6
2021/11/19 19:24:59 existing blob: sha256:250c06f7c38e52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8542
2021/11/19 19:24:59 existing blob: sha256:e8614d09b7bebabd9d8a450f44e88a8807c98a438a2ddd63146865286b132d1b
2021/11/19 19:24:59 existing blob: sha256:7067b1bc6f9ce59f3a4ed2216946ebbb27a4f7a102f55d96c6af1dc90e77b510
2021/11/19 19:25:00 ghcr.io/mattmoor/ko@sha256:d2bc030f5ed083d5e6a30a7969c9a8e599511b8d7a6e20695bf5ea029b6e2c3f: digest: sha256:d2bc030f5ed083d5e6a30a7969c9a8e599511b8d7a6e20695bf5ea029b6e2c3f size: 751
2021/11/19 19:25:01 existing blob: sha256:250c06f7c38e52dc77e5c7586c3e40280dc7ff9bb9007c396e06d96736cf8542
2021/11/19 19:25:02 pushed blob: sha256:121c637d5c84562b51404a6f71c1f995ad059740293a3911a0dc33eb223e41a4
2021/11/19 19:25:02 pushed blob: sha256:859e03b7461b2a512159493ef1504d2859ed37c05ed1ef781ff98394ea4799b5
2021/11/19 19:25:02 pushed blob: sha256:d1b55c3db0f16b5056776c6d2c279efd16d28dbf1aae3eef1f3f9b7551d1f490
2021/11/19 19:25:03 ghcr.io/mattmoor/ko@sha256:b74c230f20efd94981e5fd823bacc23cbd71055a1b3b6a0893152b398c67743b: digest: sha256:b74c230f20efd94981e5fd823bacc23cbd71055a1b3b6a0893152b398c67743b size: 751
2021/11/19 19:25:03 ghcr.io/mattmoor/ko:latest: digest: sha256:e4466a7dd9be66c7c1b43a8ecc19247041ece232407a14e3d6ea3c51d2561a71 size: 529
2021/11/19 19:25:03 Published ghcr.io/mattmoor/ko@sha256:e4466a7dd9be66c7c1b43a8ecc19247041ece232407a14e3d6ea3c51d2561a71
ghcr.io/mattmoor/ko@sha256:e4466a7dd9be66c7c1b43a8ecc19247041ece232407a14e3d6ea3c51d2561a71
```

The "SBOM" being attached in this change is the raw output of `go version -m`,
which we will convert to one of the standard formats in a subsequent change.
2021-11-22 10:57:13 -08:00
Halvard Skogsrud
2fbc9089eb Add Trimpath build option
Enables programmatic control of whether `ko` adds the `-trimpath`
flag to `go build`.

The `-trimpath` flag removes file system paths from the resulting
binary. `ko` adds `-trimpath` by default as it aids in achieving
reproducible builds.

However, removing file system paths makes interactive debugging more
challenging, in particular in mapping source file locations in the
IDE to debug information in the binary.

If you set `Trimpath` to `false` to enable interactive debugging, you
probably also want to set `DisableOptimizations` to `true` to disable
compiler optimizations and inlining.

Reference for `-trimpath`:
https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies

Resolves: #500
Related: #71, #78, https://github.com/GoogleContainerTools/skaffold/issues/6843
2021-11-18 09:04:15 +11:00
sbwsg
de2ce53efb
Fix issue where kubectl apply is run in place of kubectl create (#494) 2021-11-09 13:15:24 -05:00
Jason Hall
0015a81537
Enforce more lint checks, fix findings (#492) 2021-11-05 10:26:09 -07:00
Jason Hall
1e46fdebd5
Use signal.NotifyContext and cmd.Context (#482) 2021-11-02 17:15:25 -04:00
Ben Moss
5d7673e944
Use tools/go/packages in place of go/build (#486)
* Use tools/go/packages in place of go/build

* Use build config dir

Signed-off-by: Ben Moss <benm@vmware.com>

* Use filepath.Dir in place of ".." for explicitness
2021-10-27 11:10:27 -04:00
Matthias Diester
b9f92681ba
Improve build config issue error scenario #483 (#487)
* Add build config usage log statement

There is currently no indication whether `ko` picks one of the configured
build configurations from the `.ko.yaml` configuration file for a build.

Add log statement to print the build config being picked for the build.

Introduce default entry for build config `ID` in case it is not specified.

* Add path check for build configuration settings

Add `os.Stat` to verify that the path that is configured in the build
configuration entry is valid. As a side effect, this will print out an error
message in case someone sets an import path like `github.com/google/ko` in
the `main` field of the build config.

* Fix trimpath command line flag in README

Fixed wrong command line flag `--trimpath` to `-trimpath`.
2021-10-27 11:09:41 -04:00
Halvard Skogsrud
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
Jason Hall
42723d75e7
Revert "Always produce OCI images and indexes (#449)" (#462)
This reverts commit 465eca2b93f860b212a2911f93dc9547876f898a.

This breaks pushing to quay.io.
2021-10-06 07:15:52 -04:00
Jason Hall
465eca2b93
Always produce OCI images and indexes (#449)
* Always produce OCI images and indexes

* test each constituent manifest's mediatype
2021-10-05 11:58:31 -04:00
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
688ca47675
Isolate unit tests from os.Environ (#455)
Platform resolution unit tests were affected by GOARCH/GOOS. Move the
os.Environ() call out of the function under test to avoid this.
2021-09-29 09:23:32 -07:00
Jason Hall
2adcadd918
Fix regression in adding /ko-app to PATH (#448) 2021-09-27 11:00:25 -04:00
Jason Hall
0451db7d0c
drop special behavior to support Go pre-1.13 (#446) 2021-09-22 12:59:09 -04:00
jonjohnsonjr
45467f076b
Do not require docker installed for tests (#438) 2021-09-20 07:07:56 -04:00
jonjohnsonjr
61d5250c55
Drop scary warning (#439) 2021-09-16 10:48:12 -07: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
Halvard Skogsrud
9a256a4b19
Enable setting environment variables in .ko.yaml (#419)
* Enable setting environment variables in .ko.yaml

Matches the GoReleaser format.

Related: #340

* Use different env example
2021-08-23 08:05: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
86a7b6f4b8
Don't set image.base.name if base is specified by digest (#408)
* Don't set image.base.name if base is specified by digest

* don't set empty annotation

* annotate Results, not Images and Indexes separately

* moar cleanup

* skip annotations check for images in indexes, these won't be annotated anymore
2021-08-11 16:52:01 -04: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
4ff8308086
Use annotation strings from image-spec/specs-go (#407) 2021-08-03 20:00:24 -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
c9efd26241
Annotate OCI image indexes with base image information (#385) 2021-07-30 09:29:58 -07:00
Jason Hall
f16d0d0412
Don't add .exe suffix to windows executables (#400) 2021-07-28 16:28:22 -04:00
Evan Anderson
f04730dc84
Make --insecure-registry work with TLS registries whose certs we can't verify. (#398)
* Make --insecure-registry work with TLS registries whose certs we can't verify.

* Don't error if we can't disable TLS checking when insecure.
2021-07-28 13:23:45 -07:00
Jason Hall
690533235a
Build working Windows container images (#374)
* Build working Windows container images

Add e2e tests that run on Windows and cover kodata behavior

* now successfully skipping symlinks on windows :-/

* fix e2e test on windows, that relied on a symlink in kodata after all

* document windows symlink issue

* review feedback

* re-add kodata symlink tests for linux
2021-07-27 16:19:21 -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
Jason Hall
56282bf645
Fix layout tests on macos (#384) 2021-07-15 10:16:24 -04:00