kaniko/integration/dockerfiles
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
..
Dockerfile_onbuild_base Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_add fix add command bug when adding remote URLs (#277) 2018-08-07 17:10:27 -07:00
Dockerfile_test_copy Don't copy same files twice in copy integration tests (#273) 2018-08-03 10:01:29 -07:00
Dockerfile_test_copy_bucket Don't copy same files twice in copy integration tests (#273) 2018-08-03 10:01:29 -07:00
Dockerfile_test_copy_reproducible Don't copy same files twice in copy integration tests (#273) 2018-08-03 10:01:29 -07:00
Dockerfile_test_copy_same_file_many_times Always snapshot files in COPY and RUN commands 2018-08-23 18:23:39 -07:00
Dockerfile_test_daemons reproduced 247 with integration test 2018-07-26 11:16:26 -07:00
Dockerfile_test_env Environment variables with multiple '=' are not parsed correctly (#278) 2018-08-07 10:22:48 -07:00
Dockerfile_test_expose Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_extract_fs Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_label Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_metadata Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_multistage Get absolute path of file before checking whitelist 2018-08-17 18:29:11 -04:00
Dockerfile_test_mv_add Only add whiteout files once (#270) 2018-08-01 17:27:20 -07:00
Dockerfile_test_onbuild Integration test refactoring (#126) 2018-05-15 13:42:35 -07:00
Dockerfile_test_registry Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_run Set default home value (#281) 2018-08-10 12:58:07 -07:00
Dockerfile_test_run_2 Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_scratch Resolve env replacement for FROM command 2018-06-04 11:51:33 -07:00
Dockerfile_test_target Add --target flag for multistage builds (#255) 2018-07-30 09:43:23 -07:00
Dockerfile_test_user_run Set default home value (#281) 2018-08-10 12:58:07 -07:00
Dockerfile_test_volume Fully qualify images in dockerfile tests (#257) 2018-07-25 17:56:17 -07:00
Dockerfile_test_workdir Integration test refactoring (#126) 2018-05-15 13:42:35 -07:00