CI: Store RPMs by SHA

This commit brings over updates for mock builds from osbuild-composer.

Signed-off-by: Major Hayden <major@redhat.com>
This commit is contained in:
Major Hayden 2020-06-01 07:50:48 -05:00 committed by David Rheinsberg
parent f19effd70a
commit e7b480895f
3 changed files with 69 additions and 25 deletions

28
schutzbot/Jenkinsfile vendored
View file

@ -28,6 +28,10 @@ pipeline {
}
steps {
sh "schutzbot/mockbuild.sh"
stash (
includes: 'osbuild-mock.repo',
name: 'fedora31'
)
}
}
stage('Fedora 32') {
@ -37,6 +41,10 @@ pipeline {
}
steps {
sh "schutzbot/mockbuild.sh"
stash (
includes: 'osbuild-mock.repo',
name: 'fedora32'
)
}
}
stage('RHEL 8 CDN') {
@ -46,6 +54,23 @@ pipeline {
}
steps {
sh "schutzbot/mockbuild.sh"
stash (
includes: 'osbuild-mock.repo',
name: 'rhel8cdn'
)
}
}
stage('RHEL 8.3 Nightly') {
agent { label "rhel83" }
environment {
OPENSTACK_CREDS = credentials('psi-openstack-clouds-yaml')
}
steps {
sh "schutzbot/mockbuild.sh"
stash (
includes: 'osbuild-mock.repo',
name: 'rhel83'
)
}
}
}
@ -59,6 +84,7 @@ pipeline {
agent { label "fedora31" }
environment { TEST_TYPE = "image" }
steps {
unstash 'fedora31'
run_tests()
}
post {
@ -71,6 +97,7 @@ pipeline {
agent { label "fedora32" }
environment { TEST_TYPE = "image" }
steps {
unstash 'fedora32'
run_tests()
}
post {
@ -83,6 +110,7 @@ pipeline {
agent { label "rhel8" }
environment { TEST_TYPE = "image" }
steps {
unstash 'rhel8cdn'
run_tests()
}
post {

View file

@ -1,22 +1,26 @@
#!/bin/bash
set -euxo pipefail
# Colorful output.
function greenprint {
echo -e "\033[1;32m${1}\033[0m"
}
# Get OS details.
source /etc/os-release
# Install packages.
sudo dnf -qy install createrepo_c mock
if [[ $ID == 'fedora' ]]; then
sudo dnf -qy install python3-openstackclient
else
sudo pip3 -qq install python-openstackclient
fi
# Set variables.
CONTAINER=osbuildci-artifacts
WORKSPACE=${WORKSPACE:-$(pwd)}
MOCK_CONFIG="${ID}-${VERSION_ID%.*}-$(uname -m)"
REPO_DIR=repo/${BUILD_TAG}/${ID}${VERSION_ID//./}
POST_MERGE_SHA=$(git rev-parse --short HEAD)
REPO_DIR=repo/${JOB_NAME}/${POST_MERGE_SHA}/${ID}${VERSION_ID//./}
REPO_URL=${MOCK_REPO_BASE_URL}/${JOB_NAME}/${POST_MERGE_SHA}/${ID}${VERSION_ID//./}
# Print some data.
greenprint "🧬 Using mock config: ${MOCK_CONFIG}"
greenprint "📦 Post merge SHA: ${POST_MERGE_SHA}"
greenprint "📤 RPMS will be uploaded to: ${REPO_URL}"
# Clone osbuild-composer.
# TODO(mhayden): After the next osbuild-composer release, use the latest tag
@ -26,27 +30,52 @@ REPO_DIR=repo/${BUILD_TAG}/${ID}${VERSION_ID//./}
git clone https://github.com/osbuild/osbuild-composer
# Build source RPMs.
greenprint "🔧 Building source RPMs."
make srpm
make -C osbuild-composer srpm
# Fix RHEL 8 mock template for non-subscribed images.
if [[ $NODE_NAME == *rhel8[23]* ]]; then
greenprint "📋 Updating RHEL 8 mock template for unsubscribed image"
sudo curl --retry 5 -Lsko /etc/mock/templates/rhel-8.tpl \
https://gitlab.cee.redhat.com/snippets/2208/raw
fi
# 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}
# Move the logs out of the way.
greenprint "🧹 Retaining logs from mock build"
mv ${REPO_DIR}/*.log $WORKSPACE
# Create a repo of the built RPMs.
greenprint "⛓️ Creating dnf repository"
createrepo_c ${REPO_DIR}
# Prepare to upload to swift.
greenprint "🛂 Setting up OpenStack authentication credentials"
mkdir -p ~/.config/openstack
cp $OPENSTACK_CREDS ~/.config/openstack/clouds.yml
export OS_CLOUD=psi
# Upload repository to swift.
greenprint "☁ Uploading RPMs to OpenStack object storage"
pushd repo
find * -type f -print | xargs openstack object create -f value $CONTAINER
popd
popd
# Create a repository file.
greenprint "📜 Generating dnf repository file"
tee osbuild-mock.repo << EOF
[osbuild-mock]
name=osbuild mock ${JOB_NAME}-${POST_MERGE_SHA} ${ID}${VERSION_ID//./}
baseurl=${REPO_URL}
enabled=1
gpgcheck=0
# Default dnf repo priority is 99. Lower number means higher priority.
priority=5
EOF

View file

@ -5,18 +5,8 @@ set -euxo pipefail
source /etc/os-release
# Set up a dnf repository for the RPMs we built via mock.
sudo tee /etc/yum.repos.d/osbuild-mock.repo > /dev/null << EOF
[osbuild-mock]
name=osbuild mock ${BUILD_TAG} ${ID}${VERSION_ID//./}
baseurl=${MOCK_REPO_BASE_URL}/${BUILD_TAG}/${ID}${VERSION_ID//./}
enabled=1
gpgcheck=0
# Default dnf repo priority is 99. Lower number means higher priority.
priority=5
EOF
# Verify that the repository we added is working properly.
sudo dnf list all | grep osbuild-mock
sudo cp osbuild-mock.repo /etc/yum.repos.d/osbuild-mock.repo
dnf repository-packages osbuild-mock list
# Create temporary directories for Ansible.
sudo mkdir -vp /opt/ansible_{local,remote}
@ -38,9 +28,6 @@ trap "preserve_journal" ERR
# Write a simple hosts file for Ansible.
echo -e "[test_instances]\nlocalhost ansible_connection=local" > hosts.ini
# Get the SHA of osbuild which Jenkins checked out for us.
OSBUILD_VERSION=$(git rev-parse HEAD)
# Deploy osbuild-composer and osbuild using RPMs built in a mock chroot.
# NOTE(mhayden): Jenkins clones the repository and then merges the code from
# the pull request into the repo. This creates a new SHA that exists only in