📦 mockbuild: Create 'latest' repo for branch

Allow anyone to set up a dnf repository to point to the latest
build for the branch by using a repo file pointing to that build.

This would allow anyone to get the latest set of RPMs for a particular
pull request or branch (especially the master branch.

Signed-off-by: Major Hayden <major@redhat.com>
This commit is contained in:
Major Hayden 2020-07-29 11:30:20 -05:00 committed by Ondřej Budai
parent 484bb9a182
commit 17075cffa0

View file

@ -27,7 +27,7 @@ fi
# Install requirements for building RPMs in mock.
greenprint "📦 Installing mock requirements"
sudo dnf -y install createrepo_c make mock python3-pip rpm-build
sudo dnf -y install createrepo_c make mock python3-pip rpm-build rsync
# Install s3cmd if it is not present.
if ! s3cmd --version > /dev/null 2>&1; then
@ -56,6 +56,10 @@ MOCK_REPO_BASE_URL="http://osbuild-composer-repos.s3-website.us-east-2.amazonaws
# Directory to hold the RPMs temporarily before we upload them.
REPO_DIR=repo/${JOB_NAME}/${POST_MERGE_SHA}/${ID}${VERSION_ID//./}_${ARCH}
# Maintain a directory for the master branch that always contains the latest
# RPM packages.
REPO_DIR_LATEST=repo/${JOB_NAME}/latest/${ID}${VERSION_ID//./}_${ARCH}
# Full URL to the RPM repository after they are uploaded.
REPO_URL=${MOCK_REPO_BASE_URL}/${JOB_NAME}/${POST_MERGE_SHA}/${ID}${VERSION_ID//./}_${ARCH}
@ -86,7 +90,9 @@ fi
greenprint "🎁 Building RPMs with mock"
sudo mock -v -r $MOCK_CONFIG --resultdir $REPO_DIR --with=tests \
rpmbuild/SRPMS/*.src.rpm osbuild/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%%/*}
# Move the logs out of the way.
greenprint "🧹 Retaining logs from mock build"
@ -96,6 +102,14 @@ mv ${REPO_DIR}/*.log $WORKSPACE
greenprint "⛓️ Creating dnf repository"
createrepo_c ${REPO_DIR}
# Copy the current build to the latest directory.
mkdir -p $REPO_DIR_LATEST
rsync -a ${REPO_DIR}/ ${REPO_DIR_LATEST}/
# Remove the previous latest build for this branch.
# Don't fail if the path is missing.
s3cmd --recursive rm s3://${REPO_BUCKET}/${JOB_NAME}/latest/${ID}${VERSION_ID//./}_${ARCH} || true
# Upload repository to S3.
greenprint "☁ Uploading RPMs to S3"
pushd repo