diff --git a/src/cmd-build b/src/cmd-build index a48f982764614a499adaa16c31587138d0fcf67b..2597d880baacbd5c799cbff96e48ab7bcf62293f 100755 --- a/src/cmd-build +++ b/src/cmd-build @@ -100,7 +100,6 @@ while true; do ;; -*) fatal "$0: unrecognized option: $1" - exit 1 ;; *) break @@ -228,6 +227,9 @@ cat > "${commitmeta_input_json}" < tmp/buildmeta.json <> tmp/buildmeta.json <> tmp/buildmeta.json < tmp/images.json < tmp/yumrepos-git.json < tmp/yumrepos-git.json +fi + overridesjson=tmp/overrides.json if [ -f "${overrides_active_stamp}" ]; then echo '{ "coreos-assembler.overrides-active": true }' > "${overridesjson}" @@ -446,7 +465,7 @@ fi # Merge all the JSON; note that we want ${composejson} first # since we may be overriding data from a previous build. -cat "${composejson}" "${overridesjson}" tmp/meta.json tmp/buildmeta.json tmp/diff.json tmp/parent-diff.json tmp/images.json tmp/cosa-image.json "${commitmeta_input_json}" | jq -s add > meta.json +cat "${composejson}" "${overridesjson}" tmp/meta.json tmp/buildmeta.json tmp/diff.json tmp/parent-diff.json tmp/images.json tmp/cosa-image.json tmp/yumrepos-git.json "${commitmeta_input_json}" | jq -s add > meta.json # Move lockfile into build dir mv "${lockfile_out}" . diff --git a/src/cmd-build-fast b/src/cmd-build-fast index 49da7912354387c2cd60497cddfeb51d5e077f84..c07d3072344a1a6afc2052228a24300eefdee903 100755 --- a/src/cmd-build-fast +++ b/src/cmd-build-fast @@ -47,7 +47,6 @@ while true; do ;; -*) fatal "$0: unrecognized option: $1" - exit 1 ;; *) break diff --git a/src/cmd-buildextend-extensions b/src/cmd-buildextend-extensions index bbd6bb9c2e38489378d6addeda8a7d6b66e5b6d9..4201acd05fc9974e86f4d175f80f4d63b27ba7b5 100755 --- a/src/cmd-buildextend-extensions +++ b/src/cmd-buildextend-extensions @@ -1,6 +1,7 @@ #!/usr/bin/python3 -u import argparse +import json import os import shutil import sys @@ -28,8 +29,17 @@ def main(): print("Use --force to force a rebuild") return - treefile_src = 'src/config/manifest.yaml' - extensions_src = 'src/config/extensions.yaml' + init_config = 'src/config.json' + if os.path.exists(init_config): + with open(init_config, encoding='utf-8') as f: + init_cfg = json.loads(f.read()) + variant = init_cfg["coreos-assembler.config-variant"] + treefile_src = f"src/config/manifest-{variant}.yaml" + extensions_src = f"src/config/extensions-{variant}.yaml" + else: + treefile_src = 'src/config/manifest.yaml' + extensions_src = 'src/config/extensions.yaml' + if not os.path.exists(extensions_src): raise Exception(f"Missing {extensions_src}") diff --git a/src/cmd-fetch b/src/cmd-fetch index 03ffa962c7519ecf49eada8b3b69e348d04fb90c..6813b657f15da226f8d4aabe13c2c06c8948ac6b 100755 --- a/src/cmd-fetch +++ b/src/cmd-fetch @@ -67,7 +67,6 @@ while true; do ;; *) fatal "$0: unrecognized option: $1" - exit 1 ;; esac shift @@ -76,7 +75,6 @@ done if [ $# -ne 0 ]; then print_help fatal "ERROR: Too many arguments" - exit 1 fi prepare_build diff --git a/src/cmd-init b/src/cmd-init index 117977b923b9ae6bb09c106b135c342151a35031..d3d58667643ae04529e96e3cdf4cca39d3af00a4 100755 --- a/src/cmd-init +++ b/src/cmd-init @@ -9,12 +9,18 @@ dn=$(dirname "$0") FORCE=0 BRANCH="" COMMIT="" +TRANSIENT=0 +YUMREPOS="" +YUMREPOS_BRANCH="" +VARIANT="" print_help() { cat 1>&2 <<'EOF' Usage: coreos-assembler init --help - coreos-assembler init [--force] [--branch BRANCH] - [--commit COMMIT] GITCONFIG [SUBDIR] + coreos-assembler init [--force] [--transient] [--branch BRANCH] + [--commit COMMIT] [-V/--variant VARIANT] + [--yumrepos GITREPO] [--yumrepos-branch BRANCH] + GITCONFIG [SUBDIR] For example, you can use https://github.com/coreos/fedora-coreos-config as GITCONFIG, or fork it. Another option useful for local development @@ -22,6 +28,29 @@ Usage: coreos-assembler init --help starting with `/` - a symlink to it will be created and then used directly. You can specify a branch of a git repo with the `--branch` flag. + Use `--yumrepos` for builds that need .repo files and a content_sets.yaml which + are not in GITCONFIG. For example: files need to be hidden behind a firewall + in GITREPO. Using this option will clone GITREPO alongside GITCONFIG, thus you + may need to configure certificates. Use `--yumrepos-branch` to choose a non-default + branch when cloning. Local paths are also supported. + + Use `--transient` for builds that will throw away all cached data on success/failure, + and should hence not invoke `fsync()` for example. + + Each config repo must include a default set of manifests for NOSA to be able + to build an ostree commit and disk images (respectively with 'manifest.yaml' + and 'image.yaml'). You can also optionally provide another manifest to build + extensions (via extensions.yaml). + + Config repos may also include additional variants and you can select which one + to use with the '--variant' flag. The manifests for those variants should + follow the following naming convention: 'manifest-$VARIANT.yaml' + 'image-$VARIANT.yaml' 'extensions-$VARIANT.yaml'. + + The selected variant will be stored in 'src/variant.json'. Make sure to clean + all caches with 'cosa clean --all' if you manually switch the variant after + 'cosa init'. + If specified, SUBDIR is a subdirectory of the git repository that should contain manifest.yaml and image.yaml (or image.ks). EOF @@ -29,7 +58,7 @@ EOF # Call getopt to validate the provided input. rc=0 -options=$(getopt --options hfb:c: --longoptions help,force,branch:,commit: -- "$@") || rc=$? +options=$(getopt --options hfb:c:V: --longoptions help,force,transient,branch:,commit:,yumrepos:,yumrepos-branch:,variant: -- "$@") || rc=$? [ $rc -eq 0 ] || { print_help exit 1 @@ -44,6 +73,9 @@ while true; do -f | --force) FORCE=1 ;; + --transient) + TRANSIENT=1 + ;; -b | --branch) case "$2" in "") @@ -62,6 +94,33 @@ while true; do shift ;; esac ;; + --yumrepos) + case "$2" in + "") + shift ;; + *) + YUMREPOS="$2" + shift ;; + esac + ;; + --yumrepos-branch) + case "$2" in + "") + shift ;; + *) + YUMREPOS_BRANCH="$2" + shift ;; + esac + ;; + -V | --variant) + case "$2" in + "") + shift ;; + *) + VARIANT="$2" + shift ;; + esac + ;; --) shift break @@ -69,17 +128,15 @@ while true; do *) print_help fatal "init: unrecognized option: $1" - exit 1 ;; esac shift done # If user did not provide a repo then error out -if [ $# = 0 ]; then +if [ $# -ne 1 ]; then print_help fatal "ERROR: Missing GITCONFIG" - exit 1 fi # If the current working dir is not empty then error out @@ -116,6 +173,7 @@ mkdir -p src if [ -n "${COMMIT}" ]; then git -C ./config fetch origin "$COMMIT" git -C ./config reset --hard "$COMMIT" + git -C ./config submodule update --init --recursive fi if [ -n "${subdir}" ]; then mv config config-git @@ -124,15 +182,46 @@ mkdir -p src (set +x; cd config && echo -n "Config commit: " && git describe --tags --always --abbrev=42) ;; esac - manifest=config/manifest.yaml - if ! [ -f "${manifest}" ]; then - echo 1>&2 "Failed to find src/${manifest}" - fatal "If using a custom configuration, be sure it has a manifest.yaml." - fi fi) +# Default paths for manifest.yaml & image.yaml +manifest="src/config/manifest.yaml" +image="src/config/image.yaml" +if [[ ! -f "${manifest}" ]] || [[ ! -f "${image}" ]]; then + echo 1>&2 "Could not find default manifests (${manifest} & ${image})" + fatal "If you are using a custom configuration, be sure it has a manifest.yaml & image.yaml." +fi + +# Select the variant if requested +if [[ -n "${VARIANT}" ]] && [[ "${VARIANT}" != "default" ]]; then + manifest="src/config/manifest-${VARIANT}.yaml" + image="src/config/image-${VARIANT}.yaml" + if [[ ! -f "${manifest}" ]] || [[ ! -f "${image}" ]]; then + fatal "Could not find the manifests (${manifest} & ${image}) for the '${VARIANT}' variant" + fi + echo "Using variant: '${VARIANT}'" + cat > "src/config.json" < "${override_manifest}" <> "${override_manifest}" + for layer in ${layers}; do + echo " - ${layer}" >> "${override_manifest}" + done + fi + rootfs_overrides="${overridesdir}/rootfs" if [[ -d "${rootfs_overrides}" && -n $(ls -A "${rootfs_overrides}") ]]; then echo -n "Committing ${rootfs_overrides}... "