1
0
mirror of https://github.com/ko-build/ko.git synced 2025-11-29 22:47:51 +02:00
Commit Graph

64 Commits

Author SHA1 Message Date
Nathan Mittler
38a1feb001 Remove vendor directory
Also adding dependency on testify to replace some hand-rolled `requireXXX` methods.
2024-05-15 12:49:39 -04:00
Nathan Mittler
4dbf90fe81 feat: Add template params for git
This includes a number of template parameters supported by [goreleaser](https://goreleaser.com/customization/templates/). Specifically, the build date information and the majority of the Git params.

Majority of the code is copied from goreleaser. I've added the MIT license from goreleaser at the top of the files.

Fixes #493

Signed-off-by: Nathan Mittler <nmittler@aviatrix.com>
2024-05-15 11:27:55 -04:00
Nathan Mittler
067f9f7899 feat: Add global env
Supports configuring global `env` variables that will be applied to all builds.

Modifies the `builder` function to accept a `buildContext` structure. This will simplify similar modifications in the future.

Fixes #1305

Signed-off-by: Nathan Mittler <nmittler@aviatrix.com>
2024-05-14 13:58:53 -07:00
guangwu
d4a1cc961c chore: remove refs to deprecated io/ioutil (#1092)
* chore: remove refs to deprecated io/ioutil

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>

* fix: gofmt check

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>

---------

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-08-23 13:24:04 -04:00
Carlos Tadeu Panato Junior
2b8ee98d2d update boilerplate file to be KO Build Authors (#1056) 2023-06-09 10:48:00 -04:00
Jason Hall
11670b7498 fix: handle docker's unknown/unknown platform in index manifests (#975) 2023-03-08 17:09:49 -05:00
Jason Hall
76f46cc1d1 upgrade to cosign v2.0.0-rc.0 (#933) 2023-01-16 11:42:41 -05:00
Batuhan Apaydın
5e0452ad67 feat: write sbom result to disk (#822)
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>

Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
2022-09-20 16:44:54 -04:00
Ben Moss
cbe2784e52 Error if image platform does not match desired (#785) 2022-08-19 17:19:55 -04:00
Jason Hall
2f230b88c4 Set layer media types consistently (#776)
* Set layer media types consistently

* Also test that base image mediaType is not changed
2022-07-21 15:04:34 -04:00
Matt Moore
2299765c54 Start emitting multi-arch SBOMs for SPDX with ko (#743)
This plumbs through support for building multi-arch SPDX SBOMs largely based on Puerco's outline, but with a few
adaptations.  I added a few minor refactorings to try to enable consistency across the Image/Index SBOMs.

Related: https://github.com/google/ko/issues/655
2022-07-05 12:47:15 -07:00
Jason Hall
aafd3e863b Revert "Produce OCI images by default (#623)" (#653)
This reverts commit 7e9709a63a.
2022-03-18 11:30:56 -04:00
Jason Hall
204fbc9724 Correctly pass through base image annotations (#636)
There were some bugs here before:

- for indexes, we'd annotate the base, but then append to empty.Index
  which didn't carry those forward.
- when producing single-platform images based on multi-platform indexes
  (the default and most common scenario), we wouldn't carry forward the
  original base index's annotations to the single matching platform base
  image.
2022-03-07 14:12:19 -05:00
Jason Hall
7e9709a63a Produce OCI images by default (#623)
* Produce OCI images by default

This changes build logic to prefer to produce OCI images and indexes,
even if original base images are Docker manifests or manifest lists.

OCI indexes support annotations, while Docker manifest lists do not, and
we'd like to inject base image information in annotations wherever possible.

Since Quay.io recently added support for OCI manifests, this is no
longer a serious breaking change -- and anyway, producing SBOMs by default
already breaks Quay.io without --sbom=none.

This behavior can be disabled with --preserve-docker-media-type=true,
which will result in Docker-type manifests being produced if and only if
the base image was a Docker-typed manifest.

This partially reverts commit 42723d75e7.

* drop e2e test

* update generated docs

* --preserve-media-type

* docs
2022-03-04 16:21:06 -05:00
jonjohnsonjr
ea93812481 Test the right directory for kocache (#616) 2022-02-24 11:54:25 -05:00
Batuhan Apaydın
d48a62134c fix: create dir for KOCACHE (#607)
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
2022-02-23 13:34:34 -08:00
Jason Hall
e961890072 Set GOAMD64 if variant is set (#578)
This change also changes behavior of GOARM, since docs suggest that it's
only used when the GOARCH=arm, and not arm64.
2022-02-01 16:46:32 -05:00
Jason Hall
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
Wilson E. Husin
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
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
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
Jason Hall
0015a81537 Enforce more lint checks, fix findings (#492) 2021-11-05 10:26:09 -07: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
Jason Hall
42723d75e7 Revert "Always produce OCI images and indexes (#449)" (#462)
This reverts commit 465eca2b93.

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
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
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
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
4ff8308086 Use annotation strings from image-spec/specs-go (#407) 2021-08-03 20:00:24 -04: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
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
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
Jason Hall
f7df810619 Add --image-label to add labels to built images (#324) 2021-03-03 10:03:31 -08:00
Scott Nichols
c2b862d468 Move ko binary to root of project. (#257)
* Move ko binary to root of project.

* go.mod says required golang version is 1.14

* go install uses the folder name

* lint and copyright bump

* moving the test file changed the test hash.

* more refs of cmd/test

* add deprecation message
2020-12-22 09:31:02 -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
1f17ce95d4 Set GOARM based on platform.variant (#239)
This relies on some hard-coded knowledge of the go compiler, which is
unfortunate, so we will have to update this if things change.
2020-11-04 12:44:08 -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
Matt Moore
bd3f1cb17b [Automated] Update actions (#194)
* Update common github actions

Signed-off-by: Matt Moore (via Sockpuppet) <mattmoor@vmware.com>

* Run gofmt
2020-09-24 19:00:36 -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
ecce857be6 Some small nits around the codebase to make linters happy. (#181) 2020-08-10 08:21:31 -07:00
Dave Protasowski
6cbfe964d7 [modules] Dependent command packages can now be built with ko (#154)
Thus if you have a (in)direct command package as a dependency
say `myhost.com/go/package/cmd/run` you can now publish this
with the following ko command

  ko publish myhost.com/go/package/cmd/run
2020-05-01 07:18:26 -07:00
Halvard Skogsrud
ca1b2a1ded Fix: Add directory containing binary to PATH (#127)
Fixes the PATH environment variable so it contains the directory
containing the binary (i.e., /ko-app) instead of the binary itself
(e.g., /ko-app/ko).

See #114.
2020-01-28 09:15:14 -08:00
jonjohnsonjr
4ff72e36de Add entrypoint to PATH (#114)
This makes it easier to invoke the binary when using a debug container.
E.g. you could invoke `ko` instead of `/ko-app/ko`.
2019-12-11 11:08:26 -08:00
Evan Anderson
6aff039ca9 Fix path mangling on Windows. (#112)
Since we are always building linux containers, use `path.Join` rather than
`filepath.Join` when adding files to the tar.

Signed-off-by: Evan Anderson <evan.k.anderson@gmail.com>
2019-12-02 11:05:48 -08:00