From a1a3fdc1b54baf62f234ddc9dac4906e30eb5d11 Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Thu, 18 Jun 2026 17:16:08 +0200 Subject: kolla-build: fix build-date LABEL invalidating Docker layer cache The build-date label was rendered into a LABEL instruction on line 3 of every Dockerfile template, immediately after FROM. Because Docker invalidates the cache for a changed instruction and all subsequent layers, a date change caused a full rebuild of every image on each new calendar day, even when nothing else had changed. Fix this by removing build-date from the Dockerfile templates and applying it as a --label argument at build time via image.labels. Labels passed on the build command line are not part of the Dockerfile cache key, so the date is still recorded in the image metadata without affecting layer caching. Change-Id: I8ef0d85bab1a999a4d09f7cbf0c088ca00fdcf77 Signed-off-by: Michal Nasiadka --- kolla/image/kolla_worker.py | 4 ---- kolla/image/tasks.py | 1 + kolla/tests/test_build.py | 2 ++ 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'kolla') diff --git a/kolla/image/kolla_worker.py b/kolla/image/kolla_worker.py index b60f0558f..1c704d1cf 100644 --- a/kolla/image/kolla_worker.py +++ b/kolla/image/kolla_worker.py @@ -362,9 +362,6 @@ class KollaWorker(object): for path in self.docker_build_paths: template_name = "Dockerfile.j2" image_name = path.split("/")[-1] - ts = time.time() - build_date = datetime.datetime.fromtimestamp(ts).strftime( - '%Y%m%d') values = {'base_distro': self.base, 'base_image': self.conf.base_image, 'base_distro_tag': self.base_tag, @@ -390,7 +387,6 @@ class KollaWorker(object): 'users': self.get_users(), 'distro_package_manager': self.distro_package_manager, 'rpm_setup': self.rpm_setup, - 'build_date': build_date, 'clean_package_cache': self.clean_package_cache, 'patches_path': self.patches_path} env = jinja2.sandbox.SandboxedEnvironment( diff --git a/kolla/image/tasks.py b/kolla/image/tasks.py index 757197ef4..93ba91835 100644 --- a/kolla/image/tasks.py +++ b/kolla/image/tasks.py @@ -379,6 +379,7 @@ class BuildTask(EngineTask): image.status = Status.BUILDING image.start = datetime.datetime.now() + image.labels['build-date'] = image.start.strftime('%Y%m%d') self.logger.info('Building started at %s' % image.start) if image.source and 'source' in image.source: diff --git a/kolla/tests/test_build.py b/kolla/tests/test_build.py index e072860ab..e4e4d2839 100644 --- a/kolla/tests/test_build.py +++ b/kolla/tests/test_build.py @@ -82,6 +82,8 @@ class TasksTest(base.TestCase): # Existing tests exercise the docker-py SDK path; disable BuildKit so # they are not routed through _build_buildkit. self.conf.set_override('buildkit', False) + # Mock build-date + self.build_kwargs['labels'] = {'build-date': mock.ANY} @mock.patch.dict(os.environ, clear=True) @mock.patch(engine_client) -- cgit v1.2.3