Commit Graph

168 Commits

Author SHA1 Message Date
Tejal Desai f1f7297478 fix tests 2020-01-22 11:47:10 -08:00
Tejal Desai da7e9928e4 Fix Symlinks not being copies across stages 2020-01-22 11:47:10 -08:00
Tejal Desai d362359314
Merge pull request #981 from cvgw/u/cgwippern/fix-issue-940
Fix #940 set modtime when extracting
2020-01-21 09:59:22 -08:00
Cole Wippern 4e8bdb3947 Fix #940 set modtime when extracting
Certain utilities like Apt depend on modtime
for certain files. Kaniko was not setting modtime when
extracting files and so this broke things like apt.

Kaniko now sets the file mod time to the value from the tar
header.
2020-01-20 09:11:44 -08:00
Cole Wippern 876f24b0c9 update caching run and copy extracted files
Update caching run and copy commands to use the new
GetFSFromLayers method and include the whiteout option so that
whiteout files are extracted and included in extractedFiles
2020-01-17 14:19:58 -08:00
Cole Wippern 71aed35094 GetFSFromLayers
* add util.GetFSFromLayers
* GetFSFromImage delegates to GetFSFromLayers
* add FSOpts and FSConfig for GetFSFromLayers
* add tests for GetFSFromLayers
* add gomock for test support
* add mock_v1 for layers
2020-01-17 13:36:23 -08:00
Logan.Price 6a35a84034 fix: update unTar function to actually extract and save the contents of an achieve 2019-12-21 15:42:00 -08:00
Prashant Arya 85f1a5db00 Merge branch 'master' of https://github.com/GoogleContainerTools/kaniko into log 2019-12-19 03:20:56 +00:00
Cole Wippern 2aa481c15e add unit tests for caching run and copy 2019-12-10 09:29:10 -08:00
poy 0a2f2957ec when copying, skip files with the same name
When using the COPY command, if the source and destination have the same
the file should be skipped rather than copied. This is to prevent the
file from being overwritten and therefore producing an empty file.

