|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eufo pipefail |
| 4 | + |
| 5 | +container_image=ghcr.io/gardenlinux/builder:5d05982bf4132b0d7814080ea3042344d500adc3 |
| 6 | +container_engine=podman |
| 7 | + |
| 8 | +container_run_opts=( |
| 9 | + --security-opt seccomp=unconfined |
| 10 | + --security-opt apparmor=unconfined |
| 11 | + --security-opt label=disable |
| 12 | + --read-only |
| 13 | +) |
| 14 | + |
| 15 | +container_mount_opts=( |
| 16 | + -v "$PWD/features:/builder/features:ro" |
| 17 | + -v "$PWD/keyring.gpg:/builder/keyring.gpg:ro" |
| 18 | + -v "$PWD/.build:/builder/.build" |
| 19 | +) |
| 20 | + |
| 21 | +use_kms=0 |
| 22 | +resolve_cname=0 |
| 23 | + |
| 24 | +while [ $# -gt 0 ]; do |
| 25 | + case "$1" in |
| 26 | + --container-image) |
| 27 | + container_image="$2" |
| 28 | + shift 2 |
| 29 | + ;; |
| 30 | + --container-engine) |
| 31 | + container_engine="$2" |
| 32 | + shift 2 |
| 33 | + ;; |
| 34 | + --container-run-opts) |
| 35 | + declare -a "container_run_opts=($2)" |
| 36 | + shift 2 |
| 37 | + ;; |
| 38 | + --kms) |
| 39 | + use_kms=1 |
| 40 | + shift |
| 41 | + ;; |
| 42 | + --print-container-image) |
| 43 | + printf '%s\n' "$container_image" |
| 44 | + exit 0 |
| 45 | + ;; |
| 46 | + --resolve-cname) |
| 47 | + resolve_cname=1 |
| 48 | + shift |
| 49 | + ;; |
| 50 | + *) |
| 51 | + break |
| 52 | + ;; |
| 53 | + esac |
| 54 | +done |
| 55 | + |
| 56 | +if [ "$container_image" = localhost/builder ]; then |
| 57 | + dir="$(dirname -- "$(realpath -- "${BASH_SOURCE[0]}")")" |
| 58 | + "$container_engine" build -t "$container_image" "$dir" |
| 59 | +fi |
| 60 | + |
| 61 | +repo="$(./get_repo)" |
| 62 | +commit="$(./get_commit)" |
| 63 | +timestamp="$(./get_timestamp)" |
| 64 | +default_version="$(./get_version)" |
| 65 | + |
| 66 | +[ -d .build ] || mkdir .build |
| 67 | + |
| 68 | +if [ "$resolve_cname" = 1 ]; then |
| 69 | + arch="$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" dpkg --print-architecture)" |
| 70 | + cname="$("$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" /builder/parse_features --feature-dir /builder/features --default-arch "$arch" --default-version "$default_version" --cname "$1")" |
| 71 | + short_commit="$(head -c 8 <<< "$commit")" |
| 72 | + echo "$cname-$short_commit" |
| 73 | + exit 0 |
| 74 | +fi |
| 75 | + |
| 76 | +make_opts=( |
| 77 | + REPO="$repo" |
| 78 | + COMMIT="$commit" |
| 79 | + TIMESTAMP="$timestamp" |
| 80 | + DEFAULT_VERSION="$default_version" |
| 81 | +) |
| 82 | + |
| 83 | +if [ "$use_kms" = 1 ]; then |
| 84 | + for e in AWS_DEFAULT_REGION AWS_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN; do |
| 85 | + if [ -n "${!e-}" ]; then |
| 86 | + make_opts+=("$e=${!e}") |
| 87 | + fi |
| 88 | + done |
| 89 | +fi |
| 90 | + |
| 91 | +if [ -d cert ]; then |
| 92 | + container_mount_opts+=(-v "$PWD/cert:/builder/cert:ro") |
| 93 | +fi |
| 94 | + |
| 95 | +"$container_engine" run --rm "${container_run_opts[@]}" "${container_mount_opts[@]}" "$container_image" make --no-print-directory -C /builder "${make_opts[@]}" "$@" |
0 commit comments