docker add cache when git checkout same file -
i need checkout project in ci server build image reusing docker cache.
docker add together not utilize cache when checkout same file.
i in git branch a execute docker build -t somename . utilize docker cache normally, if go branch b via git checkout b, nothing, go branch a via git checkout a , run 1 time again docker build -t somename . docker cache using before first add.
here example:
dockerfile
# docker-version 0.10.0 myregistry:5000/ruby:2.1.2-1 maintainer me # gem sources run gem source -r https://rubygems.org/ run gem source -a http://gems.mydomain # never install ruby gem docs run echo "gem: --no-rdoc --no-ri" >> ~/.gemrc # gems install run mkdir /foo workdir /foo run gem install bundler add together gemfile /foo/gemfile run bundle install # expose ports expose 8080 log build
sending build context docker daemon 19.54 mb sending build context docker daemon step 0 : myregistry:5000/ruby:2.1.2-1 ---> 9ce683a713b4 step 1 : maintainer me ---> using cache ---> 8f54114fd2e7 step 2 : run gem source -r https://rubygems.org/ ---> using cache ---> f58a08708863 step 3 : run gem source -a http://gems.mydomain ---> using cache ---> 3e69e17c5954 step 4 : run echo "gem: --no-rdoc --no-ri" >> ~/.gemrc ---> using cache ---> 1edb37962dd4 step 5 : run mkdir /foo ---> running in 3d3441c34ee3 ---> aeb90f00bc9b removing intermediate container 3d3441c34ee3 step 6 : workdir /foo ---> running in 84b881d8f621 ---> 10e1d8984458 removing intermediate container 84b881d8f621 step 7 : run gem install bundler ---> running in 31e98523ce46 installed bundler-1.6.2 1 gem installed ---> 84d5195ab831 removing intermediate container 31e98523ce46 step 8 : add together gemfile /foo/gemfile ---> 3e5f2675ee22 removing intermediate container c90e8be5ea17 step 9 : run bundle install ---> running in ac0e83e5eebb fetching gem metadata http://gems.mydomain/...... fetching additional metadata http://gems.mydomain/.. resolving dependencies... installing rake 10.3.2 installing i18n 0.6.9 installing multi_json 1.10.1 . . . installing railties 3.2.19 installing responders 0.9.3 using bundler 1.6.2 bundle complete! utilize `bundle show [gemname]` see bundled gem installed. ---> 19beae703adb removing intermediate container ac0e83e5eebb step 10 : expose 8080 ---> running in 1b1e55d349e5 ---> 32405bdac6d1 removing intermediate container 1b1e55d349e5 built 32405bdac6d1 git checkout b
git checkout a
docker build -t somename .
second build log
sending build context docker daemon 19.52 mb sending build context docker daemon step 0 : myregistry:5000/ruby:2.1.2-1 ---> 9ce683a713b4 step 1 : maintainer me ---> using cache ---> 8f54114fd2e7 step 2 : run gem source -r https://rubygems.org/ ---> using cache ---> f58a08708863 step 3 : run gem source -a http://gems.mydomain ---> using cache ---> 3e69e17c5954 step 4 : run echo "gem: --no-rdoc --no-ri" >> ~/.gemrc ---> using cache ---> 1edb37962dd4 step 5 : run mkdir /foo ---> using cache ---> aeb90f00bc9b step 6 : workdir /foo ---> using cache ---> 10e1d8984458 step 7 : run gem install bundler ---> using cache ---> 84d5195ab831 step 8 : add together gemfile /foo/gemfile ---> 4977e35c80f7 removing intermediate container bd59cc0d5e51 step 9 : run bundle install ---> running in 6ff16f32e94a fetching gem metadata http://gems.mydomain/...... fetching additional metadata http://gems.mydomain/.. resolving dependencies... installing rake 10.3.2 installing i18n 0.6.9 installing multi_json 1.10.1 . . . installing railties 3.2.19 installing responders 0.9.3 using bundler 1.6.2 bundle complete! utilize `bundle show [gemname]` see bundled gem installed. ---> d9332f9035c3 removing intermediate container 6ff16f32e94a step 10 : expose 8080 ---> running in b20252a00160 ---> 4d9932882e06 removing intermediate container b20252a00160 built 4d9932882e06
docker invalidates docker build cache when file's mtime value has changed, , git not track file mtime values. cache invalidation shows in other situations too, in continuous integration or build environments involving docker, git , branches.
i have been using "touch" target in makefile run prior asking docker build container:
touch: @echo "reset timestamps on git working directory files..." find ./ | grep -v .git | xargs touch -t 200001010000.00 next, run make touch prior docker build or docker-based "build" target in same makefile...
another alternative setup git hook modifies mtime values automatically: https://git.wiki.kernel.org/index.php/examplescripts#setting_the_timestamps_of_the_files_to_the_commit_timestamp_of_the_commit_which_last_touched_them
another possible solution fork docker , remove mtime definition of caches: https://github.com/docker/docker/blob/master/pkg/tarsum/tarsum.go
note: of docker 1.8, mtime no longer taken business relationship when invalidating cache. pull request #12031 updated behavior
git docker
No comments:
Post a Comment