From 059425ffbe157ee59c1997c4d1f059799c9dd6d3 Mon Sep 17 00:00:00 2001 From: mtalexan Date: Thu, 14 Sep 2023 14:46:09 -0400 Subject: [PATCH] cmd-build: Fix buildfetch image.yaml overwriting configs Add option to cmdlib.import_ostree_commit to conditionally exclude the image.json extraction that overwrites. Add option to import_ostree_commit wrapper. Use import_ostree_commit exclusion of image.json option when importing after creating image.json. --- src/cmd-build | 3 ++- src/cmdlib.sh | 10 +++++++--- src/cosalib/cmdlib.py | 8 +++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cmd-build b/src/cmd-build index db65dfbf60..1967aa7dae 100755 --- a/src/cmd-build +++ b/src/cmd-build @@ -193,7 +193,8 @@ if [ -n "${previous_commit}" ]; then commitpartial=${tmprepo}/state/${previous_commit}.commitpartial if [ ! -f "${commitpath}" ] || [ -f "${commitpartial}" ]; then if [ -f "${previous_builddir}/${previous_ostree_tarfile_path}" ]; then - import_ostree_commit_for_build "${previous_build}" + # don't extract the image.json though, keep the one we generated during prepare_build above + import_ostree_commit_for_build "${previous_build}" false else # ok, just fallback to importing the commit object only mkdir -p "$(dirname "${commitpath}")" diff --git a/src/cmdlib.sh b/src/cmdlib.sh index a69aefed58..0e27f8dfdc 100755 --- a/src/cmdlib.sh +++ b/src/cmdlib.sh @@ -1048,9 +1048,13 @@ cmdlib.write_image_json('${srcfile}', '${outfile}')") # API to prepare image builds. # Ensures that the tmp/repo ostree repo is initialized, -# and also writes tmp/image.json. +# and also writes tmp/image.json if $2 isn't set false. import_ostree_commit_for_build() { - local buildid=$1; shift + local buildid=$1 + local extractjson=${2^:-true} + shift 2 + # pythonize the bash true/false into True/False + local extractjson_pythonized=${extractjson^} (python3 -c " import sys sys.path.insert(0, '${DIR}') @@ -1060,7 +1064,7 @@ workdir = '${workdir:-$(pwd)}' builds = Builds(workdir) builddir = builds.get_build_dir('${buildid}') buildmeta = builds.get_build_meta('${buildid}') -cmdlib.import_ostree_commit(workdir, builddir, buildmeta) +cmdlib.import_ostree_commit(workdir, builddir, buildmeta, extract_json=${extractjson_pythonized}) ") } diff --git a/src/cosalib/cmdlib.py b/src/cosalib/cmdlib.py index 53d711ccc0..32882dda8f 100644 --- a/src/cosalib/cmdlib.py +++ b/src/cosalib/cmdlib.py @@ -277,7 +277,7 @@ def extract_image_json(workdir, commit): # a metal image, we may not have preserved that cache. # # Call this function to ensure that the ostree commit for a given build is in tmp/repo. -def import_ostree_commit(workdir, buildpath, buildmeta): +def import_ostree_commit(workdir, buildpath, buildmeta, extract_json=True): tmpdir = os.path.join(workdir, 'tmp') with Lock(os.path.join(workdir, 'tmp/repo.import.lock'), lifetime=LOCK_DEFAULT_LIFETIME): @@ -294,7 +294,8 @@ def import_ostree_commit(workdir, buildpath, buildmeta): stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 and not os.path.isfile(commitpartial)): - extract_image_json(workdir, commit) + if extract_json: + extract_image_json(workdir, commit) return print(f"Extracting {commit}") @@ -320,7 +321,8 @@ def import_ostree_commit(workdir, buildpath, buildmeta): subprocess.check_call(['ostree', f'--repo={repo}', 'pull-local', tmpd, buildmeta['buildid']]) # Also extract image.json since it's commonly needed by image builds - extract_image_json(workdir, commit) + if extract_json: + extract_image_json(workdir, commit) def get_basearch():