Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support git submodules for source containers #54

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions source-container-build/app/source_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,37 @@ def make_source_archive(
repo_info = get_repo_info(source_dir)
name_sha = f"{repo_info['name']}-{repo_info['last_commit_sha']}"
output_archive = f"{source_archive_dir}/{name_sha}.tar.gz"
git_cmd = ["git", "archive", "--prefix", name_sha + "/", "--output", output_archive, "HEAD"]
log.debug("Generate source archive %r", git_cmd)
run(git_cmd, check=True, cwd=source_dir)

stash_cmd = ["git", "stash"]
log.debug("Stashing any changes to working repo %r", stash_cmd)
run(stash_cmd, check=True, cwd=source_dir)

mtime_cmd = ["git", "show", "-s", "--format=%cI"]
log.debug("Collecting timestamp of the commit at HEAD %r", mtime_cmd)
mtime_process = run(mtime_cmd, check=True, cwd=source_dir, capture_output=True, text=True)
mtime = mtime_process.stdout.strip()

ls_cmd = ["git", "ls-files", "--recurse-submodules"]
log.debug("Generate source repo file list %r", ls_cmd)
git_process = run(ls_cmd, check=True, cwd=source_dir, capture_output=True, text=True)

tar_cmd = [
"tar",
"caf",
output_archive,
"--mtime",
mtime,
"--transform",
f"s,^,{name_sha}/,",
"-T-",
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about set --owner=0 --group=0 --mode='a+rw' explicitly?

log.debug("Generate source archive %r", tar_cmd)
run(tar_cmd, input=git_process.stdout.encode("utf-8"), check=True, cwd=source_dir)

pop_cmd = ["git", "stash", "pop"]
log.debug("Popping any stashed changes to working repo %r", pop_cmd)
run(pop_cmd, cwd=source_dir)

log.info("add source archive directory to sources for bsi: %s", source_archive_dir)
sib_dirs.extra_src_dirs.append(source_archive_dir)

Expand Down
10 changes: 10 additions & 0 deletions source-container-build/app/test_source_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,16 @@ def run_side_effect(cmd, **kwargs):
completed_proc.stdout = "https://githost/org/app.git"
return completed_proc

if run_cmd == ["git", "ls-files"]:
completed_proc = Mock()
completed_proc.stdout = "file.txt"
return completed_proc

if run_cmd == ["git", "show"]:
completed_proc = Mock()
completed_proc.stdout = "2024-03-20T21:57:06-04:00"
return completed_proc

if run_cmd == ["skopeo", "inspect"]:
if parent_images:
dest_image = run_cmd[-1]
Expand Down