From 5af47a5395cbb3e51549c571b7a20f4e87add925 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Apr 04 2018 11:59:31 +0000 Subject: Add initial version of Jenkinsfile and Dockerfile. Signed-off-by: Jan Kaluza --- diff --git a/.copr/Makefile b/.copr/Makefile index e6d6a56..ac9f757 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -2,5 +2,6 @@ srpm: /usr/bin/bash .copr/prepare_spec.sh python setup.py sdist cp ./dist/*.tar.gz ./.copr + touch ./.copr/sources fedpkg --path ./.copr --release el7 srpm cp ./.copr/*.src.rpm $(outdir) diff --git a/.copr/prepare_spec.sh b/.copr/prepare_spec.sh index ba2f93a..18f8144 100644 --- a/.copr/prepare_spec.sh +++ b/.copr/prepare_spec.sh @@ -1,4 +1,4 @@ -dnf -y install python git fedpkg python-setuptools +sudo dnf -y install python git fedpkg python-setuptools FRESHMAKER_VERSION=$(python setup.py -V) FRESHMAKER_RELEASE=$(git log -1 --pretty=format:%ct) sed -e "s|\$FRESHMAKER_VERSION|$FRESHMAKER_VERSION|g" \ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6de1720 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM fedora:27 +LABEL \ + name="Freshmaker application" \ + vendor="Freshmaker developers" \ + license="GPLv2+" \ + build-date="" +# The caller should build a Freshmaker RPM package and then pass it in this arg. +ARG freshmaker_rpm +COPY $freshmaker_rpm /tmp + +RUN dnf -y install \ + /tmp/$(basename $freshmaker_rpm) \ + && dnf -y clean all \ + && rm -f /tmp/* + +USER 1001 +EXPOSE 8080 + +ENTRYPOINT fedmsg-hub diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7cc3d2a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,109 @@ +/* + * SPDX-License-Identifier: GPL-2.0+ +*/ + +try { // massive try{} catch{} around the entire build for failure notifications + timestamps { + +node('fedora') { + checkout scm + stage('Prepare') { + sh 'sudo rm -f rpmbuild-output/*.src.rpm' + sh 'mkdir -p rpmbuild-output' + sh 'make -f .copr/Makefile srpm outdir=./rpmbuild-output/' + /* Needed for mock EPEL7 builds: https://bugzilla.redhat.com/show_bug.cgi?id=1528272 */ + sh 'sudo dnf -y install dnf-utils' + sh 'sudo dnf -y builddep ./rpmbuild-output/freshmaker-*.src.rpm' + sh 'sudo dnf -y install python2-tox python3-tox' + } + stage('Run unit tests') { + sh 'tox -e flake8' + } + /* We take a flock on the mock configs, to avoid multiple unrelated jobs on + * the same Jenkins slave trying to use the same mock root at the same + * time, which will error out. */ + stage('Build RPM') { + parallel ( + 'EPEL7': { + sh """ + mkdir -p mock-result/el7 + flock /etc/mock/epel-7-x86_64.cfg \ + /usr/bin/mock -v --enable-network --resultdir=mock-result/el7 -r epel-7-x86_64 --clean --rebuild rpmbuild-output/*.src.rpm + """ + archiveArtifacts artifacts: 'mock-result/el7/**' + }, + 'F26': { + sh """ + mkdir -p mock-result/f26 + flock /etc/mock/fedora-26-x86_64.cfg \ + /usr/bin/mock -v --enable-network --resultdir=mock-result/f26 -r fedora-26-x86_64 --clean --rebuild rpmbuild-output/*.src.rpm + """ + archiveArtifacts artifacts: 'mock-result/f26/**' + }, + 'F27': { + sh """ + mkdir -p mock-result/f27 + flock /etc/mock/fedora-27-x86_64.cfg \ + /usr/bin/mock -v --enable-network --resultdir=mock-result/f27 -r fedora-27-x86_64 --clean --rebuild rpmbuild-output/*.src.rpm + """ + archiveArtifacts artifacts: 'mock-result/f27/**' + }, + ) + } +} +node('docker') { + checkout scm + stage('Build Docker container') { + unarchive mapping: ['mock-result/f26/': '.'] + def f26_rpm = findFiles(glob: 'mock-result/f26/**/*.noarch.rpm')[0] + def appversion = sh(returnStdout: true, script: """ + rpm2cpio ${f26_rpm} | \ + cpio --quiet --extract --to-stdout ./usr/lib/python\\*/site-packages/freshmaker\\*.egg-info/PKG-INFO | \ + awk '/^Version: / {print \$2}' + """).trim() + /* Git builds will have a version like 0.3.2.dev1+git.3abbb08 following + * the rules in PEP440. But Docker does not let us have + in the tag + * name, so let's munge it here. */ + appversion = appversion.replace('+', '-') + docker.withRegistry( + 'https://docker-registry.engineering.redhat.com/', + 'docker-registry-factory2-builder-sa-credentials') { + /* Note that the docker.build step has some magic to guess the + * Dockerfile used, which will break if the build directory (here ".") + * is not the final argument in the string. */ + def image = docker.build "factory2/freshmaker:${appversion}", "--build-arg freshmaker_rpm=$f26_rpm ." + image.push() + } + /* Save container version for later steps (this is ugly but I can't find anything better...) */ + writeFile file: 'appversion', text: appversion + archiveArtifacts artifacts: 'appversion' + } +} +node('docker') { + checkout scm + /* Can't use GIT_BRANCH because of this issue https://issues.jenkins-ci.org/browse/JENKINS-35230 */ + def git_branch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() + if (git_branch == 'master') { + stage('Tag "latest".') { + unarchive mapping: ['appversion': 'appversion'] + def appversion = readFile('appversion').trim() + docker.withRegistry( + 'https://docker-registry.engineering.redhat.com/', + 'docker-registry-factory2-builder-sa-credentials') { + def image = docker.image("factory2/freshmaker:${appversion}") + image.push('latest') + } + } + } +} + + } +} catch (e) { + if (ownership.job.ownershipEnabled) { + mail to: ownership.job.primaryOwnerEmail, + cc: ownership.job.secondaryOwnerEmails.join(', '), + subject: "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} failed", + body: "${env.BUILD_URL}\n\n${e}" + } + throw e +} diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py index 0cfd007..c7569a1 100644 --- a/tests/test_lightblue.py +++ b/tests/test_lightblue.py @@ -1041,8 +1041,8 @@ class TestQueryEntityFromLightBlue(helpers.FreshmakerTestCase): [leaf_image3] ] - returned_batches = [sorted(images, key=lambda image: image['brew']['build']) - for images in batches] + returned_batches = [sorted(imgs, key=lambda image: image['brew']['build']) + for imgs in batches] self.assertEqual(expected_batches, returned_batches) @patch('freshmaker.lightblue.LightBlue.find_images_with_packages_from_content_set') diff --git a/tox.ini b/tox.ini index 2b23bb1..7743809 100644 --- a/tox.ini +++ b/tox.ini @@ -7,6 +7,7 @@ envlist = py27, py35, coverage, flake8, bandit [testenv] +sitepackages=True skip_install = True deps = -r{toxinidir}/test-requirements.txt commands =