Commit Graph

42 Commits

Author SHA1 Message Date
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
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
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
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
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
Christopher Hlubek 5c61bc44bd Remove unreliable unit test for SnasphotFS with whiteout 2020-07-20 11:35:25 +02:00
Christopher Hlubek 699a4bee32 Bugfix: Reproducible layers with whiteout
When deleting files of previous layers, the whiteout files
were not added to the tar file in a consistent order.

This change adds a stable sorting to the whiteout files and
adds unit tests to check for stable sorting.
2020-07-16 10:56:59 +02:00
Tejal Desai 4ac51ef515 merge 2020-06-06 20:17:17 -07:00
Tejal Desai c576771497 fix tests 2020-06-06 11:37:35 -07:00
Tejal Desai 43338d4b2f add a new run command along with a new flag 2020-06-05 19:53:16 -07:00
Gábor Lipták bec0e6a8e3
Correct typo 2020-05-07 16:24:07 -04:00
Gilbert Gilb's fd8a2d6dd8 Merge branch 'master' into snapshot-directories 2020-03-31 14:25:04 +02:00
Gilbert Gilb's e5585fded8 Always add parent directories of files to snapshots.
During a snapshot, when a file changed and not its parent directories,
the parent directories weren't added to the layer. This is inconsistent
with Docker's behavior which always add parent directories to the layer.
In some edge-cases, it could lead to problems with docker considering
that parent directories where owned by root in forthcoming layers
although they shouldn't (see #1163).

Also, Docker seems to be POSIX compliant regarding the name of
directories in the archive, which always have a slash appended. This
commit also fixes this.

