Commit Graph

947 Commits

Author SHA1 Message Date
Michael Plump 3e56c7fd0f
chore: upgrade all the dependencies to their latest versions (#3454)
* chore: go get -u ./...

* chore: go mod tidy

* chore: go mod vendor

* chore: fix compilation for buildkit >= 0.15.0

* chore: upgrade to Go 1.24

* chore: upgrade the Debian container used in an integration test
2025-05-21 09:31:10 -04:00
Mick van Gelderen e1089414cb
fix: prevent panic when image name and stage alias are the same (#3245) 2024-07-10 09:34:45 -07:00
Aaron Prindle 5283199713
deps: bump github.com/moby/buildkit and github.com/docker/docker (#3242) 2024-07-08 13:02:39 -04:00
Leo Palmer Sunmo 6a340c6a1f
Enable pushing cache with --no-push (#3181)
Make sure we check --no-cache-push instead of --no-push when deciding whether to
push cache or not.
2024-06-04 11:21:16 -07:00
Prima Adi Pradana 34905d62e2
fix: warn instead of error when COPY wildcard does not match any files (#3127)
* when using wildcard hitting ResolveEnvAndWildcards ignore error when there is no file match

* adding unit test

* fix unit test wrong check in expected

* fix unit test for make sure there is no file copied

* copy with wildcard warning and success when no match file

* fix Test_IsSrcsValid since its changes the behaviour
2024-05-13 22:38:51 -07:00
Marc Lallaouret 7f365a644a
fix: make --registry-map compatible with namespaced images (#3138)
* For each registry mapping, represent it by a new instance of Repository and
  create a new Reference containing it.
* Improve registry mapping parser
* Add more unit tests to cover more use cases
2024-05-13 18:46:36 -07:00
Samarth08 d65b9b5418
"fix: resolve issue where cache layers would be pushed if --no-push was specified" (#3132) 2024-05-13 17:13:55 -07:00
Matthias Schneider a9062b97f7
feat: Added --chmod for ADD and COPY command. Fixes #2850 (#3119) 2024-04-22 09:28:37 -07:00
Prima Adi Pradana 02f488a694
Fix #3032: Remove query parameters in ADD command when the destinatio… (#3053)
* Fix #3032: Remove query parameters in ADD command when the destination is a directory

* fixing linter URL sorry forget to lint

* add error in extractFilename and realize that ResolveEnvironmentReplacement better execute before getting the filename
2024-03-21 19:32:40 -07:00
Prima Adi Pradana 9095b45d5c
Kaniko/add path regmaps [possible in registry maps and/or mirror] (#3051)
* add /path possible in registry maps and/or mirror

* Fixing Unit test Test_ExtractPathFromRegistryURL

* fix typo library

* fix unit test on ExtractPathFromRegistryURL

* fixing go lint url

* fix typo s/ectract/extract
2024-03-21 19:29:41 -07:00
Alessandro Bitocchi ba433abdb6
Fix COPY fails when multiple files are copied to path specified in ENV (#3034)
* Fixed unsolved ENV variable used as dest of COPY

* added unit test for copy cmd using env var as dest

* remove comment
2024-03-19 00:24:46 -07:00
Jérémie Augustin 8148159c30
Add AWS ECR error message for tag Immutability (#3045) 2024-03-18 23:01:34 -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
Alessandro Bitocchi d5c36a6210
Fix unpack tar.gz archive with ADD instruction, issue #2409 (#2991)
* Fix unpack tar.gz archive with ADD instruction, issue #2409

* Added unit test for ADD instruction
2024-02-28 23:16:42 -08: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
Kraev Sergei da3878e16b
Fix missing or partial support for pattern substition in variable references with cache enabled (#2968) 2024-02-13 18:57:19 -08:00
Aaron Prindle 081269d8bb
chore(deps): bump github.com/moby/buildkit from 0.11.6 to 0.12.5, github.com/docker/docker from 24.0.7+incompatible to 25.0.2+incompatible, and other deps (#2995) 2024-02-09 18:03:08 -08:00
Asher 398ebfb6da
Prevent extra snapshot with --use-new-run (#2943)
* Prevent extra snapshot when using new run

* Add unit tests for initializing snapshotter

There should be no snapshot for RunV2.  Added a test for SingleSnapshot
as well to prove that the test actually works (rather than `initialized`
just not being read or set properly).
2024-01-16 21:14:03 -08:00
Bob Du 16ed6b2428
replace Azure/azure-storage-blob-go => Azure/azure-sdk-for-go/sdk/storage/azblob (#2945)
Signed-off-by: BobDu <i@bobdu.cc>
2024-01-16 10:45:40 -08:00
Aaron Prindle dd752d9bbc
chore: update gcr and docker cred helpers (#2910) 2023-12-19 12:36:13 -05:00
Maxime BOSSARD df488dac40
Reproducing and Fixing #2892 (#2893)
* Add an integration test to reproduce #2892

* Fix go compilation

* Fix docker run cmd

* Fixing entrypoint

* Test warmer with cache in a volume.

* Add missing comma

* Fix imports

* Fix dir

* Add logs

* fix

* Use test framework to log

* Fix warmer failing if image already in cache.

* Fix format.
2023-12-14 17:00:54 -08:00
Aaron Prindle 9e992703e4
fix: resolve issue with copy_multistage_test.go and broken ioutil import (#2879) 2023-11-29 10:51:39 -08:00
JeromeJu 9e595494b6
Skip the /kaniko directory when copying root (#2863)
This commit adds the skip option for otiai10.Copy to skip the /kaniko
directory when the root is being copied. The files under /kaniko dir
should be ignored and thus this shall not cause any loss of information.

fixes: GoogleContainerTools#2033
2023-11-28 19:49:35 -08:00
Maxime BOSSARD e4791117c5
fix: resolve warmer memory leak. (#2763)
* Fix warmer memory leak. Write down images directly into a temp file. Add a script to test warmer in boxed memory conditions. Fixes: #2754

* Document usage of boxed_warm_in_docker.sh integration test.
2023-11-28 19:30:13 -08:00
Manish Giri 7bfc73c3ad
fix: Remove references to deprecated io/ioutil pkg (#2867)
* Update benchmark_test

* Updae tar.go

* Update further refs

* Commit next set of replacements

* Reverting changes in vendor folder

* Update integreation_with_context_test.go

* Update k8s_test.go

* Update remaining usages

* Replace conflicting usage of fs local variable
2023-11-28 13:02:53 -08:00
Adrià Garriga-Alonso 143e69492d
Create intermediate directories in COPY with correct uid and gid (#2795)
* Create directories with the right UID/GID

* Forgot to create the actual directory

* Integration test creation of intermediate files with correct ownership

* ADD version of the test
2023-11-28 10:43:42 -05: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
tal66 401616bb38
refactor: rm bool param detectFilesystem in `InitIgnoreList` (#2843) 2023-11-14 20:10:44 -05:00
Lio李歐 e5395c7a21
feat: support https URLs for digest-file (#2811)
This feature allows one to specify an https URL for any of the
digest-file options, resulting in an HTTP PUT to the provided
URL. This could for example be a (pre-signed) URL to S3 or GCS.

Currently the final digest is only written to the local filesystem,
which disappears and is not accessible when Kaniko is run in a
managed container service like AWS ECS.

By supporting https a single implementation supports all storage
services, without the need for special code for S3, GCS, etc..
2023-11-10 11:05:36 -08:00
Anna Levenberg 5133ad83b1
impl: add a retry with result function (#2837)
* impl: add a retry with result function

* fix ci errs
2023-11-09 22:12:20 -08:00
Quan Zhang b433ddd6bb
fix: fix `COPY` command error due to missing but ignored files (#2812)
Fixes https://github.com/GoogleContainerTools/kaniko/issues/1598.

This commit puts `context.ExcludesFile` before `os.Lstat` to avoid the `COPY` command error due to missing but ignored files.
2023-10-31 13:29:23 -07:00
zhouhaibing089 e65bce193d
snapshotter: use syncfs system call (#2816)
`sync` system call triggers a full page cache sync which may not always
work, especially in kubernetes environment where it is easy to be
interfered by others. I have seen several cases where a broken nfs mount
is blocking kaniko from doing its job.

With `syncfs`, it only writes cache back to disk for the current
filesystem that is used by kaniko which is supposed to be more reliable.
2023-10-30 16:59:40 -07:00
JeromeJu b6f14ae676
Add test cases and docString for regex in COPY command (#2773) 2023-10-10 08:07:18 -07:00
Vishal Khot 2a1b29a9f1
Remove fallbackToUID bool option from Kaniko code (#2767) 2023-10-02 17:36:15 -07:00
Aaron Prindle 3d1ad4c64a
chore: update function names to be correct and representative of functionality (#2720) 2023-09-20 10:55:40 -07:00
Logan Price 14b2ea5528
feat: ensure images layers correspond with the image media type (#2719)
Ensure zstd compression only gets applied to oci images.
When adding a layer to an image ensure that they are compatable if not convert them.
Create function to convert mediatypes between oci and docker types.
2023-09-13 10:49:56 -07:00
guangwu 382cf3a9c2
chore: unnecessary use of fmt.Sprintf (#2717)
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-09-01 09:44:31 -07:00
geekvest 5df0343d5b
fix function name on comment (#2707)
Signed-off-by: geekvest <cuimoman@sohu.com>
2023-09-01 09:31:52 -07:00
Diego Gonzalez 2b6b5948da
Avoid returning the UID when resolving the GIDs. (#2689)
* Fix GetUIDAndGIDFromString test.

* Avoid returning by default the UID when resolving the GIDs.
2023-08-31 18:05:27 -07:00
Logan Price e9787f85d4
fix: ensure layer media type matches image media type if oci image (#2700)
test: add to ensure media type being saved
2023-08-29 10:33:13 -07:00
JeromeJu 6ee84f128d
Change condition for the behavior when --no-push=true without --destinations (#2676)
This commit changes the condition check for the behavior when no-push is
set to true while destinations are needed. Prior this change, users would
have to set destinations even when noPush option is set to true. More
specifically, a workaround for tar files to be generated when --no-push is
true and destinations is empty is provided where a dummy destination would be
set.
2023-08-17 09:53:59 -07: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
Aaron Lehmann 32ce1bf67e
Avoid redundant calls to filepath.Clean (#2652)
filepath.Clean shows up in profiles as a hot spot, and there seem to be
many redundant calls, particularly in ignorelist handling. We can avoid
these redundant calls by pre-cleaning entries in the ignore list, and
providing fast paths when we know we're already dealing with a cleaned
candidate path.

Before:

     580ms  3.03% 72.35%      590ms  3.08%  path/filepath.(*lazybuf).append (inline)
     390ms  2.03% 74.39%      990ms  5.16%  path/filepath.Clean

After:

     0.13s  0.69% 84.01%      0.17s  0.91%  path/filepath.(*lazybuf).append (inline)
     0.13s  0.69% 84.70%      0.31s  1.65%  path/filepath.Clean
2023-07-31 17:18: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 a6bd60efd6
chore: add debug line to RedoHasher (#2591) 2023-06-28 14:13:35 -04:00
Andreas Fleig 0d925dd651
Don't write whiteout files to directories that were replaced with files or links (#2590)
If a non-empty directory gets replaced with something other than a
directory (e.g. file or symlink), the files in that directory also get
deleted. However, there should not be any whiteout files for them in the
layer. If there were, the resulting tar file would not be extractable.

Fixes #2308
2023-06-22 10:45:47 -07: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
Andreas Fleig 01763bce5b
Fix fs_util tests failing on systems with /tmp mountpoint (#2583)
* Rename IgnoreListPath to MountInfoPath in config & constants

The string points to /proc/self/mountinfo

* fs_util_test.go: fix tests failing when /tmp mountpoint present

The tests

* Test_GetFSFromLayers_ignorelist
* Test_GetFSFromLayers_with_whiteouts_include_whiteout_disabled
* Test_GetFSFromLayers_with_whiteouts_include_whiteout_enabled

were failing on systems with a /tmp mountpoint:

fs_util.InitIgnoreList() adds all mountpoints to the ignore list,
but the tests were expecting file operations in a /tmp subdirectory.

This change provides an empty mountinfo list for the affected tests.

Fixes #1779
2023-06-19 12:01:20 -07:00
Kraev Sergei eea12bd025
Fix multistage caching with COPY --from (#2559)
* Removed block on use --cache-copy-layers with multistage builds
* Removed using digest in composite key with command COPY --from
* COPY --from command uses src as file context (only changed files will be reason for change hash)
* ARG and ENV changed before COPY dont change composite key
* Add and fix some tests
* Caching work same as caching in docker buildx

Co-authored-by: Sergei Kraev <skraev@tradingview.com>
2023-06-16 10:56:05 -07:00