#!/bin/bash set -euxo pipefail # Usage: ./builder.sh if [[ $# -lt 2 ]]; then echo "Usage: $0 " exit 1 fi IMAGE="$1" VERSION="$2" IMAGE_DIR="images/${IMAGE}" MANIFEST="${IMAGE_DIR}/manifest.yaml" OUTPUT="${IMAGE_DIR}/manifest.ociarchive" REF="images/${IMAGE}/${VERSION}" # --- CHECKS --- if [[ ! -d "$IMAGE_DIR" ]]; then echo "Image directory not found: $IMAGE_DIR" exit 1 fi if [[ ! -f "$MANIFEST" ]]; then echo "Manifest not found: $MANIFEST" exit 1 fi # --- PREPARE OSTREE REPO --- mkdir -p repo cache if [[ ! -f "repo/config" ]]; then pushd repo >/dev/null ostree init --repo=. --mode=bare-user popd >/dev/null fi ostree --repo=repo config set core.fsync false # --- VERSIONING --- buildid="$(date '+%Y%m%d.0')" timestamp="$(date --iso-8601=sec)" echo "${buildid}" > .buildid echo "Composing ${VERSION}.${buildid} ..." # repos import cp images/shared/*.repo "${IMAGE_DIR}" cp "${IMAGE_DIR}"/{$IMAGE}/repos/*.repo "${IMAGE_DIR}" # Ensure manifest has correct ref and releasever sed -i '/^ref:/d' "$MANIFEST" sed -i '/^releasever:/d' "$MANIFEST" sed -i "1i releasever: ${VERSION}" "$MANIFEST" sed -i "1i ref: ${REF}" "$MANIFEST" #Run a optional per image script to do image specific things POSTPROCESS="${IMAGE_DIR}/${IMAGE}"/postprocess.sh" if [[ -x "${POSTPROCESS}" ]]; then echo "Running postprocess script: ${POSTPROCESS}" "${POSTPROCESS}" else echo "No postprocess.sh found in ${IMAGE_DIR}, skipping." fi # --- COMPOSE IMAGE --- ARGS=( "--cachedir=cache" "--initialize" "--max-layers=96" ) rpm-ostree compose image \ "${ARGS[@]}" \ "$MANIFEST" \ "$OUTPUT"