fixes #904
2019-12-08 00:57:27 -07:00
Prashant Arya 857715012f changing log level 2019-11-26 17:52:11 +00:00
Cole Wippern 2c13842451 Resolve symlink paths 2019-11-15 11:23:15 -08:00
Tejal Desai 334f0c70d6 fix golint 2019-11-07 15:11:29 -08:00
Don McCasland 5716c44ab8
Merge branch 'master' into bug-742-2 2019-11-04 09:25:25 -08:00
Tejal Desai c5bc179c85
Merge pull request #816 from yangtaokm/azure-blobstorage-https
[WIP] Add support to download context file from Azure Blob Storage
2019-10-25 10:51:50 -07:00
yangtaokm aa881d59cb fix gofmt 2019-10-22 17:10:08 +08:00
yangtaokm 45c43a2c89 refactory the code and add CreateTargetTarfile in fs_util.go 2019-10-22 16:44:51 +08:00
Prashant fa162e3005 changing debug to trace 2019-10-18 19:03:11 +05:30
Don McCasland 27020f23b9
Resolving comments 2019-10-08 12:19:20 -07:00
Don McCasland 4e1639c030
Addressing review comments 2019-10-07 10:46:28 -07:00
Tejal Desai 529bc4f20e
Merge pull request #805 from tejal29/fix_720
add debug level info what is the layer type
2019-10-04 16:19:49 -07:00
Tejal Desai 1a88d7ae9c better logging 2019-10-04 16:04:12 -07:00
Tejal Desai 3ad9255806 add debug level info what is the layer type 2019-10-04 15:51:05 -07:00
Tejal Desai 1c821d050c
Merge pull request #796 from prary/version
Kaniko version
2019-10-04 14:32:14 -07:00
Tejal Desai 9eb4a1c1ff
Merge pull request #801 from victornoel/776-dockerignore-relative
Support Dockerfile.dockerignore
2019-10-04 01:56:40 -07:00
Tejal Desai 865d49c631
Merge pull request #694 from orisano/feat-optimize-build
feat: optimize build
2019-10-04 00:51:23 -07:00
Prashant f9424d43e7 fixing lint and minor fix 2019-10-03 21:29:40 +05:30
Victor Noel db12a77e6c Fix #776 2019-10-03 17:53:14 +02:00
Don McCasland e58ee0967a
Fixing logic for Copy command. The problem was not that tar files were being unpacked in wrong order. The problem was that the COPY command requires the FS to be unpacked before it does its work. 2019-09-26 11:29:53 -07:00
jonjohnsonjr 51734fc3a3
Merge pull request #765 from Onlinehead/fix/filesystem-delete-fix
Fix SIGSEGV on file system deletion while building
2019-09-25 11:47:35 -07:00
Антон Костенко a21129f889 Fix typo and run go fmt over fs_util 2019-09-18 10:43:26 +02:00
Nao YONASHIRO 02d1ce5e1b feat: optimize HasFilepathPrefix 2019-09-18 17:19:15 +09:00
Don McCasland 1bb5a41d7d
Fixing lint issues. Adding tests for COPY command. Fixing issue with copying files out of snapshots 2019-09-16 10:48:31 -07:00
Антон Костенко a1cc42bdb7 Fix https://github.com/GoogleContainerTools/kaniko/issues/756 2019-09-10 00:44:27 +02:00
xanonid 1fa2527a7b Adapt tests such that expected paths do not contain a leading / 2019-08-09 14:24:03 +02:00
Taylor Barrella 3422d5572a Misc. small changes/refactoring (#712) 2019-07-23 15:10:22 -07:00
Johannes 'fish' Ziemke 8c732f6f52 Fix kaniko caching (#639)
* Revert "Change cache key calculation to be more reproducible. (#525)"

This reverts commit 1ffae47fdd.

* Add logging of composition key back

* Do not include build args in cache key

This should be save, given that the commands will have the args included
when the cache key gets built.
2019-05-10 09:57:03 -05:00
Daisuke Taniwaki 28bfb75a31 Fix file mode bug (#618)
* Fix file mode

* Add Dockerfile for special file permission test
2019-03-18 13:28:24 -05:00
dlorenc 877abd30ed
Refactor whitelist handling. (#559)
Also speed up stage deletion.
2019-02-13 11:17:56 -06:00
dlorenc 9047ccf7cc
This fixes a bug in the interaction between volumes in base images (#555)
and our snapshot optimizations.

If a previous base image has a volume, the directory is added to the
list of files to snapshot. That directory may not actually exist in the image.
2019-02-08 14:40:37 -06:00
dlorenc e14b660947
Fix a bug in volume handling for multi-stage images. (#554)
We were previously not resetting the whitelist between stages, this caused issues with volumes.
2019-02-07 09:01:49 -06:00
dlorenc 1ffae47fdd
Change cache key calculation to be more reproducible. (#525)
Before we were using the full image digest, but that contains a timestamp. Now
we only use the layers themselves and the image config (env vars, etc.).

Also fix a bug in unpacking the layers themselves. mtimes can change during unpacking,
so set them all once at the end.
2019-01-23 13:46:12 -06:00
Priya Wadhwa 7fd164deab Only parse .dockerignore once 2018-12-11 13:31:51 -08:00
Priya Wadhwa 9b01772cde Add logging 2018-12-11 12:44:23 -08:00
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
Priya Wadhwa 52c5759fc4
create list of build files 2018-04-16 11:08:40 -07:00
Priya Wadhwa c7bcc673fc
allow snapshot of kaniko certs so kaniko can build kaniko 2018-04-16 10:43:01 -07:00
priyawadhwa 0ddc2115a5
Merge pull request #78 from priyawadhwa/trigger
kaniko build trigger
2018-04-16 10:21:21 -07:00
priyawadhwa cebb4031b3 copy symlinks (#90) 2018-04-14 08:00:20 -07:00
Priya Wadhwa ec510a161b
change imports from k8s-container-builder to kaniko 2018-04-12 15:35:54 -07:00
Priya Wadhwa 954b1382d2
change k8s to kaniko 2018-04-12 15:30:32 -07:00