Commit Graph

478 Commits

Author SHA1 Message Date
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
priyawadhwa 7eb691055e
Merge pull request #370 from vbehar/cleanup-flag
Add a new flag to cleanup the filesystem at the end
2018-09-28 10:27:29 -07:00
priyawadhwa 5f9f71dcf8
Merge pull request #369 from vbehar/whitelist-busybox
Whitelist /busybox in the debug image
2018-09-28 09:47:48 -07:00
dlorenc d904a4c872
Add a benchmark package to store and monitor timings. (#367) 2018-09-28 09:13:17 -07:00
Vincent Behar d10e3f5b74
Whitelist /busybox in the debug image
In the debug image, declare /busybox as a volume so that it is automatically whitelisted, because we don't want to delete it when building multi-stages images.

FYI this is required when using Jenkins, because we need to use the debug kaniko image to be able to start the container "doing nothing" (with /busybox/cat) before building (by executing /kaniko/executor directly inside the container)
See https://issues.jenkins-ci.org/browse/JENKINS-52576
2018-09-28 10:55:08 +02:00
Vincent Behar 49ab8e4979
Add a new flag to cleanup the filesystem at the end
Currently, kaniko can only build a single image per container run, because the filesystem is full of the content of the first image.
When running kaniko in Jenkins, where we need to start the container "doing nothing" first (using the debug kaniko container), and then exec /kaniko/executor, this is a limitation because it means that if we want to build multiple images, we need to start multiple containers - see https://groups.google.com/forum/#!topic/kaniko-users/_7LivHdMdy0 for more details

A solution to fix this issue is to add a new flag to cleanup the filesystem at the end - the same way it is done between stages when building a multi-stages image. This way, the same (debug) container can be used to build multiple images.
2018-09-28 10:25:33 +02:00
Sharif Elgamal 49184c2114 set default HOME env properly (#341)
* set default HOME env properly

* set HOME to / if user is set by uid

* fix test

* continue to skip user_run test

* fix unit test to match new functionality
2018-09-27 07:31:51 -07:00
priyawadhwa 1a13c81be8
Merge pull request #348 from priyawadhwa/entrypoint
Review config for cmd/entrypoint after building a stage
2018-09-26 21:26:42 +01: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
priyawadhwa bb0df68e50
Merge pull request #363 from priyawadhwa/exists
Only return stdout when running commands for integration tests
2018-09-25 21:56:03 +01:00
priyawadhwa e7675e0569
Merge pull request #364 from priyawadhwa/readme
Update README to add information about layer caching
2018-09-25 21:52:14 +01:00
Priya Wadhwa cd2fedf9d2 Update README to add information about layer caching 2018-09-25 10:25:35 -07:00
Priya Wadhwa 6c39f29081 Only return stdout when running commands for integration tests
When running container-diff in integration tests, both stdout and stderr were being returned
and unmarshalled into the container-diff json object. If container-diff
was giving any error messages (such as, if it didn't have permissions to
extract a file), this would fail even if ultimately no
differences between the filesystems existed.

I updated the RunCommands to only return stdout and print stderr if the
command fails.
2018-09-25 10:05:11 -07:00
priyawadhwa 57ede49dac
Merge pull request #353 from priyawadhwa/cache
Add layer caching to kaniko
2018-09-24 21:40:40 +01:00
Priya Wadhwa e2ca1152f4 Rename flags and default caching to false
Rename --use-cache to --cache, and --cache to --cache-repo to clarify
what the flags are used for. Default caching to false.
2018-09-24 13:18:42 -07:00
Priya Wadhwa 1e1c98229c Merged master, fixed merge conflict 2018-09-17 11:12:29 +01:00
Priya Wadhwa cd1b957e43 Address code review comments; review unnecessary error check 2018-09-17 11:11:51 +01:00
Priya Wadhwa 177bd4f40e Fix typo and update comments 2018-09-17 11:05:57 +01:00
priyawadhwa 8fb220b19b
Merge pull request #356 from priyawadhwa/error
Suppress usage upon Run error
2018-09-14 14:29:31 -07:00
Priya Wadhwa 49d7c7c0ee Suppress usage upon Run error
I changed RunE to Run so that usage wouldn't show upon error. Usage will
still show if PersistentPreRunE fails, which makes sense since those
functions check to make sure arguments passed in are valid.

Also changed logging of multi arg flags to Debugf so that output would
be cleaner.
2018-09-14 12:15:31 -07:00
Priya Wadhwa f7ba67ea25 Specify cache key to differentiate cache layers 2018-09-14 09:53:03 -07:00
Priya Wadhwa eb7194a165 Fix linting errors 2018-09-13 22:06:38 -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
Tejal Desai 14f3c81b79
Merge pull request #343 from priyawadhwa/stagebuilder
Refactor build into stageBuilder type
2018-09-12 21:35:24 -07:00
Priya Wadhwa 7a6dfb6d8b Removed incorrect FS extraction from earlier merge with master, and fixed linting errors 2018-09-12 17:10:03 -07:00
Priya Wadhwa da6f099820 Merge branch 'master' of github.com:GoogleContainerTools/kaniko into entrypoint 2018-09-12 16:45:25 -07:00
Priya Wadhwa ee9aa954ac merged master, fixed conflicts 2018-09-12 16:43:32 -07:00
Priya Wadhwa bf72328611 Addressed code review comment, removed stuttering variable names 2018-09-12 16:36:53 -07:00
priyawadhwa c814466e15
Merge pull request #347 from priyawadhwa/amazon
Whitelist /etc/mtab
2018-09-12 16:08:12 -07:00
priyawadhwa ae39c0fa8b
Merge pull request #349 from priyawadhwa/gometalinter
Replace gometalinter with GolangCI-Lint
2018-09-11 16:41:58 -07:00
Priya Wadhwa 7635421ae9 Add t.Helper() call to checkLayers for better error logging 2018-09-11 16:24:21 -07:00
Priya Wadhwa ccb6259b06 More linting errors 2018-09-11 14:58:25 -07:00
Priya Wadhwa 99ab68e7f4 Replace gometalinter with GolangCI-Lint
gometalinter is broken @ HEAD, and I looked into why that was. During
that process, I remembered that we took the linting scripts from
skaffold, and found that in skaffold gometalinter was replaced with
GolangCI-Lint:

https://github.com/GoogleContainerTools/skaffold/pull/619

The change made linting in skaffold faster, so I figured instead of
fixing gometalinter it made more sense to remove it and replace it with
GolangCI-Lint for kaniko as well.
2018-09-11 13:30:42 -07:00
Priya Wadhwa d923d5ef02 Fix integration test 2018-09-11 10:07:54 -07:00
Tejal Desai 06defa6552
Merge pull request #337 from priyawadhwa/hasher
Add Key() to LayeredMap and Snapshotter
2018-09-11 09:29:50 -07:00
Priya Wadhwa c13f6e84ed Fixed unit test 2018-09-10 18:20:00 -07:00
Priya Wadhwa 5d2d2829d0 Review config for cmd/entrypoint after building a stage
As mentioned in #346, if only ENTRYPOINT is set in a stage then any
CMD inherited from a parent should be cleared.

If both entrypoint and cmd are set then nothing should change.

I added a function and unit test to review the config file after building a stage
which clears out config.Cmd if ENTRYPOINT was declared but CMD wasn't.

I also added an integration test to make sure this works, which should
be tested by the preexisting container-diff --metadata test.
2018-09-10 18:15:51 -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 d9022dd7de Refactor build into stageBuilder type
Refactoring builds by stage will make it easier to generate cache keys
for layers, since the stageBuilder type will contain everything required
to generate the key:

1. Base image with digest
2. Config file
3. Snapshotter (which will provide a key for the filesystem)
4. The current command (which will be passed in)
2018-09-07 17:17:32 -07:00
priyawadhwa 4dc34343b6
Merge pull request #320 from priyawadhwa/stages
Added a KanikoStage type for each stage of a Dockerfile
2018-09-07 16:19:40 -07:00
Priya Wadhwa 80a449f541 code review comments 2018-09-07 16:03:56 -07:00
priyawadhwa 637f14e6ed
Merge pull request #336 from priyawadhwa/string
Add CacheCommand to DockerCommand interface
2018-09-07 15:32:27 -07:00
priyawadhwa 7a7d544916
Merge pull request #340 from GoogleContainerTools/priyawadhwa-bug-template
Update issue templates
2018-09-05 10:51:19 -07:00
priyawadhwa 31647f8687 Update issue templates
Add issue template for kaniko bugs. Should fix #338
2018-09-04 14:59:05 -07:00
Priya Wadhwa e300101579 Fix linting error 2018-09-04 13:50:57 -07: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
Priya Wadhwa 4f3ab61b96 Add CacheCommand to DockerCommand interface
CacheCommand returns true if the command should be cached. Currently,
it's only true for RUN but can be added to ADD/COPY later on (these are
different since the contents of files for ADD/COPY need to be included
in the cache key generation).

I also changed CreatedBy to String so that we can log each command
before cache extraction or regular execution takes place.
2018-09-04 13:16:05 -07:00
priyawadhwa 2e10d2761c
Merge pull request #330 from priyawadhwa/bug
Make sure paths are absolute before matching files to wildcard sources
2018-08-31 15:10:25 -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 0636fe6040 Merge branch 'master' of github.com:GoogleContainerTools/kaniko into stages 2018-08-30 16:17:44 -07:00