aboutsummaryrefslogtreecommitdiff
path: root/kolla
diff options
context:
space:
mode:
authorMichal Arbet <michal.arbet@ultimum.io>2022-02-15 13:50:59 +0100
committerDr. Jens Harbott <harbott@osism.tech>2024-11-15 08:04:30 +0000
commit11f65c6c1d3bfd6a12f8e71d778d46d635010449 (patch)
tree8e223ecd5f90c5142cdb70b88f4e2400136fcd9d /kolla
parent36c12676ff185f524a7f4d2f2f4c70b5d60462b4 (diff)
downloadkolla-11f65c6c1d3bfd6a12f8e71d778d46d635010449.tar.gz
kolla-11f65c6c1d3bfd6a12f8e71d778d46d635010449.zip
Add mechanism for patching files in containers
This patch adds a way to patch files in a Docker image built by Kolla. This is very useful for several reasons, specifically: - Custom modifications - The stable branch of some library has a fix but no pip package has been released - Eliminates the need to package your own pip packages - Eliminates the need to invent your own versioning to prevent upstream versioning - Eliminates the need to manage a pip server - In other words, it eliminates the need to get a wheel into the image and install it manually using any method not previously mentioned It is also highly desirable because, although Kolla can replace the source for a service with a custom URL for a tarball or its own Git repo, it cannot do this for dependencies pulled from pip. I would also like to point out that this is a feature with its own code path and works only if the user "inserts" a patch into the folder patches/docker-image/something.patch and creates an analogous series file for patch source code. Simply said, this code will never interfere with the upstream build process since this feature is not intended for use in upstream. It is rather meant for downstream users who know what they are doing. Now they just have an option to patch their images. Everything works on all layers of the Docker image and stores a report of applied patches which can then be seen in /etc. This mechanism is similar as debian patch quilt. Change-Id: I61d0790c5d4d070b7ea9e8c99c0a76ff5d22bf9d
Diffstat (limited to 'kolla')
-rw-r--r--kolla/common/config.py2
-rw-r--r--kolla/image/build.py1
-rw-r--r--kolla/image/kolla_worker.py33
3 files changed, 35 insertions, 1 deletions
diff --git a/kolla/common/config.py b/kolla/common/config.py
index 4a6fd4903..3075052ad 100644
--- a/kolla/common/config.py
+++ b/kolla/common/config.py
@@ -178,6 +178,8 @@ _CLI_OPTS = [
help='The network mode for Docker build. Example: host'),
cfg.BoolOpt('cache', default=True,
help='Use the container engine cache when building'),
+ cfg.StrOpt('patches-path', default=None,
+ help='The path where patch files to be applied are located'),
cfg.StrOpt('platform', default=None,
help=('The platform to use for a cross-compile build. Should '
'be set in conjunction with "--base-arch" argument. '
diff --git a/kolla/image/build.py b/kolla/image/build.py
index 88189e2f7..9b6571d36 100644
--- a/kolla/image/build.py
+++ b/kolla/image/build.py
@@ -140,6 +140,7 @@ def run_build():
kolla.setup_working_dir()
kolla.find_dockerfiles()
kolla.create_dockerfiles()
+ kolla.create_patch_files()
kolla.build_image_list()
kolla.find_parents()
kolla.filter_images()
diff --git a/kolla/image/kolla_worker.py b/kolla/image/kolla_worker.py
index 1e3f4d861..798c8eaa7 100644
--- a/kolla/image/kolla_worker.py
+++ b/kolla/image/kolla_worker.py
@@ -141,6 +141,7 @@ class KollaWorker(object):
self.image_statuses_unbuildable = dict()
self.image_statuses_allowed_to_fail = dict()
self.maintainer = conf.maintainer
+ self.patches_path = conf.patches_path
try:
self.engine_client = engine.getEngineClient(self.conf)
@@ -322,7 +323,8 @@ class KollaWorker(object):
'distro_package_manager': self.distro_package_manager,
'rpm_setup': self.rpm_setup,
'build_date': build_date,
- 'clean_package_cache': self.clean_package_cache}
+ 'clean_package_cache': self.clean_package_cache,
+ 'patches_path': self.patches_path}
env = jinja2.Environment( # nosec: not used to render HTML
loader=jinja2.FileSystemLoader(self.working_dir))
env.filters.update(self._get_filters())
@@ -349,6 +351,35 @@ class KollaWorker(object):
f.write(content)
LOG.debug("Wrote it to %s", content_path)
+ def create_patch_files(self):
+ for path in self.docker_build_paths:
+ image_name = os.path.basename(path)
+ src_patch_folder = os.path.join(self.patches_path, image_name) if \
+ self.patches_path and os.path.isdir(self.patches_path) \
+ else None
+ dest_patch_folder = os.path.join(path, "patches")
+ os.makedirs(dest_patch_folder, exist_ok=True)
+
+ if not src_patch_folder or not os.path.isdir(src_patch_folder):
+ continue
+
+ src_series_path = os.path.join(src_patch_folder, "series")
+ dest_series_path = os.path.join(dest_patch_folder, "series")
+
+ if os.path.isfile(src_series_path):
+ shutil.copyfile(src_series_path, dest_series_path)
+ with open(src_series_path) as f:
+ patch_files = [line.strip() for line in f
+ if not line.startswith("#")]
+ else:
+ patch_files = []
+
+ for patch_file in patch_files:
+ src_patch_file = os.path.join(src_patch_folder, patch_file)
+ dest_patch_file = os.path.join(dest_patch_folder, patch_file)
+ if os.path.isfile(src_patch_file):
+ shutil.copyfile(src_patch_file, dest_patch_file)
+
def _merge_overrides(self, overrides):
tpl_name = os.path.basename(overrides[0])
with open(overrides[0], 'r') as f: