Commit Graph

74 Commits

Author SHA1 Message Date
Priya Wadhwa b0b36ed85a Re-add support for .dockerignore file
This PR adds support for the dockerignore file. Previously when kaniko
had support for the dockerignore file, kaniko first went through the
build context and deleted files that were meant to be ignored. This
resulted in a really bad bug where files in user mounted volumes would
be deleted (my bad).

This time around, instead of modifying the build context at all, kaniko
will check if a file should be excluded when executing ADD/COPY
commands. If a file should be excluded (based on the .dockerignore) it
won't be copied over from the buildcontext and shouldn't end up in the
final image.

I also added a .dockerignore file and Dockerfile as an integration test,
which should fail if the dockerignore is not being processed correctly or if files aren't being excluded correctly.
Also, I removed all the integration testing from the previous version of the
dockerignore support.
2018-12-10 15:20:25 -08:00
priyawadhwa 0b7fa58ca2
Merge pull request #459 from aduong/symlinks
Overwrite existing dest when copying symlink and preserve link target
2018-11-30 09:28:26 -08:00
Priya Wadhwa edd873d1fe remove unnecessary filepath.Join since dest is always an absolute path 2018-11-19 15:07:56 -05:00
Adrian Duong f23cc32c42 Overwrite existing dest when copying symlink and preserve link target 2018-11-17 23:06:34 -08:00
Priya Wadhwa 9d67953ed3 Fix bug in extracting hardlinks
When we execute multistage builds, we store the fs of each intermediate
stage at /kaniko/<stage number> if it's used later in the build. This
created a bug when extracting hardlinks, because we weren't appending
the new directory to the link path.

