Skip to content

Commit c61da89

Browse files
dustymabejlebon
authored andcommitted
allow templating {stream} in image.yaml files
This will allow us to provide the following, essentially allowing us to have the same image.yaml on all branches, but allowing for the stream name to get substituted in dynamically. ``` container-imgref: "ostree-remote-registry:fedora:quay.io/fedora/fedora-coreos:{stream}" ``` Not having something like this ended up with us mismanaging the image.yaml during the promotion of `next-devel` to `next` in coreos/fedora-coreos-tracker#1913 This was proposed as a better alternative to modifying promote-config to ignore `image.yaml`: coreos/fedora-coreos-releng-automation#202
1 parent 2b30a0a commit c61da89

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/cmdlib.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ prepare_build() {
206206
fi
207207

208208
export image_json="${tmp_builddir}/image.json"
209-
write_image_json "${image}" "${image_json}"
209+
write_image_json "${image}" "${image_json}" "${manifest}"
210210
# These need to be absolute paths right now for rpm-ostree
211211
composejson="$(readlink -f "${workdir}"/tmp/compose.json)"
212212
export composejson
@@ -1075,11 +1075,12 @@ print('Build ${buildid} was inserted ${arch:+for $arch}')")
10751075
write_image_json() {
10761076
local srcfile=$1; shift
10771077
local outfile=$1; shift
1078+
local ostree_manifest=$1; shift
10781079
(python3 -c "
10791080
import sys
10801081
sys.path.insert(0, '${DIR}')
10811082
from cosalib import cmdlib
1082-
cmdlib.write_image_json('${srcfile}', '${outfile}')")
1083+
cmdlib.write_image_json('${srcfile}', '${outfile}', ostree_manifest='${ostree_manifest}')")
10831084
}
10841085

10851086
# API to prepare image builds.

src/cosalib/cmdlib.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,16 @@ def cmdlib_sh(script):
467467
'''])
468468

469469

470-
def generate_image_json(srcfile):
470+
def generate_image_json(srcfile, ostree_manifest):
471+
manifest_vars = yaml.safe_load(open(ostree_manifest))['variables']
471472
r = yaml.safe_load(open("/usr/lib/coreos-assembler/image-default.yaml"))
472-
for k, v in flatten_image_yaml(srcfile).items():
473+
for k, v in flatten_image_yaml(srcfile, format_args=manifest_vars).items():
473474
r[k] = v
474475
return r
475476

476477

477-
def write_image_json(srcfile, outfile):
478-
r = generate_image_json(srcfile)
478+
def write_image_json(srcfile, outfile, ostree_manifest):
479+
r = generate_image_json(srcfile, ostree_manifest)
479480
with open(outfile, 'w') as f:
480481
json.dump(r, f, sort_keys=True)
481482

@@ -490,12 +491,13 @@ def merge_lists(x, y, k):
490491
x[k].extend([i for i in y[k] if i not in x[k]])
491492

492493

493-
def flatten_image_yaml(srcfile, base=None):
494+
def flatten_image_yaml(srcfile, base=None, format_args={}):
494495
if base is None:
495496
base = {}
496497

497498
with open(srcfile) as f:
498-
srcyaml = yaml.safe_load(f)
499+
contents = f.read()
500+
srcyaml = yaml.safe_load(contents.format(**format_args))
499501

500502
# first, special-case list values
501503
merge_lists(base, srcyaml, 'extra-kargs')
@@ -508,7 +510,7 @@ def flatten_image_yaml(srcfile, base=None):
508510

509511
fn = os.path.join(os.path.dirname(srcfile), srcyaml['include'])
510512
del base['include']
511-
return flatten_image_yaml(fn, base)
513+
return flatten_image_yaml(fn, base=base, format_args=format_args)
512514

513515

514516
def ensure_glob(pathname, **kwargs):

0 commit comments

Comments
 (0)