Files
fluffy-pancake/Justfile
T

271 lines
9.0 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# fluffy-pancake – Justfile (feat/umbriel-Zweig)
# Dieser Zweig baut ausschliesslich Installer-ISOs (kein qcow2/raw).
# Auf dem main-Zweig (Kinoite-Basis) stehen zusaetzlich qcow2/raw-Targets
# zur Verfuegung – dortige Justfile ist nicht identisch.
# Registry/Image-Name/Tag lassen sich per Env (REGISTRY, IMAGE_NAME,
# DEFAULT_TAG, BIB_IMAGE) ueberschreiben.
export registry := env("REGISTRY", "humocs-man.duckdns.org/humocs-man")
export image_name := env("IMAGE_NAME", "fluffy-pancake")
export default_tag := env("DEFAULT_TAG", "stable")
export bib_image := env("BIB_IMAGE", "quay.io/centos-bootc/bootc-image-builder:latest")
alias build-vm := build-iso
alias rebuild-vm := rebuild-iso
alias run-vm := run-vm-iso
[private]
default:
@just --list
# Check Just Syntax
[group('Just')]
check:
#!/usr/bin/bash
find . -type f -name "*.just" | while read -r file; do
echo "Checking syntax: $file"
just --unstable --fmt --check -f "$file"
done
echo "Checking syntax: Justfile"
just --unstable --fmt --check -f Justfile
# Fix Just Syntax
[group('Just')]
fix:
#!/usr/bin/bash
find . -type f -name "*.just" | while read -r file; do
echo "Checking syntax: $file"
just --unstable --fmt -f "$file"
done
echo "Checking syntax: Justfile"
just --unstable --fmt -f Justfile || { exit 1; }
# Clean Repo
[group('Utility')]
clean:
#!/usr/bin/bash
set -eoux pipefail
touch _build
find *_build* -exec rm -rf {} \;
rm -f previous.manifest.json
rm -f changelog.md
rm -f output.env
rm -rf output/
# Sudo Clean Repo
[group('Utility')]
[private]
sudo-clean:
just sudoif just clean
# sudoif bash function
[group('Utility')]
[private]
sudoif command *args:
#!/usr/bin/bash
function sudoif(){
if [[ "${UID}" -eq 0 ]]; then
"$@"
elif [[ "$(command -v sudo)" && -n "${SSH_ASKPASS:-}" ]] && [[ -n "${DISPLAY:-}" || -n "${WAYLAND_DISPLAY:-}" ]]; then
/usr/bin/sudo --askpass "$@" || exit 1
elif [[ "$(command -v sudo)" ]]; then
/usr/bin/sudo "$@" || exit 1
else
exit 1
fi
}
sudoif {{ command }} {{ args }}
# Build the local image using Podman from Containerfile
# HINWEIS: Auf diesem Zweig wird nur das Container-Image + ISO gebaut
# (kein qcow2/raw – diese Targets gibt es nur auf main).
# configs/auth.json liegt NICHT im Repo (gitignored, Secret) - fehlt die
# Datei, wird sie aus dem Template mit Dummy-Token angelegt, damit der
# lokale Build nicht an COPY scheitert. CI erzeugt die echte Datei selbst.
build $target_image=image_name $tag=default_tag:
#!/usr/bin/env bash
if [[ ! -f configs/auth.json ]]; then
echo "==> Kein configs/auth.json - lege Dummy aus Template an (nur lokaler Build)"
sed "s|READONLY_TOKEN_PLACEHOLDER|LOCAL-DEV-DUMMY|g" \
configs/auth.json.template > configs/auth.json
fi
BUILD_ARGS=()
if [[ -z "$(git status -s)" ]]; then
BUILD_ARGS+=("--build-arg" "SHA_HEAD_SHORT=$(git rev-parse --short HEAD)")
fi
podman build \
"${BUILD_ARGS[@]}" \
--pull=newer \
--tag "${target_image}:${tag}" \
.
# Pulls remote image or loads local image into rootful podman storage for BIB
_rootful_load_image $target_image $tag=default_tag:
#!/usr/bin/bash
set -eoux pipefail
FULL_IMAGE="${target_image}:${tag}"
# Target ist Remote-Image -> Direkt via Rootful Podman pullen
if [[ "${target_image}" != localhost/* ]]; then
echo "==> Pulle Remote-Image: ${FULL_IMAGE}"
just sudoif podman pull "${FULL_IMAGE}"
exit 0
fi
# Target ist lokales Image -> In Rootful Storage kopieren
if [[ -n "${SUDO_USER:-}" || "${UID}" -eq "0" ]]; then
echo "Bereits als root aktiv."
exit 0
fi
set +e
podman inspect -t image "${FULL_IMAGE}" > /dev/null 2>&1
return_code=$?
set -e
USER_IMG_ID=$(podman images -q "${FULL_IMAGE}")
if [[ $return_code -eq 0 ]]; then
ID=$(just sudoif podman images -q "${FULL_IMAGE}")
if [[ "$ID" != "$USER_IMG_ID" ]]; then
COPYTMP=$(mktemp -p "${PWD}" -d -t _build_podman_load.XXXXXXXXXX)
podman save "${FULL_IMAGE}" -o "${COPYTMP}/image.tar"
just sudoif podman load -i "${COPYTMP}/image.tar"
rm -rf "${COPYTMP}"
fi
else
just sudoif podman pull "${FULL_IMAGE}"
fi
# Build a bootc bootable image using Bootc Image Builder (BIB)
# HINWEIS: Bei Typ "iso" wird die Image-Referenz im Kickstart (iso/iso.toml)
# automatisch auf $target_image:$tag umgeschrieben. So installiert eine lokal
# gebaute Test-ISO auch das Test-Image und nicht :stable.
_build-bib $target_image $tag $type $config: (_rootful_load_image target_image tag)
#!/usr/bin/env bash
set -euo pipefail
args="--type ${type} "
args+="--use-librepo=True "
args+="--rootfs=btrfs"
BUILDTMP=$(mktemp -p "${PWD}" -d -t _build-bib.XXXXXXXXXX)
CONFIG_ABS="$(pwd)/${config}"
CONFIGTMP=""
if [[ "${type}" == "iso" ]]; then
CONFIGTMP=$(mktemp -p "${PWD}" -d -t _build-bib-config.XXXXXXXXXX)
sed "s|humocs-man.duckdns.org/humocs-man/fluffy-pancake:stable|{{ target_image }}:{{ tag }}|g" \
"${CONFIG_ABS}" > "$CONFIGTMP/config.toml"
CONFIG_ABS="$CONFIGTMP/config.toml"
echo "==> ISO-Kickstart zeigt auf {{ target_image }}:{{ tag }}"
fi
sudo podman run \
--rm \
-it \
--privileged \
--pull=newer \
--net=host \
--security-opt label=type:unconfined_t \
-v "${CONFIG_ABS}":/config.toml:ro \
-v "$BUILDTMP":/output \
-v /var/lib/containers/storage:/var/lib/containers/storage \
"${bib_image}" \
${args} \
"${target_image}:${tag}"
mkdir -p output
sudo mv -f $BUILDTMP/* output/
sudo rmdir $BUILDTMP
if [[ -n "$CONFIGTMP" ]]; then rm -rf "$CONFIGTMP"; fi
sudo chown -R $USER:$USER output/
# Rebuild-Schritt: Führt vor BIB ein lokales 'podman build' aus
_rebuild-bib $target_image $tag $type $config: (build target_image tag) && (_build-bib target_image tag type config)
# ==============================================================================
# BUILD TARGETS (ISO aus Remote-Registry pullen, kein lokaler Container-Build)
# ==============================================================================
# Build an ISO virtual machine image from Registry
[group('Build Virtual Machine Image')]
build-iso $target_image=(registry + "/" + image_name) $tag=default_tag: && (_build-bib target_image tag "iso" "iso/iso.toml")
# ==============================================================================
# REBUILD TARGETS (Lokaler Container-Build + ISO aus dem lokalen Image)
# ==============================================================================
# Rebuild an ISO virtual machine image locally
[group('Build Virtual Machine Image')]
rebuild-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_rebuild-bib target_image tag "iso" "iso/iso.toml")
# ==============================================================================
# RUN TARGETS (ISO in QEMU-VM starten)
# ==============================================================================
# Run a virtual machine with the specified image type and configuration
_run-vm $target_image $tag $type $config:
#!/usr/bin/bash
set -eoux pipefail
image_file="output/${type}/disk.${type}"
if [[ $type == iso ]]; then
image_file="output/bootiso/install.iso"
fi
if [[ ! -f "${image_file}" ]]; then
just "build-${type}" "$target_image" "$tag"
fi
port=8006
while grep -q :${port} <<< $(ss -tunalp); do
port=$(( port + 1 ))
done
echo "Using Port: ${port}"
echo "Connect to http://localhost:${port}"
run_args=()
run_args+=(--rm --privileged)
run_args+=(--pull=newer)
run_args+=(--publish "127.0.0.1:${port}:8006")
run_args+=(--env "CPU_CORES=4")
run_args+=(--env "RAM_SIZE=8G")
run_args+=(--env "DISK_SIZE=64G")
run_args+=(--env "TPM=Y")
run_args+=(--env "GPU=Y")
run_args+=(--device=/dev/kvm)
run_args+=(--volume "${PWD}/${image_file}":"/boot.${type}")
run_args+=(docker.io/qemux/qemu)
(sleep 30 && xdg-open http://localhost:"$port") &
podman run "${run_args[@]}"
# Run a virtual machine from an ISO
[group('Run Virtual Machine')]
run-vm-iso $target_image=(registry + "/" + image_name) $tag=default_tag: && (_run-vm target_image tag "iso" "iso/iso.toml")
# Runs shell check on all Bash scripts
lint:
#!/usr/bin/env bash
set -eoux pipefail
if ! command -v shellcheck &> /dev/null; then
echo "shellcheck could not be found. Please install it."
exit 1
fi
/usr/bin/find . -iname "*.sh" -type f -exec shellcheck "{}" ';'
# Runs shfmt on all Bash scripts
format:
#!/usr/bin/env bash
set -eoux pipefail
if ! command -v shfmt &> /dev/null; then
echo "shfmt could not be found. Please install it."
exit 1
fi
/usr/bin/find . -iname "*.sh" -type f -exec shfmt --write "{}" ';'