Build in a mock chroot first

Build the RPMs in a mock using a simple script so that ansible-osbuild
can focus fully on deployment rather than compiling RPMs.

Signed-off-by: Major Hayden <major@redhat.com>
This commit is contained in:
Major Hayden 2020-05-20 13:34:22 -05:00 committed by Tom Gundersen
parent 3c312b9bbd
commit d92a742f28
3 changed files with 122 additions and 11 deletions

46
schutzbot/Jenkinsfile vendored
View file

@ -1,6 +1,14 @@
pipeline {
agent none
environment {
// We upload build RPMs and repository files here.
OPENSHIFT_CONTAINER = "osbuildci-artifacts"
// The files we upload are available under this URL.
// This is auto-generated from OpenStack.
MOCK_REPO_BASE_URL = "https://rhos-d.infra.prod.upshift.rdu2.redhat.com:13808/v1/AUTH_95e858620fb34bcc9162d9f52367a560/osbuildci-artifacts"
}
options {
timestamps()
ansiColor('xterm')
@ -12,7 +20,45 @@ pipeline {
}
stages {
stage("Mock") {
// Halt the entire pipeline if a single RPM build fails. That
// could indicate a code problem that needs to be investigated.
failFast true
parallel {
stage('Fedora 31') {
agent { label "fedora31" }
environment {
OPENSTACK_CREDS = credentials('psi-openstack-clouds-yaml')
}
steps {
sh "schutzbot/mockbuild.sh"
}
}
stage('Fedora 32') {
agent { label "fedora32" }
environment {
OPENSTACK_CREDS = credentials('psi-openstack-clouds-yaml')
}
steps {
sh "schutzbot/mockbuild.sh"
}
}
stage('RHEL 8.2') {
agent { label "rhel82" }
environment {
OPENSTACK_CREDS = credentials('psi-openstack-clouds-yaml')
}
steps {
sh "schutzbot/mockbuild.sh"
}
}
}
}
stage("Functional Testing") {
// Allow the other stages to finish if a single stage fails.
failFast false
parallel {
stage('Fedora 31 base') {
agent { label "fedora31" }

53
schutzbot/mockbuild.sh Executable file
View file

@ -0,0 +1,53 @@
#!/bin/bash
set -euxo pipefail
# 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//./}
# Build source RPMs.
make srpm
make -C osbuild srpm
# Fix RHEL 8 mock template.
sudo curl --retry 5 -Lsko /etc/mock/templates/rhel-8.tpl \
https://gitlab.cee.redhat.com/snippets/2208/raw
# Add fastestmirror to the Fedora template.
sudo sed -i '/^install_weak_deps.*/a fastestmirror=1' \
/etc/mock/templates/fedora-branched.tpl
# Compile RPMs in a mock chroot
sudo mock -r $MOCK_CONFIG --no-bootstrap-chroot \
--resultdir $REPO_DIR --with=tests \
rpmbuild/SRPMS/*.src.rpm osbuild/rpmbuild/SRPMS/*.src.rpm
sudo chown -R $USER ${REPO_DIR}
# Move the logs out of the way.
mv ${REPO_DIR}/*.log $WORKSPACE
# Create a repo of the built RPMs.
createrepo_c ${REPO_DIR}
# Prepare to upload to swift.
mkdir -p ~/.config/openstack
cp $OPENSTACK_CREDS ~/.config/openstack/clouds.yml
export OS_CLOUD=psi
# Upload repository to swift.
pushd repo
find * -type f -print | xargs openstack object create -f value $CONTAINER
popd

View file

@ -1,6 +1,23 @@
#!/bin/bash
set -euxo pipefail
# Get OS details.
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.
dnf list all | grep osbuild-mock
# Create temporary directories for Ansible.
sudo mkdir -vp /opt/ansible_{local,remote}
sudo chmod -R 777 /opt/ansible_{local,remote}
@ -21,25 +38,20 @@ trap "preserve_journal" ERR
# Write a simple hosts file for Ansible.
echo -e "[test_instances]\nlocalhost ansible_connection=local" > hosts.ini
# Set Ansible's config file location.
export ANSIBLE_CONFIG=ansible-osbuild/ansible.cfg
# Get the SHA of osbuild-composer which Jenkins checked out for us.
OSBUILD_COMPOSER_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
# Jenkins. We use ${WORKSPACE} below to tell ansible-osbuild to use the clone
# that Jenkins made for testing osbuild-composer.
# Deploy osbuild/osbuild-composer via the repository we created.
export ANSIBLE_CONFIG=ansible-osbuild/ansible.cfg
git clone https://github.com/osbuild/ansible-osbuild.git ansible-osbuild
ansible-playbook \
-i hosts.ini \
-e osbuild_composer_repo_url=${WORKSPACE} \
-e osbuild_composer_version=${OSBUILD_COMPOSER_VERSION} \
-e install_source=mock \
-e install_source=os \
ansible-osbuild/playbook.yml
# Ensure the testing package is installed.
sudo dnf -y install osbuild-composer-tests
# Run the tests.
ansible-playbook \
-e workspace=${WORKSPACE} \