Commit Graph

879 Commits

Author SHA1 Message Date
Lukas 679c71c907
refactor: simpler local integration tests (#2110)
* tests(integration): add fake gcs server and use sdk instead of gsutil

* tests(integration): add flag to run tests for a subset of dockerfiles

Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>

* tests(integration): conditionally create gcs client

* refactor: create package for gcs bucket interaction

* tests(integration): use util.Tar for integration tarball creation

* refactor: create TarballOfDirectory func

* chore: add dockerignore for faster builds

* docs: add docs for dockerfile pattern

* fix: issue during personal review

* chore: cleanup

Signed-off-by: Höhl, Lukas <lukas.hoehl@accso.de>

* fix(integration-tests): remove default bucket

Signed-off-by: Lukas Hoehl <ludi.origin@gmail.com>
2022-06-14 13:38:01 -04:00
Hingbong Lo 9f57952214
fix: use refrence should after err handles (#2128)
* fix: use refrence should after err handles

* Update pkg/executor/build.go

Co-authored-by: Jason Hall <jason@chainguard.dev>
2022-06-09 11:00:30 -04:00
Andreas Fleig bc46c24707
Write parent directories to tar before whiteout files (#2113)
* Write parent directories to tar before whiteout files

Fixes #1149

The OCI image spec does not specify this order but it's a good idea and Docker
does the same.

When manually comparing layers created by Docker and Kaniko there are still
some differences (that container-diff does not show):

* Kaniko adds / to layers
* For `mkdir /test`, docker adds `/test` and an opaque whiteout file
  `/test/.wh..wh..opq`. Kaniko only adds `/test/` (and /).

* snapshot_test: cleanup

Fix typos and use listFilesInTar() where possible
2022-05-31 16:42:32 -04:00
Tony De La Nuez 77ac6942a6
Fix missing setuid flags on COPY --from=build operation (#2089)
* Fix missing file permissions on multi-stage build

Fixes #2075

When a file with the setuid bit is copied from one stage
to another, the permissions were not copied over properly after
setting ownership on directory and the file itself.

* Update pkg/util/fs_util.go

Co-authored-by: Jason Hall <jason@chainguard.dev>

* Adding boilerplate to dockerfile

* Add bash check to bail with exit code 1 if setuid not present

Co-authored-by: Jason Hall <jason@chainguard.dev>
2022-05-22 09:20:18 -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
Gabriel Nützi 28432d3c84
fix(ci): Docker build for issue 1837 (#2095)
* fix: Docker build for issue 1837

* fix: Linting
2022-05-17 14:21:57 -04:00
Gabriel Nützi 7b50fc8a57
fix: Main (#2094) 2022-05-17 13:27:24 -04:00
Jason D'Amour 872758b8b0
feat: add flag to disable pushing cache (#2038) 2022-05-16 12:21:26 -07:00
zhouhaibing089 96a8ee0c07
hasher: hash security.capability attributes (#1994)
In Dockerfile, if there is something like:

```
RUN setcap cap_net_raw=+ep /path/to/binary
```

kaniko won't detect that there is a change on file `/path/to/binary` and
thus discards this layer. This patch allows the hasher function to
actually look at `security.capability` extended attributes.
2022-05-04 12:31:10 -04:00
Gabriel Nützi 76a54a031d
Fix: Flatten layer function needs to return existing files in the layer correctly (#2057)
* fix: Remove hardcoded whiteout prefix

* fix: Flatten function should return all existing files without whiteouts

* np: Documentation
2022-04-26 16:46:09 -04:00
Gabriel Nützi 9df31b1bcb
fix: Remove hardcoded whiteout prefix (#2056) 2022-04-25 14:52:30 -04:00
Víctor 13ed53e25c
proc: detect kubernetes runtime by mounts (#2054)
Fix #1936
Kubernetes was not being detected by files not by /proc/?/cgroup
contents. Now it detects the kubernetes runtime if any of those
conditions are met:

* /var/run/secrets/kubernetes.io/serviceaccount exists
* /proc/mounts has the mount for "/" with fs type "overlay"
2022-04-18 10:20:42 -04:00
François JACQUES f9c5745c63
Fixes #2046: make target stage lookup case insensitive (#2047) 2022-04-12 09:54:14 -04:00
ePirat f930b75b8b
Add GitLab CI credentials helper (#2040)
This simplifies usage of Kaniko in GitLab CI environments and
means that it's not longer necessary to manually cobble together
the config with the right values from the environment in
error-prone shell commands.
2022-04-11 13:13:47 -04: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
Naveen 783979948d
Fix - Incomplete regular expression for hostnames (#1993)
Fixed the codeql issue
```
Sanitizing untrusted URLs is an important technique for preventing attacks such as request forgeries and malicious redirections. Often, this is done by checking that the host of a URL is in a set of allowed hosts.

If a regular expression implements such a check, it is easy to accidentally make the check too permissive by not escaping regular-expression meta-characters such as ..

Even if the check is not used in a security-critical context, the incomplete check may still cause undesirable behavior when it accidentally succeeds.

```
2022-03-16 00:16:04 -04:00
Jason Hall f067edae9f
Fix bug with log disabling (#1959)
Prior to this change, Kaniko disabled logging for its ecr-login
dependency by redirecting the logger's output to ioutil.Discard.
However, since that used the logrus standard logger, this had the effect
of completely disabling (redirecting to Discard) _all_ logging done by
Kaniko.

This caused integratiion test failures, and left any user of Kaniko
without any logging.

This fix updates the dependency on ecr-login to include a fix for this
issue, and updates to the new API introduced in that fix.
2022-02-28 15:02:05 -05:00
Jason Hall c6623cd1e3
Bump ecr-login dep to avoid some log spam (#1946)
Previously the ecr-login cred helper we compile into the executor/warmer
binaries would log a warning when they were asked for credentials for a
non-ECR image. This takes advantage of recent work in ecr-login to let
consumers like kaniko disable that logging.
2022-02-21 02:20:02 +05:30
Gabriel Nützi 2d94d56af7
Fix resolving arguments over multi-stage build (#1928)
* Fix resolving argument over mulit-stage build

- Building multi-stage Dockerfiles did not correctly resolve
  ARG commands over different stages. Now, each stage depends on the
  build arguments set by the stage before.

Closes: #1911

* Fix resolving empty arg commands
2022-02-10 09:22:21 -08: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
Florian Apolloner ef97636546
Restore build args after optimize. Fixes #1910, #1912. (#1915)
* Restore build args after optimize. Fixes #1910, #1912.

* Apply review suggestions.
2022-02-09 11:50:40 -05:00
Eng Zer Jun 0adbbee21d
test: use `T.TempDir` to create temporary test directory (#1918)
The directory created by `T.TempDir` is automatically removed when the
test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-02-07 13:27:34 -05:00
Jason Hall a7425d1fd0
Remove k8schain, statically link helpers (#1891) 2022-01-21 12:42:12 -08:00
Jason Hall 76624697df
Bump github.com/docker/docker to latest release (#1866)
* Bump github.com/docker/docker to latest release

* Pin deps to docker/docker's requirements

fix build breakages
fix unit test
Trying to see whether am-i-in-a-container checks are broken for integration tests...
2022-01-14 15:58:32 -05:00
Dawei Ma ee2249b3d5
fix: ARG/ENV used in script does not invalidate build cache (#1688) (#1693) 2021-12-30 12:51:00 -05:00
Jason Hall 633f555c5c
Fix implicit GCR auth (#1856)
* Fix implicit GCR auth

* boilerplate
2021-12-28 20:34:32 -05:00
Jason Hall 129df249c9
Log full image ref by digest when pushing an image (#1857) 2021-12-28 07:13:11 -06:00
Andrei Kvapil 2ea368dde8
tar: read directly from stdin (#1728)
* tar: run directly from stdin

* export UnTar function
2021-12-26 07:09:26 -05:00
Guillaume Calmettes d2f3e896cd
Fix regression: can fetch branches and tags references without specifying commit hashes for private git repository used as context (#1823)
* [FIX] can fetch tags and branches refs without specifying commit hashes

* [ENH] more precise comment
2021-12-24 15:13:45 -05:00
Andrei Kvapil e38b0c8d90
Fix calculating path for copying ownership (#1859)
* Fix calculating path for copying ownership

* fix CI
2021-12-24 07:09:53 -05:00
Andrei Kvapil 7065921aa4
Fix copying ownership (#1725)
* fix uid, gid overriding

* fix ownership for staging building

* add integration test

* add check for ignored files

* improve errors
2021-12-23 13:25:55 -05:00
Lars Seipel ac1a703731
Fix possible nil pointer derefence in fs_util.go (#1813)
When os.Stat returns an error different from ErrNotExist,
mkdirAllWithPermissions may panic with a nil pointer
derefence due to insufficient error checking.

Avoid the panic by bailing out, returning the error to the
caller.
2021-12-23 11:37:27 -05:00
ygelfand b3ec974cfc
include auth when fetching specific specs (#1796)
Signed-off-by: ygelfand <yuri@shlitz.com>
2021-12-23 11:36:19 -05:00
Travis DePrato ee95be1e27
Use pax tar format (#1809)
* Use PAX tar format

* Add test case
2021-12-23 11:35:00 -05:00
François JACQUES 5c81fa5774
Fixes #1837 : keep file capabilities on archival (#1838)
Signed-off-by: JACQUES Francois <hypnoce@donarproject.org>
2021-12-22 20:05:39 -05:00
Tejal Desai ee31dc93b6
Revert "Support mirror registries with path component (#1707)" (#1794)
* Revert "Support mirror registries with path component (#1707)"

This reverts commit 4e218f2162.

* fix tests and add co-sign back
2021-10-20 19:13:24 -07:00
wwade 82fc94d930
git: accept explicit commit hash for git context (#1765)
* git: accept explicit commit hash for git context

When checking out code from non-github repositories, the typical
assumptions may not be valid, e.g. that the only interesting
non-branch commits have ref names starting with refs/pull. A specific
example is fetching an un-merged commit from a gerrit repository by
commit hash.

This change just looks at the second part of the git context path and
checks if it's a SHA commit hash, and if so, will fetch and check out
this commit after cloning the repository.

Sample context argument:

    https://github.repo/project#e1772f228e06d15facdf175e5385e265b57068c0

* ci: fix test script to recognize any non-zero exit as an error

hack/linter.sh didn't properly install golangci-lint in hack/bin as I
already have another version of golangci-lint on my PATH, but then it
failed to execute because it was looking for it specifically in
hack/bin.

When the executable is not found, the exit code is 127 instead of 1,
and so test.sh ignored the error.

Two fixes:

1. `test.sh`:
  - Use `if (script) ...` instead of assigning / checking a result
    variable to determine if each validation script passed or failed.

2. `hack/linter.sh`:
  - Instead of checking for golangci-lint on the path, just
    specifically check for an executable file (`test -x`) in the
    expected location.

Co-authored-by: Wade Carpenter <wwade@users.noreply.github.com>
2021-10-19 19:27:15 -07: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
Gilbert Gilb's a42adb9bb4
Fix composite cache key for multi-stage copy command (#1735)
* chore: add workflows for pr tests

* fix unit tests

* fix formatting

* chore: fix gobuild

* change minikube script

* chore: fix lint install script

* chore: ignore and fix tests

* fix lint and run gofmt

* lint fixes

* k8s executor image only

* fix Makefile

* fix travis env variables

* more info on k8s tests

* fix travis run

* fix

* fix

* fix

* fix log

* some more changes

* increase timeout

* delete travis.yml and fix multiple copy tests

* fix registry mirror

* fix lint

* add concurency

* last attemot to fix k8 integrations

* diff id for diff workflows

* Fix composite cache key for multi-stage copy command (#1706)

PR #1518 reintroduced COPY layers caching using the `--cache-copy-layers`
flag. Unfortunately, this PR also introduced a bug by not including the
stage digest into the caching key of the COPY command when the
`--cache-copy-layers` flag was not set. As a result, kaniko would use
any previous (possibly stalled) layer from the cache because the digest
of the "COPY --from" command would never change.

PR author probably expected Go to fallthrough in the switch just like C
does. However, this is not the case. Go does not fallthrough in
switch-statements by default and requires the fallthrough keyword to be
used. Note that this keyword is not available in type-switches though,
because it wouldn't work properly with typings.

* refactor: add an abstract copy command interface to avoid code duplication

* fix typo in error message

Co-authored-by: Tejal Desai <tejal29@gmail.com>
2021-10-18 23:31:01 -07:00
Tejal Desai 1da17b6e9b
chore: add workflows for pr tests (#1766)
* chore: add workflows for pr tests

* fix unit tests

* fix formatting

* chore: fix gobuild

* change minikube script

* chore: fix lint install script

* chore: ignore and fix tests

* fix lint and run gofmt

* lint fixes

* k8s executor image only

* fix Makefile

* fix travis env variables

* more info on k8s tests

* fix travis run

* fix

* fix

* fix

* fix log

* some more changes

* increase timeout

* delete travis.yml and fix multiple copy tests

* fix registry mirror

* fix lint

* add concurency

* last attemot to fix k8 integrations

* diff id for diff workflows
2021-10-18 23:22:44 -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
Jason Hall 4e218f2162
Support mirror registries with path component (#1707) 2021-08-10 22:06:51 -07:00
nihilo 682191f523
Bugfix/trailing path separator (#1683)
* Test_EnvReplacement: env of path ends in a slash

* Fix trailing path separator
2021-07-08 12:06:52 -07:00
Silvano Cirujano Cuesta 1d9bc175c2
Add support for CPU variants (#1676)
Signed-off-by: Silvano Cirujano Cuesta <silvano.cirujano-cuesta@siemens.com>
Inspired-by: mickkael 19755421+mickkael@users.noreply.github.com
2021-07-08 12:05:38 -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 094fe52b37
Revert "save snaphots to tmp dir (#1662)" (#1670)
This reverts commit 754253d375.
2021-06-14 12:09:07 -07:00
Patrick Barker 754253d375
save snaphots to tmp dir (#1662) 2021-06-14 12:08:47 -07:00