diff --git a/bin/yashchiki b/bin/yashchiki index 65547ecd58ab0ef24020d54531bbfeadc6d07044..90cd7a5ba6425920443a3c52ab199045d97bab33 100755 --- a/bin/yashchiki +++ b/bin/yashchiki @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import argparse import os @@ -51,7 +51,7 @@ parser = argparse.ArgumentParser( to OUTPUT. """)) -all_stages=["fetch", "build-base", "build-spack", "image"] +all_stages=set(["fetch", "build-base-image", "build-base", "build-spack", "image"]) all_styles = list(os.listdir(os.path.dirname(os.path.realpath(__file__)) + "/../share/yashchiki/styles/")) @@ -166,6 +166,7 @@ tmpdir.mkdir(exist_ok=True, parents=True) env = os.environ.copy() env.update({ "DOCKER_BASE_IMAGE": config["docker_base_image"], + "BUILD_BASE_SANDBOX": str(int(config["build_base_sandbox"])), # This needs to be here because otherwise the default python # (2.7.18) will pollute the spec and lead to a conflict # can be removed as soon as the explicit preferred version @@ -182,11 +183,13 @@ env.update({ "YASHCHIKI_SPACK_VERBOSE": str(int(args.spack_verbose)), "YASHCHIKI_SANDBOXES": args.sandboxes_dir, "YASHCHIKI_IMAGE_NAME": args.output, + "YASHCHIKI_BASEIMAGE_NAME": str(args.output) + "_base", # FIXME: nicer, it's a path on the left! "YASHCHIKI_SPACK_PATH": args.spack_dir, "YASHCHIKI_BUILD_CACHE_NAME": args.build_cache_name, "TMPDIR": tmpdir, "YASHCHIKI_CACHES_ROOT": args.caches_dir, "YASHCHIKI_JOBS": str(args.jobs), + "ROOT_DIR": root_dir, }) needs_spackdir = False @@ -195,10 +198,15 @@ if "fetch" in args.stages: env.update({"YASHCHIKI_ENABLE_STAGE_FETCH": "1"}) needs_spackdir = True +if "build-base-image" in args.stages: + env.update({"YASHCHIKI_ENABLE_STAGE_BUILD_BASE_IMAGE": "1"}) + +# FIXME: better called build-sandbox, etc.? if "build-base" in args.stages: env.update({"YASHCHIKI_ENABLE_STAGE_BUILD_BASE": "1"}) needs_spackdir = True +# FIXME: unused? if "build-spack" in args.stages: env.update({"YASHCHIKI_ENABLE_STAGE_BUILD_SPACK": "1"}) needs_spackdir = True @@ -206,9 +214,10 @@ if "build-spack" in args.stages: if "image" in args.stages: env.update({"YASHCHIKI_ENABLE_STAGE_IMAGE": "1"}) -if args.stages != all_stages: - if not pathlib.Path(args.sandboxes_dir, args.style).exists(): - raise RuntimeError("Using yashchiki with incomplete set of stages is only possible for using an existing sandbox.") +# FIXME: readd this reasonably +#if (args.stages != set('fetch', ']) and (args.stages != all_stages): +# if not pathlib.Path(args.sandboxes_dir, args.style).exists(): +# raise RuntimeError("Using yashchiki with incomplete set of stages is only possible for using an existing sandbox.") if needs_spackdir: if not args.spack_dir.is_dir(): @@ -222,6 +231,7 @@ if args.build_cache_on_failure_name: args.log_dir.mkdir(parents=True, exist_ok=True) +import time def run(script: str, env: dict, script_args: list = []): """ Execute the given script. @@ -322,6 +332,8 @@ env.update({"YASHCHIKI_META_DIR": meta_dir}) run("lib/yashchiki/create_caches.sh", env) run("lib/yashchiki/fetch.sh", env) +if config.get("docker_base_image", False): + run("lib/yashchiki/build_base_sandbox.sh", env, [base_sandbox_recipe]) run(str(pathlib.Path("share", "yashchiki", "styles", args.style, "create_recipe.sh")), env) @@ -332,4 +344,3 @@ if args.update_build_cache: if args.tmpdir is None: shutil.rmtree(tmpdir) - diff --git a/lib/yashchiki/build_base_sandbox.sh b/lib/yashchiki/build_base_sandbox.sh new file mode 100755 index 0000000000000000000000000000000000000000..38c049e58661c7b78fd52a815c6871dc7d1ff0c1 --- /dev/null +++ b/lib/yashchiki/build_base_sandbox.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -euo pipefail +shopt -s inherit_errexit 2>/dev/null || true + +if [ -z "${YASHCHIKI_ENABLE_STAGE_BUILD_BASE_IMAGE:-}" ]; then + echo "Skipping stage build-base-image." + exit 0 +fi + +# set generic locale for building +export LANG=C.UTF-8 +export LC_ALL=C.UTF-8 + +unset LC_CTYPE +unset LC_COLLATE +unset LC_MONETARY +unset LC_NUMERIC +unset LC_TIME +unset LC_MESSAGES + +TARGET_FOLDER="${YASHCHIKI_SANDBOXES}/${CONTAINER_STYLE}" + +mkdir -p ${YASHCHIKI_SANDBOXES} + +apptainer build --fakeroot --force ${YASHCHIKI_BASEIMAGE_NAME} $1