mirror of
https://codeberg.org/hyperreal/vauxite-build
synced 2024-11-01 08:43:13 +01:00
113 lines
3.6 KiB
Bash
Executable File
113 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
CLEAN_BUILD=""
|
|
RELVER="39"
|
|
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"
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
echo "Please run build with sudo"
|
|
exit 1
|
|
fi
|
|
|
|
# Ensure gum is installed
|
|
if ! test -x "$(command -v gum)"; then
|
|
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
|
|
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
|
|
|
|
# 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*
|
|
|
|
if [ -n "${CLEAN_BUILD}" ]; then
|
|
log_struc_info "Clean build repo" directory "${BUILD_REPO}"
|
|
rm -rf "${BUILD_REPO}"
|
|
fi
|
|
|
|
# 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}"
|
|
|
|
if [ ! -d "${BUILD_REPO}/objects" ]; then
|
|
log_info "Previous build repo not found. Initialize new build repo in archive mode"
|
|
if ! ostree --repo="${BUILD_REPO}" init --mode=archive; then
|
|
log_struc_error "Error initializing new build repo in archive mode" status "$?"
|
|
exit 1
|
|
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
|
|
log_struc_error "Error cloning source repo" status "$?"
|
|
exit 1
|
|
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}"
|
|
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 "$?"
|
|
exit 1
|
|
fi
|