So, if `/tmp/file1` and `/tmp/file2` were hardlinked, kaniko was trying
to link `/kaniko/0/tmp/file1` to `/tmp/file2` instead of
`/kaniko/0/tmp/file2`. This change will append the correct directory to
the link, and fixes #437 #362 #352 #342.
2018-11-16 16:18:49 -08:00
dlorenc 0c294138b8
Make snapshotting faster by using filepath.SkipDir. (#451)
filepath.Walk has a special error you can return from your walkFn
indicating it should skip directories. This change makes use of that
to skip whitelisted directories.
2018-11-14 17:44:38 -06:00
dlorenc 063663e17b
Skip unpacking the base FS if there are no run commands (or only cached ones). (#440)
This is the final part of an optimization that I've been refactoring towards for awhile.
If the Dockerfile consists of no RUN commands, or cached RUN commands, followed by metadata-only
operations, we can skip downloading and unpacking the base image.
2018-11-12 12:51:45 -06: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
priyawadhwa f4612404c4
Merge pull request #389 from peter-evans/fix-symlink-extraction
Fix symlink extraction
2018-10-18 10:21:23 -07:00
Deniz Zoeteman 129eb9b8a8
Change loglevel for copying files to debug (#303) 2018-10-12 16:16:48 +02:00
peter-evans 38e8dc2cdd Remove all at path to make way for new reg files and links 2018-10-11 15:33:25 +09:00
peter-evans 5695ebc3d5 Remove all at path to make way for new symlink 2018-10-11 09:28:55 +09:00
priyawadhwa 8f0d257134
Merge pull request #334 from peter-evans/fix-volume-cmd
Fix handling of the volume directive
2018-10-01 14:49:33 -07:00
dlorenc e1b0f7732e
Fixes a whitelist issue when untarring files in ADD commands. (#371)
* Fixes a whitelist issue when untarring files in ADD commands.

* Add go-cmp test tool.

* Make the integration test tolerate some file differences.
2018-09-28 11:42:07 -07:00
peter-evans b1e28ddb4f Fix handling of volume directive 2018-09-28 11:16:25 +09:00
xanonid 59cb0ebec9 Enable overwriting of links (solves #351) (#360)
* Enable overwriting of links (solves #351)

* add integration test to check extraction of images with replaced hardlinks

* Prevent following symlinks during extracting normal files

This fixes #359, #361, #362.
2018-09-26 07:14:35 -07:00
Priya Wadhwa c216fbf91b Add layer caching to kaniko
To add layer caching to kaniko, I added two flags: --cache and
--use-cache.

If --use-cache is set, then the cache will be used, and if --cache is
specified then that repo will be used to store cached layers. If --cache
isn't set, a cache will be inferred from the destination provided.

Currently, caching only works for RUN commands. Before executing the
command, kaniko checks if the cached layer exists. If it does, it pulls
it and extracts it. It then adds those files to the snapshotter and
append a layer to the config history.  If the cached layer does not exist, kaniko executes the command and
pushes the newly created layer to the cache.

All cached layers are tagged with a stable key, which is built based off
of:

1. The base image digest
2. The current state of the filesystem
3. The current command being run
4. The current config file (to account for metadata changes)

I also added two integration tests to make sure caching works

1. Dockerfile_test_cache runs 'date', which should be exactly the same
the second time the image is built
2. Dockerfile_test_cache_install makes sure apt-get install can be
reproduced
2018-09-13 18:32:53 -07:00
priyawadhwa c814466e15
Merge pull request #347 from priyawadhwa/amazon
Whitelist /etc/mtab
2018-09-12 16:08:12 -07:00
Priya Wadhwa ccb6259b06 More linting errors 2018-09-11 14:58:25 -07:00
Priya Wadhwa 63cecbff74 Whitelist /etc/mtab
While looking into #345, we were seeing the error:

Error: error building image: chmod /etc/mtab: operation not permitted

during extraction of `amazonlinux:1`. I looked into why kaniko couldn't
extract this file properly, and found that it already existed as a
symlink pointing to /proc/mounts, which returned an error when we tried
to run chmod on it.

Confusingly, in the image the /etc/mtab is a regular file, not a
symlink.

I can think of two ways to solve this problem:
  1. Whitelist /etc/mtab so that whatever already exists in the system
  is used
  2. Check if a regular file already exists, and hasn't been extracted yet,
  before extracting

I went with option 1 because for option 2 we'd have to keep a list of
all files that had been extracted in memory.
2018-09-10 17:06:09 -07:00
Priya Wadhwa 1513295103 Make sure paths are absolute before matching files to wildcard sources
The bug in #329 occurred because of a bug in matchSources, where the
filepath wasn't absolute, so the source "/kaniko-bug/*" wasn't being
matched to the file "kaniko-bug/test-file"

To fix this, I added logic for making filepaths absolute and added to
the unit test for the function to test that it works.
2018-08-31 11:57:20 -07:00
Priya Wadhwa e0130c5942 Remove extra symlink check 2018-08-30 10:13:06 -07:00
Priya Wadhwa 85393a60c2 Fixed unit tests 2018-08-29 16:11:03 -07:00
Priya Wadhwa 5bdb87e0e7 Extract filesystem in order rather than in reverse
Extracting the layers of the filesystem in order will make it easier to
extract cached layers and deal with hardlinks.

This PR implements extracting in order and adds an integration tests to
make sure hardlinks are extracted properly.

It also fixes two bugs I found when extracting symlinks:

1. We'd get a "file exists" error when trying to symlink to an existing
file with a whiteout later in the layer tarball
2. We'd get a "file exists" error when trying to create a symlink from a
file that was created in a prior layer (perhaps as a regular file or as
a symlink pointing to someting else)

To fix both of these, we resolve all symlinks in a layer at the end. I
also added logic to delete any existing paths before creating the
symlink.
2018-08-29 15:44:38 -07:00
Priya Wadhwa 7080a8dd69 Add specific files from tar archives to list of snapshotted filesa
I changed UnpackLocalTarArchive to return a list of files that were
extracted, so that the list of snapshotted files for ADD is more
accurate. Previously, we used to add all files in the extracted dir to
be snapshotted, but this could result in preexisting files being
snapshotted again.
2018-08-27 13:44:39 -07:00
Priya Wadhwa 9a93f5bad9 Snapshot only specific files for COPY
Before #289 was merged, when copying over directories for COPY kaniko
would get a list of all files at the destination specified and add them
to the list of files to be snapshotted. If the destination was root it
would add all files. This worked because the snapshotter made sure the
file had been changed before adding it to the layer.

After #289, we changed the logic to add all files snapshotted to a layer
without checking if the files had been changed. This created the bug in
got all the files at root and added them to the layer without checking
if they had been changed.

This change should fix this bug. Now, the CopyDir function returns a
list of files it copied over and only those files are added to the list
of files to be snapshotted.

Should fix #314
2018-08-27 11:39:00 -07:00
Priya Wadhwa d8ae5618af Get absolute path of file before checking whitelist
Issue 291 pointed out that symlink "../proc/self/mounts" in the fedora image wasn't being extracted properly and kaniko was erroring out.
This is because the file path wasn't absolute so kaniko wasn't recognizing it as a whitelisted path.
With this change, we first resolve a path to it's absolute path before checking the whitelist.
2018-08-17 18:29:11 -04:00
priyawadhwa 954b6129d6
Extract intermediate stages to filesystem (#266)
* WIP

* save and extract stage tarballs if there are dependencies
2018-08-02 09:40:24 -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
xanonid d411bd6daf Track file ownership and use file ownership from base images (#209)
* Track file ownership and use file ownership from base images

* Fix fs_util_test - use current uid/gid.
2018-06-22 15:11:02 -07:00
Priya Wadhwa 54282e3e8c
Fix bug in snapshotting 2018-06-21 14:07:59 -07:00
Jon Johnson 8b0a1a7689 dep update go-containerregistry 2018-06-03 00:59:34 +00:00
Priya Wadhwa e3f4dc479d
Move all files in executor image to /kaniko directory 2018-05-21 14:08:06 -07:00
Priya Wadhwa 577f448993
Make sure necessary files aren't deleted for multistage builds 2018-05-21 11:20:32 -07:00
Priya Wadhwa 6934f785c8
Pass in clone of buildargs for dockerfile parsing 2018-05-14 16:19:26 -07:00
Priya Wadhwa 282f8abbee
Merge master, refactor to work with ARG 2018-05-11 15:53:11 -07:00
Priya Wadhwa 347ce66a9b
Merged master, fixed merge conflict 2018-05-09 13:50:33 -07:00
Priya Wadhwa d040c89af6
Ignore symlinks during file extraction if link is whitelisted 2018-05-08 11:02:29 -07:00
Priya Wadhwa 7fbc21ec73
Merged master, fixed merge conflict 2018-05-07 09:14:17 -07:00
Priya Wadhwa 48688df7a6
Fixed merge conflicts, support multistage builds 2018-04-26 16:39:02 -07:00
Priya Wadhwa 904575d0cb
support multi stage builds 2018-04-26 15:40:41 -07:00
dlorenc cd5b744904
Switch from containers/image to go-containerregistry (#140)
* Vendor changes for go-containerregistry switch.

* Manual changes for go-containerregistry switch.

The biggest change is refactoring the tarball unpacking.

* Pull more of container-diff out.

* More vendor removals.

* More unit tests.
2018-04-25 19:21:05 -07:00
Priya Wadhwa 946b11b894
fix parent directory 2018-04-25 12:59:18 -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
Priya Wadhwa cf713fe0cd
fixed bug in copy 2018-04-23 18:13:27 -07:00
Priya Wadhwa 7dbc7a04a7
Support multi stage builds 2018-04-23 17:25:12 -07:00
Priya Wadhwa be38696c7d Updated unit tests after refactor 2018-04-19 20:39:29 -07:00
Priya Wadhwa 6054d7e653 Refactor copy and add
Refactor copy and add

Add/copy pass integration tests
2018-04-19 20:27:41 -07:00
Matt Rickard cff201dee6 org rename from GoogleCloudPlatform to GoogleContainerTools 2018-04-17 11:45:39 -07:00
Priya Wadhwa b47f682c80
Fix 'text file busy' error 2018-04-16 13:40:02 -07:00