Skip to content

Commit

Permalink
Convert containers root folder into a tar.gz
Browse files Browse the repository at this point in the history
OBS cannot handle folders as sources, compress a folder named root in
the container folder into a root.tar.gz before pushing to OBS.
  • Loading branch information
cbosdo committed Jan 22, 2025
1 parent 4fdca6c commit 52eea0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Reduce the number of layers in the image
19 changes: 18 additions & 1 deletion rel-eng/custom/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
import os
import shutil
import tarfile

from tito.builder import Builder
from tito.common import run_command, debug, info_out
Expand Down Expand Up @@ -92,8 +93,14 @@ def copy_sources(self):

gitdir = os.path.join(self.git_root, self.relative_project_dir)
for path in os.listdir(gitdir):
debug("Processing " + path)
file_path = os.path.join(gitdir, path)
if os.path.isfile(file_path):
if path == "root":
# Create a root.tar.gz file from the files in root folder
target_path = os.path.join(self.rpmbuild_sourcedir, "root.tar.gz")
tar(os.path.join(gitdir, path), target_path)
self.sources.append(target_path)
elif os.path.isfile(file_path):
target_path = os.path.join(self.rpmbuild_sourcedir, path)
self.copy_source(file_path, target_path)

Expand Down Expand Up @@ -129,6 +136,16 @@ def copy_push(self, name):
self.sources.append(target_script)


def tar(src, dest):
'''
Create a dest tar.gz file from the files in the src folder.
'''
debug(f"Compressing {src} into {dest}")
with tarfile.open(dest, "w:gz") as tarball:
for name in os.listdir(src):
tarball.add(os.path.join(src, name), name)




class ChartBuilder(ContainerBuilder):
Expand Down

0 comments on commit 52eea0e

Please sign in to comment.