From bfb9a02aaf980e3db9a8e866b2488c5d601b1a41 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 11 Jul 2019 22:21:21 -0400 Subject: [PATCH] cmd-build: Add --version switch For FCOS, we need to be able to drive versioning from outside of `cosa build` (see [1]). This will also be used in the very short-term to manually version the first few FCOS preview releases before making it automated. [1] https://github.com/coreos/coreos-assembler/issues/463#issuecomment-479635190 --- src/cmd-build | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/cmd-build b/src/cmd-build index 523a998d85..748dc2e7af 100755 --- a/src/cmd-build +++ b/src/cmd-build @@ -8,7 +8,7 @@ dn=$(dirname "$0") print_help() { cat 1>&2 <<'EOF' Usage: coreos-assembler build --help - coreos-assembler build [--force] [--skip-prune] [TARGETS] + coreos-assembler build [--force] [--skip-prune] [--version VERSION] [TARGETS] Build OSTree and image artifacts from previously fetched packages. The TARGETS argument is a list of artifact types to build; if unspecified it @@ -26,8 +26,9 @@ EOF # Parse options FORCE= SKIP_PRUNE=0 +VERSION= rc=0 -options=$(getopt --options hf --longoptions help,force,force-nocache,skip-prune -- "$@") || rc=$? +options=$(getopt --options hf --longoptions help,force,version:,force-nocache,skip-prune -- "$@") || rc=$? [ $rc -eq 0 ] || { print_help exit 1 @@ -45,6 +46,10 @@ while true; do --skip-prune) SKIP_PRUNE=1 ;; + --version) + shift + VERSION=$1 + ;; --) shift break @@ -158,6 +163,14 @@ if [ -f "${manifest_lock}" ]; then sleep 1 fi +# We'll pass this directly to rpm-ostree instead of through +# commitmeta_input_json since that one also gets injected into meta.json, where +# there's already ostree-version. +version_arg= +if [ -n "${VERSION}" ]; then + version_arg="--add-metadata-string=version=${VERSION}" +fi + # These need to be absolute paths right now for rpm-ostree composejson=${PWD}/tmp/compose.json # Put this under tmprepo so it gets automatically chown'ed if needed @@ -167,7 +180,7 @@ lockfile_out=${tmprepo}/tmp/manifest-lock.generated.${basearch}.json runcompose --cache-only ${FORCE} --add-metadata-from-json "${commitmeta_input_json}" \ --write-composejson-to "${composejson}" \ --ex-write-lockfile-to "${lockfile_out}" \ - ${lock_arg} + ${lock_arg} ${version_arg} # Very special handling for --write-composejson-to as rpm-ostree doesn't # write it if the commit didn't change. if [ -f "${changed_stamp}" ]; then