Fixes #1163
2020-03-29 18:25:37 +02:00
Tejal Desai caaf6c8adf fix tests 2020-03-24 10:50:59 -07:00
cvgw 965b606720 remove cruft and unneeded loop 2020-02-23 13:38:08 -08:00
cvgw a675ad998a Resolve filepaths before scanning for changes 2020-02-20 09:45:44 -08:00
Tejal Desai c9dc474031 fix linter 2020-02-07 13:47:17 -08:00
Tejal Desai 8b69a13641 fix commut 2020-02-06 15:37:47 -08:00
Tejal Desai 674f5bda5d fix tests 2020-02-06 15:17:09 -08:00
tinkerborg 82bce229bd omit uname/gname in tar headers
When using cache, the rootfs may not have been extracted. This prevents uname/gname from resolving
as there is no /etc/password or /etc/group. This makes this layer unnecessarily differ from
a cached layer which does contain this information. Omitting these should be consistent with Docker's
behavior.
2020-02-06 13:36:26 -05:00
tinkerborg cc2c9a0663 sort filesToAdd in TakeSnapshot
filesToAdd is sorted in TakeSnapshotFS, but not here. This makes ordering unpredictable within the layer's tarball,
causing the SHA to differ even if layer contents haven't changed
2020-02-06 13:36:21 -05:00
Tejal Desai 3e5d0a6334 add unit tests 2020-01-23 11:12:54 -08:00
Tejal Desai 873b577e1a
Merge pull request #729 from xanonid/Remove_leading_slash_in_layer_tarball_paths
Remove leading slash in layer tarball paths (Closes: #726)
2019-09-13 10:05:25 -07:00
xanonid 1fa2527a7b Adapt tests such that expected paths do not contain a leading / 2019-08-09 14:24:03 +02:00
Matthew Dawson 619fc5e59b Make container layers captured using FS snapshots reproducible
When a Dockerfile command requires using the TakeSnapshotFS function,
the resulting layer has a random ordering of files.  This causes the
layer to have a non-deterministic hash defeating the reproducible flag.
Issue #710 appears to document this issue as well.

To fix, always sort the list of files to be added in scanFullFilesystem.
This avoids trying to sort the file list during execution, and takes
almost no time to complete.
2019-07-11 21:58:42 -04:00
Daisuke Taniwaki 1bf4421047 Fix parent directory permissions (#619)
* Add parent directories of adding files

* Add integration Dockerfile to test parent directory permissions

* Remove unnecessary helper method

* Use a file on the internet for integration Dockerfile
2019-03-19 12:40:15 -05:00
dlorenc fc43e218f0
Buffer layers to disk as they are created. (#428)
When building Docker images, layers were previously stored in memory.
This caused obvious issues when manipulating large layers, which could
cause Kaniko to crash.
2018-11-06 09:26:54 -06:00
Priya Wadhwa 13accbaf32 Add Key() to LayeredMap and Snapshotter
This will return a string representaiton of the current filesystem to be
used with caching.

Whenever a file is explictly added (via ADD or COPY), it will be stored
in "added" in the LayeredMap. The file will map to a hash created by
CacheHasher (which doesn't take into account mtime, since that will be
different with every build, making the cache useless)

Key() will returns a sha of the added files which will be used in
determining the overall cache key for a command.
2018-09-04 13:42:33 -07:00
Christie Wilson 2fe93f2911 No longer try to verify kaniko dir isn't snapshotted
This test had previously (before #231) been making a change to a file in
the kaniko dir, then checking that it isn't being snapshotted. This was
to test the whitelisting logic, which makes sure that changes to /kaniko
aren't included in images. However the test creates a temporary dir, so
the kaniko dir is actually in /tmp/<some temp dir>/kaniko, and
in #231 the logic was simplified to no longer have a special case for
tests. The test continued to pass because `MaybeAdd` noticed that the
kaniko file wasn't changing, and didn't add it. After changing this to
always add the files, it revealed that this was left behind by accident.

I also opened #307 to add integration test coverage for this logic.

I also marked `CheckErrorAndDeepEqual` as a helper function so that when
it fails, the line number reported is where that was called.
2018-08-23 18:23:46 -07:00
Christie Wilson 607af5f7a6 Always snapshot files in COPY and RUN commands
Kaniko uses mtime (as well as file contents and other attributes) to
determine if files have changed. COPY and ADD commands should _always_
update the mtime, because they actually overwrite the files. However it
turns out that the mtime can lag, so kaniko would sometimes add a new
layer when using COPY or ADD on a file, and sometimes would not. This
leads to a non-deterministic number of layers.

To fix this, we have updated the kaniko commands to be more
authoritative in declaring when they have changed a file (e.g. WORKDIR
will now only create the directory when it doesn't exist) and we will
trust those files and _always_ add them, instead of only adding them if
they haven't changed.

It is possible for RUN commands to also change the filesystem, in which
case kaniko has no choice but to look at the filesystem to determine
what has changed. For this case we have added a call to `sync` however
we still cannot guarantee that sometimes the mtime will not lag, causing the
number of layers to be non-deterministic. However when I tried to cause
this behaviour with the RUN command, I couldn't.

This changes the snapshotting logic a bit; before this change, the last
command of the last stage in a Dockerfile would always scan the whole
file system and ignore the files returned by the kaniko command. Instead
we will now trust those files and assume that the snapshotting
performed by previous commands will be adequate.

Docker itself seems to rely on the storage driver to determine when
files have changed and so doesn't have to deal with these problems
directly.

An alternative implementation would use `inotify` to track which files
have changed. However that would mean watching every file in the
filesystem, and adding new watches as files are added. Not only is there
a limit on the number of files that can be watched, but according to the
man pages a) this can take a significant amount of time b) there is
complication around when events arrive (e.g. by the time they arrive,
the files may have changed) and lastly c) events can be lost, which
would mean we'd run into this non-deterministic behaviour again anyway.

Fixes #251
2018-08-23 18:23:39 -07:00
priyawadhwa 31b7cd3732
Fix bug in copy command by refactoring whitelist checks (#231)
* Fixed bug

* WIP

* fix unit tests
2018-07-10 08:23:35 -07:00
Priya Wadhwa 54282e3e8c
Fix bug in snapshotting 2018-06-21 14:07:59 -07:00
Priya Wadhwa a211c1ec71
Make sure to snapshot parent directories of specific files for add/copy 2018-04-24 16:22:37 -07:00
Matt Rickard cff201dee6 org rename from GoogleCloudPlatform to GoogleContainerTools 2018-04-17 11:45:39 -07:00
Priya Wadhwa ec510a161b
change imports from k8s-container-builder to kaniko 2018-04-12 15:35:54 -07:00
Priya Wadhwa fad0d25aec
Add README and update name to kaniko 2018-04-02 14:00:15 -07:00
Priya Wadhwa 27b09f28be
Add config as point to ExecuteCommand, fix snapshots 2018-03-09 11:30:35 -08:00
Priya Wadhwa 75e7e47b76
Added integration test, minor changes to files 2018-03-08 11:49:56 -08:00
Priya Wadhwa 98826ef951
Changed /work-dir to /kbuild 2018-03-07 15:38:22 -08:00
Priya Wadhwa 3195b84c25
Fixed integration tests, changed directory to /work-dir 2018-03-06 15:25:04 -08:00
Priya Wadhwa 448e9dc3ce
Removed panic and added logging 2018-03-02 13:39:51 -08:00
Priya Wadhwa 43bad54292
Added snapshot package and tests 2018-02-28 11:05:57 -08:00