Commit Graph

171 Commits

Author SHA1 Message Date
Prima Adi Pradana 423d20cee2
warmer validate and copy registry mirror to registry map (#3140) 2024-05-13 22:36:38 -07:00
Matthias Schneider a9062b97f7
feat: Added --chmod for ADD and COPY command. Fixes #2850 (#3119) 2024-04-22 09:28:37 -07:00
Matheus Pimenta 8bbd69d8a1
Add --push-ignore-immutable-tag-errors boolean CLI option (#2774) 2024-02-29 10:05:58 -08:00
schwannden 20a6ab560e
feat: add skip tls flag for private git context (#2854)
If git clone context is a private self-signed repository, we allow user
to add --git insecure-skip-tls=true flag in the option. The value is
default to false, this behavior is in accordance with the go-git
package.
2024-02-28 23:18:41 -08:00
Sacha Smart 818b1392e0
feat: add support for no push environment variable (#2983)
* feat: add support for no push environment variable

* Update to Readme

* feat: add support for no push environment variable


Update to Readme
2024-02-22 20:20:41 -05:00
Damien Degois 1bf529e6d9
Add flag to remap registries for any registry mirror (#2935)
* Add flag to remap registries for any registry mirror

The purpose of this PR is to add an option to remap registries, a kind of generalized `--registry-mirror`.
This is helpful for air-gapped environments and/or when local registry mirrors are available (not limited to docker.io).
This allows user to reference any images without having to change their location.
It also permit to separate infra related configuration (the mirrors) from CI/CD pipeline definition by using an environment variable for example (the reason behind the early return if flag provided but empty).
Therefore you can have a pipeline calling kaniko with `--registry-map=$REGISTRY_MAP` and have the `REGISTRY_MAP` populated via the runner's env by another team, and the absence of env wouldn't trigger a failure, it makes the pipeline env independent.

I've also considered the option of environment variables directly but it doesn't seems to be in kaniko's philosophy.

This makes quite some duplicated code :/ One option to keep the mirror flag and behavior would be to use only one codebase and convert `--registry-mirror=VALUE` to `--registry-map=index.docker.io=VALUE` internally. Suggestions welcome!

* Configure logging config sooner to be able to use it in flag parsing

* Replace registry mirrors by maps logic and use env var

* Add env vars to README.md

* Fix test
2024-02-14 15:23:41 -08:00
Anna Levenberg 6b7604ee58
feat: add a retry with result function enabled by --image-download-retry (#2853)
* feat: add a retry with result function enabled by --image-download-retry (#2853)

* impl: add a retry with result function

* fix ci errs

* test: add unit tests

* gofmt

* make debian a const

* update param description
2023-11-20 10:10:17 -08:00
Anoop S 66f24c90f3
Print error to stderr instead of stdout before exiting (#2823)
fix: fmt.Println prints error to stdout before exiting which is against Unix
principles.
2023-11-16 10:33:51 -08:00
Julian cefe99b92a
Added skip-push-permission flag (#2657)
Added skip-push-permission flag to conditionally disable push permission check on build start to accommodate for slow network policies
2023-08-15 11:23:16 -07:00
Fernando Giannetti c2445c76da
Allows to disable the fallback to the default registry on image pull (#2637)
* Allow to disable the fallback to the default registry on image pull

When one or more registry mirror(s) are deffined with the 'registry-mirror' argument, if none of those mirrors include the image,
the current behavior is to fallback to the default registry.
If a whitelist (or some image restriction) is applied at the mirror side, fallbacking to the default registry makes that restriction useless.
This new argument allows to skip the fallback and abort the build if the mirror rejects an image.
If it is not set, is completelly transparent.

* fix typo on command help
2023-07-26 13:05:37 -07:00
Aaron Prindle 974c494b9a
fix: resolve issue where warmer CLI always validated optional arg -> breakage for majority of users (#2603) 2023-06-29 12:11:50 -04:00
Aaron Prindle 2f946a4791
fix: update cache-ttl help text to be correct regarding unit of duration (#2568) 2023-06-28 14:13:21 -04:00
alexezio 0743c19176
feat: cache dockerfile images through warmer (#2499)
* feat: cache dockerfile images through warmer

* Fix logical error in conditional statement

* Addressed review feedback

1. Updated help text for the --build-arg flag to indicate it should be used with the dockerfile flag.
2. Updated the documentation to include the optional --build-arg flag.
3. Added unit tests for `ParseDockerfile`, covering scenarios for missing Dockerfile, invalid Dockerfile, single stage Dockerfile, multi-stage Dockerfile and Args Dockerfile

---------

Co-authored-by: 连奔驰 <benchi.lian@thoughtworks.com>
2023-06-21 12:00:22 -07:00
Zigelboim Misha 4b0bfd2ff0
valdiateFlags typo fixed (#2554) 2023-06-18 19:37:12 -07:00
Eric 7525828ef9
Add mTLS (client cert) registry authentication (#2180)
* Add mTLS (client cert) support

Add support for Mutual TLS (mTLS) client certificate authentication.
The expected format of the new --registry-client-cert flag is the same
as the existing --registry-certificate flag, which will allow
different client certificates for different registries:

--registry-client-cert my.registry.url=/path/to/cert.crt,/path/to/key.key

* tidy: Rename mTLS (Client Cert) flag to be in line with others

This flag didn't describe that it was for the client certs uses with
the registry. Although this should be reasonably obvious, I like the
consistency with the other registry flag.

* test: Added unit tests for mTLS (Client Cert) loading

* test: Add 2 more tests for comma split formatting

since the comma splitting is a new portion of code let's make sure
that that format works well too in other cases

* tidy: Fix formatting of flag help text

* tidy: Made invalid cert format error consistent

I was running the tests and saw the message:

Failed to load client certificate/key '/path/to/client/certificate.cert' for my.registry.name, format is my.registry.name=/path/to/cert,/path/to/key

I then realized that it'd be a lot nicer if this showed the user what
they input, and how they should change it (rather than decomposing it:

Failed to load client certificate/key 'my.registry.name=/path/to/client/certificate.cert', expected format: my.registry.name=/path/to/cert,/path/to/key

* test: Fixed incorrect test argument

This didn't fail the test before because it's only attempting to show
that certs only get loaded and used for their associated registry but
it's important to keep this correct.

This case is covered by the test below, "RegistriesClientCertificates
incorrect cert format"

* doc: Add new flag to README.md

* mod: Fail to push if there was a problem loading client certs

Rather than warning that there was an issue, we should fail if the
requested client certificates were not found or failed to load.

This feels a lot better than waiting for the build to finish then
failing later.

* mod: Return an error if the certificate authority fails to load, just like client certs

The MakeTransport function was changed in the previous commit to
allow returning errors if there was a problem loading certificates,
rather than just print warnings.

This feels a lot better as you get the error immediately that there's
a problem to fix, rather than getting a warning, then later an error
that the server's certificate could not be verified.

* tidy: fix golint issues
2023-05-18 14:20:51 -07:00
Lavrenti Frobeen 76afb70790
Add support for zstd compression (#2313)
* Add support for configurable compression algorithm (gzip, zstd) and compression level

We want to make the layer compression in kaniko configurable, so we have added two optional command line arguments “--compression” and “--compression-level”. The former allows the user to specify a compression algorithm (zstd, gzip) and the latter can be used to specify the compression level.

Depending on the selected compression algorithm and level we modify the set of layerOptions that are used to create tarball layers in `push.go` and `build.go`.

The actual implementation of the zstd support can be found in our fork of the go-containerregistry package for which we have filed this PR: google/go-containerregistry#1487

The changes should be fully backwards compatible.

* Restrict inputs for compression flag to gzip and zstd

This change will ensure that users can only specify supported compression algorithms (`zstd`, `gzip`) to the `--compression` flag.

* Fix incorrect type for switch statements on config.Compression
2023-04-01 22:25:25 -04:00
Joël Pepper 14ea7c4071
Fix Integration tests (#2425)
* fix(ci): Bump golangci-lint to 1.51.1

* chore(lint): fix gofmt and goimport issues

* chore(lint): fix linter issues

- Adapted error comparison according to linter recommendation
- Disabled noctx linting for http request where canceling makes no sense
- Disabled nilerror linting where nil error is returned on purpose
- Disabled makezero linter where slice is explicitly deepcopied

* chore(ci): Update go version in tests workflows

* fix(ci): Allow boilerplate years from 2000-2099

Previously the regex only allowed the copyright notice to contain the
years 2018,2019,2020,2021, or 2022. This commit widens to regex to
20\d\d allowing any year in the range [2000-2099]

* feat(ci): Replace minikube with k3s for intregration tests

The existing setup for minikube is very complicated, replicating most of
the setup steps for a full kubernetes cluster in an only partially
supported minikube configuration (driver=none). Furthermore the existing
setup has been broken for sometime, likely, at least in part due to the
changes to CNI and CRI in recent kubernetes versions.

Since what we actually need is only a running Kubernetes cluster on the
node and access to a registry on localhost:5000, we can switch the
extremely complicated minikube setup for a lightweight cluster using
k3s. Minikube came with a default addon for running a registry on every
node, but the same is not the case for k3s, instead we make use of the
package helm controller and its HelmChart CR to deploy twuni/docker-registry.helm
and expose it on localhost using the integrated LoadBalancer controller.

* fix(test-684): pin base container version

The dockerfile for the regression test connected to issue 684 used a
rolling tag as base image, making it flaky and fail since it was
introduced.

This commit pins the base image to the digest of bionic-20200219, which,
based on the date of the commit that introduced to the dockerfile would
be the most newest ubuntu build and likely what the "rolling" tag
resolved to back then. Since this also an image from the pre-oci days of
ubuntu, this circumvents a bug in container-diff as well
(https://github.com/GoogleContainerTools/container-diff/issues/389)
2023-03-21 12:30:54 -04:00
Natalie Arellano 4d077e2a40
Provide `--cache-repo` as OCI image layout path (#2250)
* Adds the ability to provide `--cache-repo` as an OCI image layout path

- Adds cache.LayoutCache to implement cache.LayerCache interface
- When opts.CacheRepo has "oci:" prefix, instantiates a LayoutCache

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Add integration test for layout cache

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Updates from PR review

Signed-off-by: Natalie Arellano <narellano@vmware.com>

Signed-off-by: Natalie Arellano <narellano@vmware.com>
2022-09-28 10:19:02 -04:00
Gabriel Nützi 90e426ba3f
refactor: Make CLI argument names consistent (#2084)
* fix: Wrong argument naming

* fix: tarPath as well

* Test

* fix: Fix tests

* np: Format markdown

* fix: Review changes
2022-08-22 09:10:11 -04:00
chenggui53 348018d0e9
fix(KanikoDir): update DOCKER_CONFIG env when use custom kanikoDir (#2202)
* Fix(KanikoDIr): update DOCKER_CONFIG env when user defined new KanikoDIr

* Update root.go

* Update root.go
2022-08-12 14:34:19 -04:00
Ramy f9dcb92c38
add cache run command option (#2032)
Co-authored-by: Rami CHAABANE <rchaabane@scaleway.com>
2022-08-09 08:35:00 -04:00
Gabriel Nützi 323e616a67
fix: Refactor `LayersMap` to correct old strange code behavior (#2066)
* fix: Correct flatten function in layers

- Added a test.
- Cache current image, track deletes in `whiteouts` as well as normal adds in `layers`.
- Fix ugly delete behavior of `layerHashCache`.
  Delete it when crerating a new snapshot.
- Slight cleanup in `snapshot.go`.
- Format ugly `WalkFS` function.

* fix: Add symbolic link changes  to Hasher and CacheHasher

* fix: Better log messages

* fix(ci): Integration tests

* fix(ci): Add `--no-cache` to docker builds

* fix(ci): Pass credentials for error integration test

* np: Missing .gitignore in `hack`

* np: Capitalize every log message

- Correct some linting.

* fix: Key function

- Merge only last layer onto `currentImage`.

* fix: Remove old obsolete `cacheHasher`
2022-05-17 20:30:58 -04:00
Jason D'Amour 872758b8b0
feat: add flag to disable pushing cache (#2038) 2022-05-16 12:21:26 -07:00
Jack 25edbb2430
fix: kaniko dir env unused (#2067)
* update kaniko-dir flag description

* add dir check anonymous func for check to config or env

* add kaniko dir constant in default options

* Update cmd/executor/cmd/root.go

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* add CopyDir util usage for checkKanikoDir func

* add removal of kaniko dir on successful copy of new files

* add comment for CopyDir usage

Co-authored-by: Jason Hall <jasonhall@redhat.com>
2022-05-16 12:17:25 -07:00
Diego Gonzalez 1b59a296a8
Use canonical platform values. Fix 1995. (#2025)
* Use canonical image architectures. Closes #1995.

Prior to this change, Kaniko was not using the platform's canonical value.

* Update platform unit test.
2022-03-31 15:15:24 -04:00
Jack d4cf49077a
feat: kaniko dir config option (#1997)
* remove configurables from constants

* add configurables to config init

* add kaniko dir flag

* cleanup pkg constants

* replace buildcontext constants pkg occurrences with config

* add KanikoDir to KanikoOptions

* replace executor constants pkg occurrences with config

* remove redundant KanikoDir assignment

* replace constants to config for IntermediateStagesDir

* fix imports

* add default kaniko directory into constants

* add check for kanikoDir on use

* update init to use default path constant

* update executor kanikoDir check

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* alter checkKanikoDir parameter

* add TestKanikoDir func

* update error handling style

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* remove shorthand flag usage from test

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* add docstring to integration test

Co-authored-by: Jason Hall <jasonhall@redhat.com>

* remove shorthand flag from kaniko-dir

Co-authored-by: Jason Hall <jasonhall@redhat.com>
2022-03-31 15:10:23 -04:00
Igor Scheller 7b161105a5
Move and fix GetContainerRuntime check from bpfd proc (#1996)
* Moved genuinetools/bpfd proc

* Removed unused code from util/proc, added genuinetools/bpfd proc test, fixed naming

* refactor: adjust bpfd container runtime detection

* Moved util/proc.go to util/proc/proc.go, added boilerplate

Co-authored-by: ejose19 <8742215+ejose19@users.noreply.github.com>
2022-03-23 11:09:01 -04:00
Oliver Gregorius 86493d07cc
Removed whitelist-var-run normalization as this breaks functionality (#1956)
Closes #1795
2022-02-27 15:49:37 -05:00
Jason Hall 3589382378
Correctly handle platforms that include CPU variants (#1929)
* Correctly handle platforms that include CPU variants

Prior to this change, Kaniko would only select the platform-specific
image from a multi-platform image using the OS and architecture to
select the image. This leads to problems when there are two platforms
that are indistinguishable using only this information (e.g.,
linux/arm/v5 and linux/arm/v7).

This change more explicitly selects the right image from a
multi-platform image, taking CPU variant into account (v5 vs v7), using
containerd's CPU variant detection logic.

This also moves platform defaulting up as early as possible in execution
as it can go, so that malformed platform values are detected as soon as
possible.

* set platform in unit test
2022-02-10 09:12:23 -08:00
Jason Hall 1a6b8ce37b
Add KANIKO_REGISTRY_MIRROR env var (#1875) 2022-01-14 10:07:55 -06:00
Jason Hall 633f555c5c
Fix implicit GCR auth (#1856)
* Fix implicit GCR auth

* boilerplate
2021-12-28 20:34:32 -05:00
Tejal Desai cf4822c31c
Run docker_credentials_gcr in warmer (#1780)
* run docker_credentials_gcr in warmer

* fix tests

* fix dockerfiles

* fix boilerplate

* mend

* fix

* another lint
2021-10-19 12:25:42 -07:00
Janosch Maier 46e01340c2
Remove tarball.WithCompressedCaching flag to resolve OOM Killed error (#1722)
* Remove tarball.WithCompressedCaching flag to resolve OOM Killed error

Large images cannot be build as the kaniko container will be killed due to an OOM error. Removing the tarball compression drastically reduces the memory required to push large image layers. Fixes #1680

This change may increase the build time for smaller images. Therefore a command line option to trigger the compression or a more intelligent behaviour may be useful.

* Add new command line flag to toggle compressed caching

* Add unittest for build with --compressed-caching command line flag set to false
2021-10-19 00:14:06 -07:00
Rhianna b525d1e27b
Support force-building metadata layers into snapshot (#1731)
* feat: add support for forcing build metadata

* Chore: Added snapshot forceBuildMetadata flag tests.
2021-10-18 11:43:51 -07:00
Jose Donizetti 5b3fb84a22
Retry extracting filesystem from image (#1685)
* Retry extracting filesystem from image

* Add flag image-fs-extract-retry

* Add --image-fs-extract-retry documentation
2021-07-08 12:00:22 -07:00
Tejal Desai 04fb2fd55e
rename flag `--whitelist-var-run` to `ignore-var-run` (#1668)
* rename flag

* instead depcrecate

* add normalize function
2021-06-14 12:08:37 -07:00
Kamal Nasser f21639daac
Fix snapshotter ignore list; do not attempt to delete whiteouts of ignored paths (#1652)
* avoid deleting whiteouts if they are in ignore list

* fix snapshotter ignore list

* include filesystem mounts in ignorelist of snapshotter
* clean up ignore list logic

* add unit and integration tests for #1652

* fix tests and ignore list updates
2021-06-04 10:07:24 -07:00
Benjamin Krenn 57ea150cad
Exit Code Propagation (#1655)
* exit codes of failed RUN commands may now be propagated to the caller by using the --propagate-exit-code flag

* removed exit code propagation flag; the exit function now unwraps the error and looks for an exit code

* added integration test for exit code propagation

* added trailing new line in test Dockerfile_exit_code_propagation; tidying up README.md removing all traces of error propagation flag

* moved exit code propagation test to integration_test.go; moved exit code propagation test files to 'testdata' to avoid interference with other integration tests
2021-06-01 10:43:49 -07:00
Chris Hoffman ac1fc88081
Copy dockerfile.dockerignore if it exists when copying Dockerfile (#1607) 2021-04-14 09:02:24 -07:00
Jon Friesen d40a51f38f
adds ignore-path command arguments to executor (#1622)
* adds ignore-path command

* add flag to README
2021-04-13 14:29:51 -07:00
Sascha Schwarze 69f942f751
Improve retry behavior for push operation (#1578)
* Update go-containerregistry to 0.4

* Implement --push-retry argument
2021-02-22 21:25:58 -08:00
Tejal Desai ffd35dbe12
Mutli-arch support (#1531)
* initial commit

* remove bazel jobs

* fix arch

* more fixes after testing and code review comments

* fix build platform

* add individual cloudbuild.yaml as its taking 45 mins for a cloud build trigger

* add buildx plugin

* add more debugging

* update busybox version to fix CVE-2018-1000500

* fix

* lint + more debug

* fix

* fix

* fix

* remove images from cloudbiuld

* move CI job back to docker

* one more fix

* lets see

* bring it back

* move CI job back to docker

* remove aerg from top

* live restart config

* remove live restore as minikube setup failed

* add --force-systemd

* add --force-systemd and docker driver none

* change the --run flag

* docker info and some logs removed

* fix docker command

* upgrade version for buildx to 0.5.1

* remove docker service from travis.yml and add systemd cgroup config

* move the docker config up

* move them back to docker build

* fix

* fix all dockerfiles

* fix warmer

* fix

* rm bazel jobs

* add more logs

* fix debug

Co-authored-by: ankitm123 <ankitmohapatra123@gmail.com>
2021-01-25 17:49:19 -08:00
Or Geva b3e036aab2
Add --image-name-tag-with-digest flag (#1541) 2021-01-19 13:28:05 -08:00
Tejal Desai 9f76932171
Update GowalkDir dependency to pick up fixes. Added default 90 min timeout for walking FS. Override it with environment variable. Add slowjam to kaniko pod (#1530) 2020-12-21 22:40:37 -08:00
Tejal Desai b04399eeac
add caching copy layers back (#1518)
* add caching copy layers back

* fix test

* lint

* fix test - 2

* Add integration test

* fix lint
2020-12-11 00:25:03 -08:00
Vincent Behar dde98a8e73
feat(warmer): Warmer now supports all registry-related flags (#1499)
which means we can now:
- set up one or more mirrors
- set up registries certificates
- skip TLS verify
- use plain HTTP
using the same set of flags that are defined for the executor
2020-12-10 22:55:43 -08:00
Severin Strobl c2a919a801
Switch to runtime detection via bpfd/proc (#1502)
The upstream of github.com/genuinetools/amicontained switched to the
container runtime detection via github.com/genuinetools/bpfd/proc,
which supports a larger range of container runtimes. With this change
(among others) Podman can be detected correctly.

Fixes #1501.
2020-12-09 11:44:31 -08:00
Vincent Behar 131828a1ad
feat: support multiple registry mirrors with fallback (#1498)
Fixes #1473

The initial implementation of the registry mirror only allowed a single mirror, and if pulling from the mirror failed, the build would fail.

This change introduces:
- multiple registry mirrors instead of a single one
- fallback if an image can't be pulled from a registry

This is the same behavior as the docker daemon and will allow using a registry mirror such as `mirror.gcr.io` which is incomplete and doesn't have all the content that the default registry on docker.io has.

Note that there are no changes in the CLI flags, the `--registry-mirror` flag is still valid. But now it can be used multiple times to set up more than one registry mirror.

Co-authored-by: Tejal Desai <tejaldesai@google.com>
2020-12-08 16:16:25 -08:00
mickkael 275cc9a7e7
Add option customPlatform (#1500)
* Add option customPlatform

* fix formatting

* fix No newline at end of file
2020-12-08 16:11:18 -08:00
Yulia Gaponenko 49e7d8a8cd
Add s390x kaniko build to multi-arch list (#1475)
This is extenion of current code to build s390x version of kaniko
executor image and add it to multi-arch manifest

Signed-off-by: Yulia Gaponenko <yulia.gaponenko1@de.ibm.com>
2020-11-04 14:03:16 -08:00