Commit Graph

594 Commits

Author SHA1 Message Date
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
priyawadhwa 9cc1d277f0
Merge pull request #311 from DerDackel/separate-insecure-from-tls-verify
Separate --insecure-skip-tls-verify flag into two separate flags
2018-08-30 16:16:40 -07:00
priyawadhwa deda0ea04d
Merge pull request #326 from priyawadhwa/fs-forward
Extract filesystem in order rather than in reverse
2018-08-30 10:49:13 -07:00
Priya Wadhwa 1db7fc2a61 Rebased 2018-08-30 10:16:08 -07:00
Priya Wadhwa e0130c5942 Remove extra symlink check 2018-08-30 10:13:06 -07:00
Sebastian Jackel 1a7de69f3e Rename DockerInsecure field to InsecurePush 2018-08-30 09:36:12 +02:00
Sebastian Jackel 3a58f20927 Added --insecure and --skip-tls-verify flag to README 2018-08-30 09:34:31 +02:00
Sebastian Jackel 4ba6148621 Implement separation between Insecure (HTTP) registry and skipping TLS verification into two separate command line parameters 2018-08-30 09:34:31 +02:00
priyawadhwa bb75c04618
Merge pull request #327 from priyawadhwa/logs
Configure logs to show colors
2018-08-29 17:39:40 -07:00
priyawadhwa 764681770c
Merge pull request #328 from priyawadhwa/timestamp
Updated created by time for built image
2018-08-29 17:33:30 -07:00
Priya Wadhwa 3dddb82bed Updated created by time for built image
Should fix #312
2018-08-29 16:56:53 -07:00
Priya Wadhwa 85393a60c2 Fixed unit tests 2018-08-29 16:11:03 -07:00
Priya Wadhwa 15db85e36a Configure logs to show colors 2018-08-29 16:08:09 -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
priyawadhwa 49f92980d5
Merge pull request #324 from priyawadhwa/cloudbuild
Build each kaniko image separately
2018-08-29 11:36:02 -07:00
Sharif Elgamal f5c03e7167
Merge pull request #323 from sharifelgamal/multitag
support multiple tags when writing to a tarfile
2018-08-29 11:15:10 -07:00
sharifelgamal 493344e438
support multiple tags when writing to a tarfile 2018-08-28 18:14:03 -07:00
Priya Wadhwa ef3f64bdf6 Build each kaniko image separately
I was seeing an error with our cloudbuild triggers where the tagged
:latest version of image wasn't the same as the :commit version, even
though it was created via 'docker tag image:commit image:latest'.

I'm not sure why this would be happening, but for now building each
image separately should hopefully fix this error.
2018-08-28 10:59:29 -07:00
priyawadhwa 3654ea4a02
Merge pull request #321 from daniel-harrison/master
Enable shared config for s3
2018-08-27 16:06:22 -07:00
Priya Wadhwa 935d322f1d Rebased on master 2018-08-27 14:18:24 -07:00
Priya Wadhwa 64a0b1d75f Added a KanikoStage type for each stage of a Dockerfile
I added a KanikoStage to hold each stage of the Dockerfile along with
information about each stage that would be useful later on.

The new KanikoStage type holds the stage itself, along with some
additional information:

1. FinalStage -- whether the current stage is the final stage
2. BaseImageStoredLocally/BaseImageIndex -- whether the base image for
this stage is stored locally, and if so what the index of the base image
is
3. SaveStage -- whether this stage needs to be saved for use in a future
stage

This is the first part of a larger refactor for building stages, which
will later make it easier to add layer caching.
2018-08-27 14:15:04 -07:00
priyawadhwa f1c68033af
Merge pull request #319 from priyawadhwa/bug
Snapshot only specific files for COPY
2018-08-27 14:00:20 -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
dlorenc a740b53e6d
Remove some constraints from our Gopkg.toml. (#318)
These are not required and make the builds of dependent programs harder.
2018-08-27 13:55:51 -05: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
Christie Wilson 216b14f79f
Merge pull request #289 from bobcatfish/copy_copy_copy
Always snapshot files in COPY and RUN commands
2018-08-24 17:04:29 -07:00
Christie Wilson 7f64037a8c Separate snapshotting of parent dirs from files
To make the logic a bit more clear, when snapshotting files, the
parent dirs are now snapshotted in a different loop from the files we
are actually trying to snapshot. Unfortunately this loop is nearly
duplicated but I did managed to group some fo the related logic
together:
- A function to check if the file should be snapshotted (e.g. isn't
whitelisted, etc.)
- Created a `Tar` type to handle some of the logic around tar-ing, e.g.
tracking hardlinks and stat-ing files before adding them

One side effect of this is that now when snapshoting the file system,
files will be stat-ed twice.
2018-08-24 16:34:59 -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 6dccd4ec4a Make it more clear the mtime issue is theoretical
Although we were able to reproduce this with the previous behaviour of
the COPY and ADD commands, we have fixed that issue and our attempts to
cause the issue to occur with RUN did not succeed, so it may be that in
practice this will never happen.
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 360390056c
Merge pull request #306 from priyawadhwa/refactor
Refactor command line arguments and the executor
2018-08-23 14:44:11 -07:00
Priya Wadhwa d867eadbb0 Review code comments; improved error messages for push 2018-08-23 14:27:13 -07:00
Priya Wadhwa cfa822f178 Refactor command line arguments and the executor
In this refactor I:

1. Created KanikoOptions to make it easier to pass around arguments
passed in through the command line
2. Reorganized executor.go by putting the logic for pushing the image in
a new file push.go
3. Made some error messages clearer
4. Fixed a mistake in the README for pushing to AWS
5. Marked the --bucket flag as hidden since we want people to use
--context instead, and marked an aws flag as hidden which is set in a
vendored directorya
2018-08-23 13:30:36 -07:00
priyawadhwa a776d18817
Merge pull request #305 from dlorenc/update
Update go-containerregistry.
2018-08-23 11:56:45 -07:00
dlorenc 6b3ab0d549 Update go-containerregistry. 2018-08-23 11:33:36 -07:00