The length of these is not predictable. It depends on the shortest unique prefix in the repository and git configuration. Just use the full one, which also makes it easier to copy the id from `git log` or GitHub.
104 lines
3.1 KiB
Bash
Executable file
104 lines
3.1 KiB
Bash
Executable file
#!/bin/bash
|
||
set -euo pipefail
|
||
|
||
# Colorful output.
|
||
function greenprint {
|
||
echo -e "\033[1;32m${1}\033[0m"
|
||
}
|
||
|
||
# Get OS details.
|
||
source /etc/os-release
|
||
ARCH=$(uname -m)
|
||
|
||
# mock and s3cmd are only available in EPEL for RHEL.
|
||
if [[ $ID == rhel ]]; then
|
||
greenprint "📦 Setting up EPEL repository"
|
||
curl -Ls --retry 5 --output /tmp/epel.rpm \
|
||
https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
|
||
sudo rpm -Uvh /tmp/epel.rpm
|
||
fi
|
||
|
||
# Register RHEL if we are provided with a registration script.
|
||
if [[ -n "${RHN_REGISTRATION_SCRIPT:-}" ]] && ! sudo subscription-manager status; then
|
||
greenprint "🪙 Registering RHEL instance"
|
||
sudo chmod +x $RHN_REGISTRATION_SCRIPT
|
||
sudo $RHN_REGISTRATION_SCRIPT
|
||
fi
|
||
|
||
# Install requirements for building RPMs in mock.
|
||
greenprint "📦 Installing mock requirements"
|
||
sudo dnf -y install createrepo_c make mock python3-pip rpm-build s3cmd
|
||
|
||
# Enable fastestmirror for mock on Fedora.
|
||
if [[ $ID == fedora ]]; then
|
||
sudo sed -i '/^install_weak_deps=.*/a fastestmirror=1' \
|
||
/etc/mock/templates/fedora-branched.tpl
|
||
fi
|
||
|
||
# Mock configuration file to use for building RPMs.
|
||
MOCK_CONFIG="${ID}-${VERSION_ID%.*}-$(uname -m)"
|
||
|
||
# The commit this script operates on.
|
||
COMMIT=$(git rev-parse HEAD)
|
||
|
||
# Bucket in S3 where our artifacts are uploaded
|
||
REPO_BUCKET=osbuild-composer-repos
|
||
|
||
# Public URL for the S3 bucket with our artifacts.
|
||
MOCK_REPO_BASE_URL="http://osbuild-composer-repos.s3-website.us-east-2.amazonaws.com"
|
||
|
||
# Relative path of the repository – used for constructing both the local and
|
||
# remote paths below, so that they're consistent.
|
||
REPO_PATH=osbuild/${ID}-${VERSION_ID}/${ARCH}/${COMMIT}
|
||
|
||
# Directory to hold the RPMs temporarily before we upload them.
|
||
REPO_DIR=repo/${REPO_PATH}
|
||
|
||
# Full URL to the RPM repository after they are uploaded.
|
||
REPO_URL=${MOCK_REPO_BASE_URL}/${REPO_PATH}
|
||
|
||
# Print some data.
|
||
greenprint "🧬 Using mock config: ${MOCK_CONFIG}"
|
||
greenprint "📦 SHA: ${COMMIT}"
|
||
greenprint "📤 RPMS will be uploaded to: ${REPO_URL}"
|
||
|
||
# Build source RPMs.
|
||
greenprint "🔧 Building source RPMs."
|
||
make srpm
|
||
git clone --quiet https://github.com/osbuild/osbuild-composer osbuild-composer
|
||
make -C osbuild-composer srpm
|
||
|
||
# Compile RPMs in a mock chroot
|
||
greenprint "🎁 Building RPMs with mock"
|
||
sudo mock -r $MOCK_CONFIG --no-bootstrap-chroot \
|
||
--resultdir $REPO_DIR --with=tests \
|
||
rpmbuild/SRPMS/*.src.rpm osbuild-composer/rpmbuild/SRPMS/*.src.rpm
|
||
sudo chown -R $USER ${REPO_DIR}
|
||
|
||
# Change the ownership of all of our repo files from root to our CI user.
|
||
sudo chown -R $USER ${REPO_DIR%%/*}
|
||
|
||
greenprint "🧹 Remove logs from mock build"
|
||
rm ${REPO_DIR}/*.log
|
||
|
||
# Create a repo of the built RPMs.
|
||
greenprint "⛓️ Creating dnf repository"
|
||
createrepo_c ${REPO_DIR}
|
||
|
||
# Upload repository to S3.
|
||
greenprint "☁ Uploading RPMs to S3"
|
||
pushd repo
|
||
s3cmd --acl-public sync . s3://${REPO_BUCKET}/
|
||
popd
|
||
|
||
# Create a repository file.
|
||
greenprint "📜 Generating dnf repository file"
|
||
tee osbuild-mock.repo << EOF
|
||
[osbuild-mock]
|
||
name=osbuild mock ${COMMIT}
|
||
baseurl=${REPO_URL}
|
||
enabled=1
|
||
gpgcheck=0
|
||
# Default dnf repo priority is 99. Lower number means higher priority.
|
||
priority=5
|
||
EOF
|