sandcastle-build (2375B)
1 #!/usr/bin/env bash 2 3 set -eu 4 5 no_cache_args=() 6 package_args=() 7 containerfile=Dockerfile 8 containerfile_set= 9 10 while [[ $# -gt 0 ]]; do 11 case $1 in 12 --no-cache) 13 no_cache_args=(--no-cache) 14 package_args=(--force) 15 ;; 16 -*) 17 echo >&2 "Unknown option '$1'" 18 exit 1 19 ;; 20 *) 21 if [[ -n $containerfile_set ]]; then 22 echo >&2 "Unexpected argument '$1'" 23 exit 1 24 fi 25 containerfile=$1 26 containerfile_set=yes 27 ;; 28 esac 29 shift 30 done 31 32 SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) 33 34 cd "$SCRIPT_DIR" 35 36 if [[ ! -r $containerfile ]]; then 37 echo >&2 "Containerfile '${containerfile}' not found or not readable." 38 exit 1 39 fi 40 41 sandcastle_version=unknown 42 if git_version=$(git describe --tags --always --dirty 2>/dev/null); then 43 sandcastle_version=$git_version 44 fi 45 46 builder_image=localhost/taler-sandcastle-package-builder:latest 47 cache_dir=$SCRIPT_DIR/cache 48 mkdir -p \ 49 "$cache_dir/debian-trixie/apt-archives/partial" \ 50 "$cache_dir/debian-trixie/apt-lists/partial" \ 51 "$cache_dir/npm" 52 53 read -r turnstile_url turnstile_tag < <( 54 python3 - "$SCRIPT_DIR" <<'PY' 55 import sys 56 57 root = sys.argv[1] 58 sys.path.insert(0, f"{root}/buildscripts") 59 from package_config import load_config 60 61 config = load_config(f"{root}/packages.toml") 62 package = config.packages["turnstile"] 63 print(config.repository_for(package).url, package.tag, sep="\t") 64 PY 65 ) 66 67 # The nofile ulimit is required to prevent fakeroot from becoming sluggish. 68 build_args=( 69 podman build 70 --log-level=debug 71 --ulimit=nofile=2048:2048 72 -f "$containerfile" 73 --volume "$cache_dir/debian-trixie/apt-archives:/var/cache/apt/archives:z" 74 --volume "$cache_dir/debian-trixie/apt-lists:/var/lib/apt/lists:z" 75 --volume "$cache_dir/npm:/root/.npm:z" 76 ) 77 78 echo "Building package-builder image with containerfile: $containerfile" 79 "${build_args[@]}" "${no_cache_args[@]}" \ 80 --target base-system \ 81 --tag "$builder_image" \ 82 . 83 84 echo "Building outdated Debian packages" 85 python3 buildscripts/sandcastle_build_packages.py \ 86 --builder-image "$builder_image" \ 87 "${package_args[@]}" 88 89 echo "Building final sandcastle image" 90 exec "${build_args[@]}" "${no_cache_args[@]}" \ 91 --build-arg "SANDCASTLE_VERSION=$sandcastle_version" \ 92 --build-arg "TURNSTILE_GIT_URL=$turnstile_url" \ 93 --build-arg "TURNSTILE_TAG=$turnstile_tag" \ 94 --target taler-final \ 95 --tag taler-base-all \ 96 .