diff options
| author | Sam Yaple <sam@yaple.net> | 2015-08-20 14:24:58 +0000 |
|---|---|---|
| committer | Sam Yaple <sam@yaple.net> | 2015-08-20 15:35:28 +0000 |
| commit | 49a9fba23ee5440fb3bc2bfadc0714a311f981e1 (patch) | |
| tree | d7fc1298a735cdcadbe500d7335004c62e2cc1e6 | |
| parent | a760549e78d2a36b2684dc75f521b5d05bb501b2 (diff) | |
| download | kolla-49a9fba23ee5440fb3bc2bfadc0714a311f981e1.tar.gz kolla-49a9fba23ee5440fb3bc2bfadc0714a311f981e1.zip | |
Allow Docker to make better use of cache
Docker cache takes into account things like filesize, hash of file,
and even timestamp and access times when determining whether to use
the cache or not. This modifies the build script to adjust all the
timestamps to 0 epoch. Since we dont care about timestamps this allows
us to make far better use of the cache, including when downloading and
creating tarballs for source builds.
Change-Id: Id4287cf1fcaa2de63feaab9e6f4ebbd4defdb768
Partially-Implements: blueprint build-script
| -rwxr-xr-x | tools/build.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/build.py b/tools/build.py index 89cffc061..63477a148 100755 --- a/tools/build.py +++ b/tools/build.py @@ -80,6 +80,9 @@ class WorkerThread(Thread): 'Failed to download tarball: status_code {}'.format( r.status_code)) + # Set time on destination tarball to epoch 0 + os.utime(os.path.join(dest_dir, source['dest']), (0, 0)) + def builder(self, image): LOG.info('Processing: {}'.format(image['name'])) image['status'] = "building" @@ -204,6 +207,14 @@ class KollaWorker(object): shutil.copytree(self.images_dir, self.working_dir) LOG.debug('Created working dir: {}'.format(self.working_dir)) + def set_time(self): + for root, dirs, files in os.walk(self.working_dir): + for file_ in files: + os.utime(os.path.join(root, file_), (0, 0)) + for dir_ in dirs: + os.utime(os.path.join(root, dir_), (0, 0)) + LOG.debug('Set atime and mtime to 0 for all content in working dir') + def createDockerfiles(self): for path in self.docker_build_paths: template_name = "Dockerfile.j2" @@ -390,6 +401,10 @@ def main(): if args['template']: kolla.createDockerfiles() + # We set the atime and mtime to 0 epoch to preserve allow the Docker cache + # to work like we want. A different size or hash will still force a rebuild + kolla.set_time() + pools = kolla.buildQueues() # Returns a list of Queues for us to loop through |
