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=""
|
2024-02-28 15:02:07 +01:00
|
|
|
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"
|
2024-02-28 15:02:07 +01:00
|
|
|
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
|
2024-02-28 15:02:07 +01:00
|
|
|
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
|
|
|
|
|
2024-02-28 15:02:07 +01:00
|
|
|
# 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
|
2024-02-28 15:02:07 +01:00
|
|
|
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 "$@"
|
|
|
|
}
|
|
|
|
|
2024-02-28 15:02:07 +01:00
|
|
|
# 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
|
|
|
|
|
2024-02-28 15:02:07 +01:00
|
|
|
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}"
|
|
|
|
|
2024-02-28 15:02:07 +01:00
|
|
|
# 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
|
|
|
|
|
2024-02-29 01:38:48 +01:00
|
|
|
# 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
|
2024-02-29 01:38:48 +01:00
|
|
|
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
|