Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mockbuild: make more consistent with other osbuild projects #49

Merged
merged 8 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions koji-osbuild.spec.in → koji-osbuild.spec
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
%global commit @commit@
%global forgeurl https://github.com/osbuild/koji-osbuild

Name: koji-osbuild
Version: @version@
Version: 3
Release: 0%{?dist}
Summary: Koji integration for osbuild composer

Expand Down Expand Up @@ -152,5 +151,8 @@ Integration tests for koji-osbuild. To be run on a dedicated system.


%changelog
* @longdate@ osbuild <osbuilders@osbuild.org> - @version@-@reltag@
- build from git sources.
# the changelog is distribution-specific, therefore there's just one entry
# to make rpmlint happy.

* Tue Aug 25 2020 Image Builder team <osbuilders@osbuild.org> - 0-1
- On this day, this project was born.
41 changes: 10 additions & 31 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('koji-osbuild', license: 'ASL 2.0', version: '3')
project('koji-osbuild', license: 'ASL 2.0')

srcdir = meson.source_root()

Expand All @@ -16,33 +16,12 @@ install_data(
)

git = find_program('git')

subs = configuration_data()
subs.set('version', meson.project_version())

longdate = run_command('date', '+%a %b %d %Y').stdout().strip()
subs.set('longdate', longdate)

gitres = run_command(git, ['--git-dir=@0@/.git'.format(srcdir),
'rev-parse',
'--short=7',
'HEAD'])

if gitres.returncode() == 0
commit = gitres.stdout().strip()
subs.set('commit', commit)

gitrev = gitres.stdout().strip()
gitdate = run_command('date', '+%Y%m%d').stdout().strip()
# YYYYMMDD<scm><revision>
subs.set('reltag', '@0@git@1@'.format(gitdate, gitrev))
endif

spec_file = configure_file(
input: 'koji-osbuild.spec.in',
output: 'koji-osbuild.spec',
configuration: subs
gitres = run_command(
git,
['--git-dir=@0@/.git'.format(srcdir), 'rev-parse', 'HEAD'],
check=True
)
commit = gitres.stdout().strip()

archive_name = meson.project_name() + '-' + gitrev
full_archive_name = archive_name + '.tar.gz'
Expand Down Expand Up @@ -79,7 +58,8 @@ srpm_target = custom_target(
rpmbuild, '-bs',
spec_file,
'--define', '_sourcedir ' + meson.build_root(),
'--define', '_topdir ' + rpmdirs_target.full_path()
'--define', '_topdir ' + rpmdirs_target.full_path(),
'--define', 'commit ' + commit
],
output: 'srpms',
depends: [archive]
Expand All @@ -91,15 +71,14 @@ rpm_target = custom_target(
rpmbuild, '-ba',
spec_file,
'--define', '_sourcedir ' + meson.build_root(),
'--define', '_topdir ' + rpmdirs_target.full_path()
'--define', '_topdir ' + rpmdirs_target.full_path(),
'--define', 'commit ' + commit
],
output: 'rpms',
depends: [archive]
)

