diff options
| author | James Reilly <jreilly1821@gmail.com> | 2025-03-12 22:07:17 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-12 12:37:17 -0400 |
| commit | a4833543c88aa3fa791302666cafe72b12d57735 (patch) | |
| tree | 956b688f148ba5565b4569a4f3598d8d9c50efc8 | |
| parent | 4e461eccd9813a485093db1ff85a27cfd0410672 (diff) | |
| download | AeroCore-OS-a4833543c88aa3fa791302666cafe72b12d57735.tar.gz AeroCore-OS-a4833543c88aa3fa791302666cafe72b12d57735.zip | |
Fix: Update Justfile (#76)
* Fix: Update Justfile
Updated to match the Bluefin LTS one. Stripped the iso customizations stuff
* fix: update Containerfile
ublue-os/silverblue-main:latest shouldn't be the default
| -rw-r--r-- | Containerfile | 4 | ||||
| -rw-r--r-- | Justfile | 205 |
2 files changed, 169 insertions, 40 deletions
diff --git a/Containerfile b/Containerfile index 67bd49c..80b04aa 100644 --- a/Containerfile +++ b/Containerfile @@ -1,7 +1,7 @@ -FROM ghcr.io/ublue-os/silverblue-main:latest +FROM ghcr.io/ublue-os/bazzite:stable ## Other possible base images include: -# FROM ghcr.io/ublue-os/bazzite:stable +# FROM ghcr.io/ublue-os/bazzite:latest # FROM ghcr.io/ublue-os/bluefin-nvidia:stable # # ... and so on, here are more base images @@ -1,12 +1,10 @@ export repo_organization := env("GITHUB_REPOSITORY_OWNER", "yourname") export image_name := env("IMAGE_NAME", "yourimage") +export centos_version := env("CENTOS_VERSION", "stream10") +export fedora_version := env("CENTOS_VERSION", "41") export default_tag := env("DEFAULT_TAG", "latest") export bib_image := env("BIB_IMAGE", "quay.io/centos-bootc/bootc-image-builder:latest") -export SUDO_DISPLAY := if `if [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; then echo true; fi` == "true" { "true" } else { "false" } -export SUDOIF := if `id -u` == "0" { "" } else { if SUDO_DISPLAY == "true" { "sudo --askpass" } else { "sudo" } } -export PODMAN := if path_exists("/usr/bin/podman") == "true" { env("PODMAN", "/usr/bin/podman") } else { if path_exists("/usr/bin/docker") == "true" { env("PODMAN", "docker") } else { env("PODMAN", "exit 1 ; ") } } - alias build-vm := build-qcow2 alias rebuild-vm := rebuild-qcow2 alias run-vm := run-vm-qcow2 @@ -52,54 +50,136 @@ clean: [group('Utility')] [private] sudo-clean: - ${SUDOIF} just clean + just sudoif just clean -build $target_image=image_name $tag=default_tag: +# 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 }} + +# This Justfile recipe builds a container image using Podman. +# +# Arguments: +# $target_image - The tag you want to apply to the image (default: aurora). +# $tag - The tag for the image (default: lts). +# $dx - Enable DX (default: "0"). +# $hwe - Enable HWE (default: "0"). +# $gdx - Enable GDX (default: "0"). +# +# DX: +# Developer Experience (DX) is a feature that allows you to install the latest developer tools for your system. +# Packages include VScode, Docker, Distrobox, and more. +# HWE: +# Hardware Enablement (HWE) is a feature that allows you to install the latest hardware support for your system. +# Currently this install the Hyperscale SIG kernel which will stay ahead of the CentOS Stream kernel and enables btrfs +# GDX: https://docs.projectaurora.io/gdx/ +# GPU Developer Experience (GDX) creates a base as an AI and Graphics platform. +# Installs Nvidia drivers, CUDA, and other tools. +# +# The script constructs the version string using the tag and the current date. +# If the git working directory is clean, it also includes the short SHA of the current HEAD. +# +# just build $target_image $tag $dx $hwe $gdx +# +# Example usage: +# just build aurora lts 1 0 1 +# +# This will build an image 'aurora:lts' with DX and GDX enabled. +# + +# Build the image using the specified parameters +build $target_image=image_name $tag=default_tag $dx="0" $hwe="0" $gdx="0": #!/usr/bin/env bash # Get Version - ver="${tag}-$(date +%Y%m%d)" + ver="${tag}-${centos_version}.$(date +%Y%m%d)" BUILD_ARGS=() + BUILD_ARGS+=("--build-arg" "MAJOR_VERSION=${centos_version}") BUILD_ARGS+=("--build-arg" "IMAGE_NAME=${image_name}") BUILD_ARGS+=("--build-arg" "IMAGE_VENDOR=${repo_organization}") + BUILD_ARGS+=("--build-arg" "ENABLE_DX=${dx}") + BUILD_ARGS+=("--build-arg" "ENABLE_HWE=${hwe}") + BUILD_ARGS+=("--build-arg" "ENABLE_GDX=${gdx}") if [[ -z "$(git status -s)" ]]; then BUILD_ARGS+=("--build-arg" "SHA_HEAD_SHORT=$(git rev-parse --short HEAD)") fi - ${PODMAN} build \ + podman build \ "${BUILD_ARGS[@]}" \ --pull=newer \ - --tag "${image_name}:${tag}" \ + --tag "${target_image}:${tag}" \ . +# Command: _rootful_load_image +# Description: This script checks if the current user is root or running under sudo. If not, it attempts to resolve the image tag using podman inspect. +# If the image is found, it loads it into rootful podman. If the image is not found, it pulls it from the repository. +# +# Parameters: +# $target_image - The name of the target image to be loaded or pulled. +# $tag - The tag of the target image to be loaded or pulled. Default is 'default_tag'. +# +# Example usage: +# _rootful_load_image my_image latest +# +# Steps: +# 1. Check if the script is already running as root or under sudo. +# 2. Check if target image is in the non-root podman container storage) +# 3. If the image is found, load it into rootful podman using podman scp. +# 4. If the image is not found, pull it from the remote repository into reootful podman. + _rootful_load_image $target_image=image_name $tag=default_tag: #!/usr/bin/bash set -eoux pipefail + # Check if already running as root or under sudo if [[ -n "${SUDO_USER:-}" || "${UID}" -eq "0" ]]; then - echo "Already root or running under sudo, no need to load image from user ${PODMAN}." + echo "Already root or running under sudo, no need to load image from user podman." exit 0 fi + # Try to resolve the image tag using podman inspect set +e - resolved_tag=$(${PODMAN} inspect -t image "${target_image}:${tag}" | jq -r '.[].RepoTags.[0]') + resolved_tag=$(podman inspect -t image "${target_image}:${tag}" | jq -r '.[].RepoTags.[0]') return_code=$? set -e if [[ $return_code -eq 0 ]]; then - # Load into Rootful ${PODMAN} - ID=$(${SUDOIF} ${PODMAN} images --filter reference="${target_image}:${tag}" --format "'{{ '{{.ID}}' }}'") + # If the image is found, load it into rootful podman + ID=$(just sudoif podman images --filter reference="${target_image}:${tag}" --format "'{{ '{{.ID}}' }}'") if [[ -z "$ID" ]]; then + # If the image ID is not found, copy the image from user podman to root podman COPYTMP=$(mktemp -p "${PWD}" -d -t _build_podman_scp.XXXXXXXXXX) - ${SUDOIF} TMPDIR=${COPYTMP} ${PODMAN} image scp ${UID}@localhost::"${target_image}:${tag}" root@localhost::"${target_image}:${tag}" + just sudoif TMPDIR=${COPYTMP} podman image scp ${UID}@localhost::"${target_image}:${tag}" root@localhost::"${target_image}:${tag}" rm -rf "${COPYTMP}" fi else - # Make sure the image is present and/or up to date - ${SUDOIF} ${PODMAN} pull "${target_image}:${tag}" + # If the image is not found, pull it from the repository + just sudoif podman pull "${target_image}:${tag}" fi +# Build a bootc bootable image using Bootc Image Builder (BIB) +# Converts a container image to a bootable image +# Parameters: +# target_image: The name of the image to build (ex. localhost/fedora) +# tag: The tag of the image to build (ex. latest) +# type: The type of image to build (ex. qcow2, raw, iso) +# config: The configuration file to use for the build (default: image.toml) + +# Example: just _rebuild-bib localhost/fedora latest qcow2 image.toml _build-bib $target_image $tag $type $config: (_rootful_load_image target_image tag) #!/usr/bin/env bash set -euo pipefail @@ -113,13 +193,14 @@ _build-bib $target_image $tag $type $config: (_rootful_load_image target_image t sudo rm -rf "output/${type}" || true fi - args="--type ${type}" + args="--type ${type} " + args+="--use-librepo=True" if [[ $target_image == localhost/* ]]; then args+=" --local" fi - sudo ${PODMAN} run \ + sudo podman run \ --rm \ -it \ --privileged \ @@ -130,53 +211,70 @@ _build-bib $target_image $tag $type $config: (_rootful_load_image target_image t -v $(pwd)/output:/output \ -v /var/lib/containers/storage:/var/lib/containers/storage \ "${bib_image}" \ - --rootfs btrfs \ ${args} \ - "${target_image}" + "${target_image}:${tag}" sudo chown -R $USER:$USER output +# Podman builds the image from the Containerfile and creates a bootable image +# Parameters: +# target_image: The name of the image to build (ex. localhost/fedora) +# tag: The tag of the image to build (ex. latest) +# type: The type of image to build (ex. qcow2, raw, iso) +# config: The configuration file to use for the build (deafult: image.toml) + +# Example: just _rebuild-bib localhost/fedora latest qcow2 image.toml _rebuild-bib $target_image $tag $type $config: (build target_image tag) && (_build-bib target_image tag type config) -[group('Build Virtual Machine Image')] +# Build a QCOW2 virtual machine image +[group('Build Virtal Machine Image')] build-qcow2 $target_image=("localhost/" + image_name) $tag=default_tag: && (_build-bib target_image tag "qcow2" "image.toml") -[group('Build Virtual Machine Image')] +# Build a RAW virtual machine image +[group('Build Virtal Machine Image')] build-raw $target_image=("localhost/" + image_name) $tag=default_tag: && (_build-bib target_image tag "raw" "image.toml") -[group('Build Virtual Machine Image')] +# Build an ISO virtual machine image +[group('Build Virtal Machine Image')] build-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_build-bib target_image tag "iso" "iso.toml") -[group('Build Virtual Machine Image')] +# Rebuild a QCOW2 virtual machine image +[group('Build Virtal Machine Image')] rebuild-qcow2 $target_image=("localhost/" + image_name) $tag=default_tag: && (_rebuild-bib target_image tag "qcow2" "image.toml") -[group('Build Virtual Machine Image')] +# Rebuild a RAW virtual machine image +[group('Build Virtal Machine Image')] rebuild-raw $target_image=("localhost/" + image_name) $tag=default_tag: && (_rebuild-bib target_image tag "raw" "image.toml") -[group('Build Virtual Machine Image')] +# Rebuild an ISO virtual machine image +[group('Build Virtal Machine Image')] rebuild-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_rebuild-bib target_image tag "iso" "iso.toml") +# Run a virtual machine with the specified image type and configuration _run-vm $target_image $tag $type $config: #!/usr/bin/bash set -eoux pipefail + # Determine the image file based on the type image_file="output/${type}/disk.${type}" - if [[ $type == iso ]]; then image_file="output/bootiso/install.iso" fi + # Build the image if it does not exist if [[ ! -f "${image_file}" ]]; then just "build-${type}" "$target_image" "$tag" fi - # Determine which port to use - port=8006; + # Determine an available port to use + port=8006 while grep -q :${port} <<< $(ss -tunalp); do port=$(( port + 1 )) done echo "Using Port: ${port}" echo "Connect to http://localhost:${port}" + + # Set up the arguments for running the VM run_args=() run_args+=(--rm --privileged) run_args+=(--pull=newer) @@ -184,21 +282,52 @@ _run-vm $target_image $tag $type $config: run_args+=(--env "CPU_CORES=4") run_args+=(--env "RAM_SIZE=8G") run_args+=(--env "DISK_SIZE=64G") - # run_args+=(--env "BOOT_MODE=windows_secure") 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-docker) - ${PODMAN} run "${run_args[@]}" & + + # Run the VM and open the browser to connect + podman run "${run_args[@]}" & xdg-open http://localhost:${port} - fg "%${PODMAN}" + fg "%podman" + +# Run a virtual machine from a QCOW2 image +[group('Run Virtal Machine')] +run-vm-qcow2 $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "qcow2" "image.toml") + +# Run a virtual machine from a RAW image +[group('Run Virtal Machine')] +run-vm-raw $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "raw" "image.toml") + +# Run a virtual machine from an ISO +[group('Run Virtal Machine')] +run-vm-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "iso" "iso.toml") + +# Run a virtual machine using systemd-vmspawn +[group('Run Virtal Machine')] +spawn-vm rebuild="0" type="qcow2" ram="6G": + #!/usr/bin/env bash + + set -euo pipefail + + [ "{{ rebuild }}" -eq 1 ] && echo "Rebuilding the ISO" && just build-vm {{ rebuild }} {{ type }} + + systemd-vmspawn \ + -M "bootc-image" \ + --console=gui \ + --cpus=2 \ + --ram=$(echo {{ ram }}| /usr/bin/numfmt --from=iec) \ + --network-user-mode \ + --vsock=false --pass-ssh-key=false \ + -i ./output/**/*.{{ type }} -[group('Run Virtual Machine')] -run-vm-qcow2 $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "qcow2" "image-builder.config.toml") -[group('Run Virtual Machine')] -run-vm-raw $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "raw" "image-builder.config.toml") +# Runs shell check on all Bash scripts +lint: + /usr/bin/find . -iname "*.sh" -type f -exec shellcheck "{}" ';' -[group('Run Virtual Machine')] -run-vm-iso $target_image=("localhost/" + image_name) $tag=default_tag: && (_run-vm target_image tag "iso" "image-builder-iso.config.toml") +# Runs shfmt on all Bash scripts +format: + /usr/bin/find . -iname "*.sh" -type f -exec shfmt --write "{}" ';' |
