55 lines
3 KiB
Bash
55 lines
3 KiB
Bash
#!/bin/bash
|
|
# Private worker driver. All paths/identities are selected by the daemon/builder.
|
|
set -euo pipefail
|
|
export LC_ALL=C
|
|
work=$1
|
|
bootstrap=$2
|
|
snapshot=$3
|
|
repository=$4
|
|
reference=$5
|
|
offline=${6:-0}
|
|
[[ $work == /* && $bootstrap == /* && $repository == /* ]]
|
|
[[ $snapshot =~ ^[0-9a-f]{64}$ && $reference =~ ^service/overlay-builds/[a-zA-Z0-9_-]+$ ]]
|
|
[[ $offline == 0 || $offline == 1 ]]
|
|
[[ -d $work && ! -L $work && -d $bootstrap && ! -L $bootstrap ]]
|
|
[[ -f $work/manifest.json && -f $work/policy.json && -d $work/sources && -d $work/adapters ]]
|
|
[[ ! -e $work/result.json && ! -e $work/artifact && ! -e $work/resolution.json ]]
|
|
mkdir -p "$work/cache" "$work/logs"
|
|
printf 'isolated layer builder\n' > "$work/sandbox-marker"
|
|
network=(--resolv-conf=replace-host)
|
|
if [[ $offline == 1 ]]; then network=(--private-network --resolv-conf=off); fi
|
|
common=(--quiet --settings=no --register=no "--directory=$bootstrap"
|
|
"--bind=$work:/job" "--bind-ro=$work/sandbox-marker:/run/archipelago-layer-sandbox")
|
|
|
|
# Bootstrap is a private checkout of the authenticated new base, never live /usr.
|
|
# Scripts are copied into the job by the supervised caller, not fetched at runtime.
|
|
systemd-nspawn "${common[@]}" "${network[@]}" /bin/bash -euo pipefail -c '
|
|
python3 -I -B /job/adapters/resolve-overlay.py /job/manifest.json "$1" /run/overlay-resolve /job/resolution.json
|
|
args=()
|
|
if [[ $2 == 1 ]]; then args+=(--offline); fi
|
|
python3 -I -B /job/adapters/download-overlay.py /job/resolution.json /run/overlay-download /job/cache /job/download.json "${args[@]}"
|
|
' overlay-download "$snapshot" "$offline" > "$work/logs/download.log" 2>&1
|
|
|
|
# Installation and packing share one private /run lifecycle. No build result
|
|
# contains these transient paths: the indexed artifact uses relative namespaces.
|
|
systemd-nspawn "${common[@]}" --private-network --resolv-conf=off /bin/bash -euo pipefail -c '
|
|
python3 -I -B /job/adapters/install-overlay.py /job/resolution.json /job/download.json /job/policy.json /job/cache /run/overlay-target /job/installation.json
|
|
python3 -I -B /job/adapters/capture-overlay.py /job/adapters /job/resolution.json /job/installation.json /job/cache /job/sources /job/packing.json
|
|
python3 -I -B /job/adapters/indexed-overlay.py /job/adapters /job/manifest.json /job/packing.json /job/artifact > /job/packed.json
|
|
' > "$work/logs/install.log" 2>&1
|
|
|
|
# No ref is updated unless all preceding required steps succeeded.
|
|
commit=$(ostree --repo="$repository" commit --branch="$reference" --tree="dir=$work/artifact" \
|
|
--add-metadata-string="archipelago.snapshot=$snapshot")
|
|
[[ $commit =~ ^[0-9a-f]{64}$ ]]
|
|
python3 -I -B - "$work" "$commit" "$snapshot" <<'PY'
|
|
import json
|
|
from pathlib import Path
|
|
import sys
|
|
work = Path(sys.argv[1])
|
|
packed = json.loads((work / 'packed.json').read_bytes())
|
|
with (work / 'result.json').open('x') as stream:
|
|
json.dump(dict(version=0, commit=sys.argv[2], snapshot_id=sys.argv[3],
|
|
lock_sha256=packed['lock_sha256']), stream, sort_keys=True)
|
|
stream.write('\n')
|
|
PY
|