msg = ['',
'version: @0@'.format(meson.project_version()),
'',
'hub plugins path: @0@'.format(hub_plugins_path),
'builder plugins path: @0@'.format(builder_plugins_path),
'',
Expand Down
10 changes: 0 additions & 10 deletions schutzbot/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ pipeline {
retry(3) {
sh "schutzbot/mockbuild.sh"
}
stash (
includes: 'mock.repo',
name: 'fedora32'
)
}
}
stage('EL8') {
Expand All @@ -67,10 +63,6 @@ pipeline {
retry(3) {
sh "schutzbot/mockbuild.sh"
}
stash (
includes: 'mock.repo',
name: 'rhel8cdn'
)
}
}
}
Expand All @@ -86,7 +78,6 @@ pipeline {
AWS_CREDS = credentials('aws-credentials-osbuildci')
}
steps {
unstash 'fedora32'
run_tests('integration')
}
post {
Expand All @@ -103,7 +94,6 @@ pipeline {
RHN_REGISTRATION_SCRIPT = credentials('rhn-register-script-production')
}
steps {
unstash 'rhel8cdn'
run_tests('integration')
}
post {
Expand Down
13 changes: 9 additions & 4 deletions schutzbot/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ fi
# Add osbuild team ssh keys.
cat schutzbot/team_ssh_keys.txt | tee -a ~/.ssh/authorized_keys > /dev/null

# Set up a dnf repository for the RPMs we built via mock.
sudo cp mock.repo /etc/yum.repos.d/

# Set up dnf repositories with the RPMs we want to test
sudo tee /etc/yum.repos.d/osbuild.repo << EOF
[osbuild]
[koji-osbuild]
name=osbuild ${GIT_COMMIT}
baseurl=${DNF_REPO_BASEURL}/koji-osbuild/${ID}-${VERSION_ID}/${ARCH}/${GIT_COMMIT}
enabled=1
gpgcheck=0
# Default dnf repo priority is 99. Lower number means higher priority.
priority=5

[osbuild]
name=osbuild ${OSBUILD_COMMIT}
baseurl=${DNF_REPO_BASEURL}/osbuild/${ID}-${VERSION_ID}/${ARCH}/${OSBUILD_COMMIT}
enabled=1
gpgcheck=0
Expand Down
92 changes: 45 additions & 47 deletions schutzbot/mockbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,34 @@ function greenprint {
source /etc/os-release
ARCH=$(uname -m)

# Mock configuration file to use for building RPMs.
MOCK_CONFIG="${ID}-${VERSION_ID%.*}-$(uname -m)"

# The commit we are testing
GIT_SHA=$(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://${REPO_BUCKET}.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=koji-osbuild/${ID}-${VERSION_ID}/${ARCH}/${GIT_SHA}

# 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}

# Don't rerun the build if it already exists
if curl --silent --fail --head --output /dev/null "${REPO_URL}/repodata/repomd.xml"; then
greenprint "🎁 Repository already exists. Exiting."
exit 0
fi

# Mock is only available in EPEL for RHEL.
if [[ $ID == rhel ]] && ! rpm -q epel-release; then
greenprint "📦 Setting up EPEL repository"
Expand All @@ -27,75 +55,45 @@ fi

# Install requirements for building RPMs in mock.
greenprint "📦 Installing mock requirements"
sudo dnf -y install createrepo_c meson mock ninja-build python3-pip rpm-build
sudo dnf -y install createrepo_c mock python3-pip rpm-build

# Install s3cmd if it is not present.
if ! s3cmd --version > /dev/null 2>&1; then
greenprint "📦 Installing s3cmd"
sudo pip3 -q install s3cmd
fi

# Jenkins sets a workspace variable as the root of its working directory.
WORKSPACE=${WORKSPACE:-$(pwd)}

# Mock configuration file to use for building RPMs.
MOCK_CONFIG="${ID}-${VERSION_ID%.*}-$(uname -m)"

# The commit we are testing
GIT_SHA=$(git rev-parse --short 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://${REPO_BUCKET}.s3-website.us-east-2.amazonaws.com"

# Directory to hold the RPMs temporarily before we upload them.
REPO_DIR=koji-osbuild/${GIT_SHA}/${ID}${VERSION_ID//./}_${ARCH}

# Full URL to the RPM repository after they are uploaded.
REPO_URL=${MOCK_REPO_BASE_URL}/${REPO_DIR}

# Print some data.
greenprint "🧬 Using mock config: ${MOCK_CONFIG}"
greenprint "📦 Git SHA: ${GIT_SHA}"
greenprint "📤 RPMS will be uploaded to: ${REPO_URL}"

# Build source RPMs.
greenprint "🔧 Building source RPMs."
meson build
ninja -C build srpms
greenprint "🔧 Building source RPM"
git archive --prefix "koji-osbuild-${GIT_SHA}/" --output "koji-osbuild-${GIT_SHA}.tar.gz" HEAD
sudo mock -v -r "$MOCK_CONFIG" --buildsrpm \
--define "commit ${GIT_SHA}" \
--spec ./koji-osbuild.spec \
--sources "./koji-osbuild-${GIT_SHA}.tar.gz" \
--resultdir ./srpm

# Compile RPMs in a mock chroot
greenprint "🎁 Building RPMs with mock"
sudo mock -v -r $MOCK_CONFIG --resultdir repo/$REPO_DIR --with=tests \
build/rpmbuild/SRPMS/*.src.rpm
greenprint "🎁 Building RPMs"
sudo mock -v -r $MOCK_CONFIG \
--define "commit ${GIT_SHA}" \
--resultdir $REPO_DIR \
srpm/*.src.rpm

# Change the ownership of all of our repo files from root to our CI user.
sudo chown -R $USER repo/${REPO_DIR%%/*}
sudo chown -R $USER ${REPO_DIR%%/*}

# Move the logs out of the way.
greenprint "🧹 Retaining logs from mock build"
mv repo/${REPO_DIR}/*.log $WORKSPACE
greenprint " Remove logs from mock build"
rm ${REPO_DIR}/*.log

# Create a repo of the built RPMs.
greenprint "⛓️ Creating dnf repository"
createrepo_c repo/${REPO_DIR}
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 mock.repo << EOF
[schutzbot-mock]
name=schutzbot mock ${GIT_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