Skip to content

Commit

Permalink
build: Handle case of previous build with no image.json in ostree
Browse files Browse the repository at this point in the history
For now, we need to handle this.  But I think we can switch
back to hard requiring it later, which will happen naturally
when we rework the build system to more cleanly separate
ostree container builds and disk image builds.

Closes: coreos#2885
  • Loading branch information
cgwalters committed Jun 1, 2022
1 parent 816ebae commit 823fe2b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/cosalib/cmdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,24 @@ def rm_allow_noent(path):

def extract_image_json(workdir, commit):
repo = os.path.join(workdir, 'tmp/repo')
with open(os.path.join(workdir, 'tmp/image.json'), 'w') as f:
subprocess.check_call(['ostree', f'--repo={repo}', 'cat', commit, '/usr/share/coreos-assembler/image.json'], stdout=f)
path = os.path.join(workdir, 'tmp/image.json')
tmppath = path + '.tmp'
with open(tmppath, 'w') as f:
rc = subprocess.call(['ostree', f'--repo={repo}', 'cat', commit, '/usr/share/coreos-assembler/image.json'], stdout=f)
if rc == 0:
# Happy path, we have image.json in the ostree commit, rename it into place and we're done.
os.rename(tmppath, path)
return
# Otherwise, we are operating on a legacy build; clean up our tempfile.
os.remove(tmppath)
if not os.path.isfile(path):
# In the current build system flow, image builds will have already
# regenerated tmp/image.json from src/config. If that doesn't already
# exist, then something went wrong.
raise Exception("Failed to extract image.json")
else:
# Warn about this case; but it's not fatal.
print("Warning: Legacy operating on ostree image that does not contain image.json")


# In coreos-assembler, we are strongly oriented towards the concept of a single
Expand Down

0 comments on commit 823fe2b

Please sign in to comment.