Use rpm-ostree compose image on Fedora Server

This commit is contained in:
Jeffrey Serio 2024-02-28 18:38:48 -06:00
parent a553eda122
commit 0df8a00eb2

View File

@ -45,15 +45,6 @@ function log_struc_error() {
} }
# Ensure dependencies are installed # Ensure dependencies are installed
if ! test -f "/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-${RELVER}-x86_64"; then
if ! dnf install -y distribution-gpg-keys; then
log_struc_error "Error installing distribution-gpg-keys" status "$?"
exit 1
fi
rsync -aAX /usr/share/distribution-gpg-keys/fedora/ /etc/pki/rpm-gpg
ln -sf "/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-${RELVER}-primary" "/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-${RELVER}-x86_64"
fi
if ! dnf install -y ostree podman rpm-ostree; then if ! dnf install -y ostree podman rpm-ostree; then
log_struc_error "Error installing ostree, podman, and rpm-ostree" status "$?" log_struc_error "Error installing ostree, podman, and rpm-ostree" status "$?"
exit 1 exit 1
@ -104,26 +95,6 @@ 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}" 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}" 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 "$?"
exit 1
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 "$?"
exit 1
fi
# Get commit ID
log_info "Get commit ID"
OSTREE_BRANCH=$(jq ."ref" "${TREEFILE}" | tr -d '"')
COMMIT_ID=$(ostree --repo="${BUILD_REPO}" rev-parse "${OSTREE_BRANCH}")
# Login to registry # Login to registry
log_struc_info "Login to registry" registry "${REGISTRY}" log_struc_info "Login to registry" registry "${REGISTRY}"
if ! podman login -p "${REGISTRY_PASSWD}" -u "${REGISTRY_USER}"; then if ! podman login -p "${REGISTRY_PASSWD}" -u "${REGISTRY_USER}"; then
@ -131,9 +102,9 @@ if ! podman login -p "${REGISTRY_PASSWD}" -u "${REGISTRY_USER}"; then
exit 1 exit 1
fi fi
# Compose container image and push to registry # Compose ostree base image and push to registry
log_struc_info "Compose container image from commit" commit "${COMMIT_ID}" log_struc_info "Compose ostree base image and push to registry" treefile "${TREEFILE}" registry "${REGISTRY}"
if ! ostree container encapsulate --repo="${BUILD_REPO}" "${OSTREE_BRANCH}" "docker://${REGISTRY}/fedora-atomic/vauxite-build/vauxite:${RELVER}"; then if ! rpm-ostree compose image --cachedir "${CACHE_DIR}" -i --initialize-mode=if-not-exists --format=registry "${TREEFILE}" "${REGISTRY}/fedora-atomic/vauxite-build/vauxite:${RELVER}"; then
log_struc_error "Error composing container image" status "$?" log_struc_error "Error composing ostree and/or pushing to registry" status "$?"
exit 1 exit 1
fi fi