vauxite-build/ostree-engine

102 lines
3.4 KiB
Plaintext
Raw 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=""
2024-02-09 19:30:31 +01:00
SOURCE_BRANCH="f39"
SOURCE_URL="https://pagure.io/workstation-ostree-config"
DEST_REPO="/srv/repo"
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"
if [ "$(id -u)" != "0" ]; then
gum log --time datetime --level error "Please run build with sudo"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi
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 "$@"
}
# 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 "${SOURCE_BRANCH}" directory "${SOURCE_REPO}"
if ! git clone -b "${SOURCE_BRANCH}" "${SOURCE_URL}" "${SOURCE_REPO}"; then
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 "Remove upstream xfce-desktop-pkgs.yaml from temporary work directory" file xfce-desktop-pkgs.yaml directory "${TMP_WORK_DIR}"
rm -f "${TMP_WORK_DIR}"/xfce-desktop-pkgs.yaml
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}"
# Compose ostree
METADATA_STR="$(date '+%Y-%m-%dT%H%M%S')"
log_struc_info "Compose ostree" cachedir "${CACHE_DIR}" repo "${BUILD_REPO}" metadata-string "${METADATA_STR}" treefile "${TREEFILE}"
if ! rpm-ostree compose tree --unified-core --cachedir="${CACHE_DIR}" --repo="${BUILD_REPO}" --add-metadata-string=Build="${METADATA_STR}" "${TREEFILE}"; then
log_struc_error "Error composing ostree" status "$?"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi
# Prepare deploy
log_info "Prune refs older than 30 days"
if ! ostree --repo="${BUILD_REPO}" prune --refs-only --keep-younger-than='30 days ago'; then
log_struc_error "Error pruning refs" status "$?"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi
# Deploy
2024-02-10 04:03:50 +01:00
log_struc_info "Deploy to web server" build_repo "${BUILD_REPO}" dest_repo "${DEST_REPO}"
if ! "$(pwd)/rsync-repos" --src "${BUILD_REPO}" --dest "${DEST_REPO}"; then
2024-02-09 19:30:31 +01:00
log_struc_error "Error deploying to web server" status "$?"
2024-02-10 01:25:23 +01:00
exit 1
2024-02-09 19:30:31 +01:00
fi