vauxite-build/ostree-engine

113 lines
3.6 KiB
Plaintext
Raw Permalink Normal View History

2024-02-09 19:30:31 +01:00
#!/usr/bin/env bash
set -euo pipefail
2024-02-10 04:03:50 +01:00
CLEAN_BUILD=""
RELVER="39"
2024-02-09 19:30:31 +01:00
SOURCE_URL="https://pagure.io/workstation-ostree-config"
OSTREE_FILES_DIR="$(pwd)/src"
CACHE_DIR="$(pwd)/.cache"
BUILD_REPO="$(pwd)/.build-repo"
SOURCE_REPO="$(pwd)/.source-repo"
TMP_WORK_DIR="$(pwd)/.tmp"
TREEFILE="${TMP_WORK_DIR}/vauxite.json"
REGISTRY="git.hyperreal.coffee:5050"
REGISTRY_PASSWD="$(cat /home/jas/.vauxite-build-registry-token)"
REGISTRY_USER="hyperreal"
2024-02-09 19:30:31 +01:00
if [ "$(id -u)" != "0" ]; then
echo "Please run build with sudo"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi
# Ensure gum is installed
if ! test -x "$(command -v gum)"; then
2024-02-29 01:45:03 +01:00
cat <<EOF > /etc/yum.repos.d/charm.repo
[charm]
name=Charm
baseurl=https://repo.charm.sh/yum/
enabled=1
gpgcheck=1
gpgkey=https://repo.charm.sh/yum/gpg.key
EOF
dnf install -y gum
fi
# Helper functions
2024-02-09 19:30:31 +01:00
function log_struc_info() {
gum log --time datetime --structured --level info "$@"
}
function log_info() {
gum log --time datetime --level info "$@"
}
function log_struc_error() {
gum log --time datetime --structured --level error "$@"
}
# Ensure dependencies are installed
if ! dnf install -y ostree podman rpm-ostree; then
log_struc_error "Error installing ostree, podman, and rpm-ostree" status "$?"
exit 1
fi
2024-02-09 19:30:31 +01:00
# Clean working directory
log_struc_info "Clean cache directory" directory "${CACHE_DIR}"
rm -rf "${CACHE_DIR}"
log_struc_info "Clean source repo" directory "${SOURCE_REPO}"
rm -rf "${SOURCE_REPO}"
log_struc_info "Clean temporary working directory" directory "${TMP_WORK_DIR}"
rm -rf "${TMP_WORK_DIR}"
log_struc_info "Clean /tmp/rpmostree*" files /tmp/rpmostree*
rm -rf /tmp/rpmostree*
2024-02-10 04:03:50 +01:00
if [ -n "${CLEAN_BUILD}" ]; then
log_struc_info "Clean build repo" directory "${BUILD_REPO}"
rm -rf "${BUILD_REPO}"
fi
2024-02-09 19:30:31 +01:00
# Prepare build env
log_struc_info "Ensure cache directory exists" directory "${CACHE_DIR}"
mkdir -p "${CACHE_DIR}"
log_struc_info "Ensure temporary working directory exists" directory "${TMP_WORK_DIR}"
mkdir -p "${TMP_WORK_DIR}"
2024-02-10 04:03:50 +01:00
if [ ! -d "${BUILD_REPO}/objects" ]; then
log_info "Previous build repo not found. Initialize new build repo in archive mode"
2024-02-09 19:30:31 +01:00
if ! ostree --repo="${BUILD_REPO}" init --mode=archive; then
2024-02-10 04:03:50 +01:00
log_struc_error "Error initializing new build repo in archive mode" status "$?"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi
fi
log_struc_info "Clone source repo" url "${SOURCE_URL}" branch "f${RELVER}" directory "${SOURCE_REPO}"
if ! git clone -b "f${RELVER}" "${SOURCE_URL}" "${SOURCE_REPO}"; then
2024-02-09 19:30:31 +01:00
log_struc_error "Error cloning source repo" status "$?"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi
log_struc_info "Copy contents of source repo into temporary work directory" source_repo "${SOURCE_REPO}" directory "${TMP_WORK_DIR}"
rsync -aAX "${SOURCE_REPO}"/ "${TMP_WORK_DIR}"
log_struc_info "Copy contents of ostree files directory into temporary work directory" source "${OSTREE_FILES_DIR}" dest "${TMP_WORK_DIR}"
rsync -aAX "${OSTREE_FILES_DIR}"/ "${TMP_WORK_DIR}"
# Login to registry
log_struc_info "Login to registry" registry "${REGISTRY}"
if ! podman login -p "${REGISTRY_PASSWD}" -u "${REGISTRY_USER}"; then
log_struc_error "Error logging into container registry" registry "${REGISTRY}" user "${REGISTRY_USER}" passwd "${REGISTRY_PASSWD}" status "$?"
exit 1
fi
# Compose ostree base image and push to registry
log_struc_info "Compose ostree base image and push to registry" treefile "${TREEFILE}" registry "${REGISTRY}"
2024-02-29 01:45:03 +01:00
if ! rpm-ostree compose image --cachedir "${CACHE_DIR}" --initialize-mode=if-not-exists --format=registry "${TREEFILE}" "${REGISTRY}/fedora-atomic/vauxite-build/vauxite:${RELVER}"; then
log_struc_error "Error composing ostree and/or pushing to registry" status "$?"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi