David Caro has uploaded a new change for review. Change subject: Added mock_run script and builder ......................................................................
Added mock_run script and builder That will allow us to run custom scripts inside mock, like generating isos or running unit tests Change-Id: Ibac828fe5bd08b857e5649d2ed7e9466a4822507 Signed-off-by: David Caro <dcaro...@redhat.com> --- A jobs/confs/shell-scripts/mock_run.sh A jobs/confs/yaml/builders/mock_run.yaml 2 files changed, 156 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/33/36033/1 diff --git a/jobs/confs/shell-scripts/mock_run.sh b/jobs/confs/shell-scripts/mock_run.sh new file mode 100644 index 0000000..d04da3f --- /dev/null +++ b/jobs/confs/shell-scripts/mock_run.sh @@ -0,0 +1,150 @@ +#!/bin/bash -xe +echo "shell-scripts/mock_run.sh" +# Do some black magic +# PARAMETERS +# +# project +# Name of the project it runs on, specifically the dir where the code +# has been cloned +# +# distro +# Distribution it should create the rpms for (usually el6, el7, fc19 or +# fc20) +# +# arch +# Architecture to build the packages for +# +# extra-packages +# List of packages to install +# +# extra-repos +# List of extra repositories to use when building, in a space separated list +# of name,url pairs +# +# env +# Extra environment variables +# +# script +# Script to run inside mock, with the jenkins/jobs/confs/shell-scripts as +# basepath +# +# copy_dirs +# Directories to copy inside the chroot + +distro="{distro}" +arch="{arch}" +copy_dirs=({copy-dirs}) +project="{project}" +extra_packages=({extra-packages}) +extra_repos=({extra-repos}) +extra_env="{env}" +script="{script}" + + +### Generate the mock configuration +pushd "$WORKSPACE"/jenkins/mock_configs +arch="{arch}" +case $distro in + fc*) distribution="fedora-${{distro#fc}}";; + el*) distribution="epel-${{distro#el}}";; + *) echo "Unknown distro $distro"; exit 1;; +esac +mock_conf="${{distribution}}-$arch-ovirt-snapshot" +mock_repos=() +for mock_repo in "${{extra_repos[@]}}"; do + mock_repos+=("--repo" "$mock_repo") +done +echo "#### Generating mock configuration" +./mock_genconfig \ + --name="$mock_conf" \ + --base="$distribution-$arch.cfg" \ + --option="basedir=$WORKSPACE/mock/" \ + --option="plugin_conf.bind_mount_enable=True" \ + --option='plugin_conf.bind_mount_opts.dirs=[ + ("/dev", "/dev/"), + ("/sys", "/sys/"), + ("/lib/modules", "/lib/modules/"), + ]' \ + "${{mock_repos[@]}}" \ +> "$mock_conf.cfg" +sudo touch /var/cache/mock/*/root_cache/cache.tar.gz || : +cat "$mock_conf.cfg" +popd + +pkg_array=() +for package in "${{packages[@]}}"; do + [[ -f "$package" ]] \ + || {{ + echo "ERROR: Package $package not found!" + exit 1 + }} +done + +## prepare the command line +my_mock="/usr/bin/mock" +my_mock+=" --configdir=$WORKSPACE/jenkins/mock_configs" +my_mock+=" --root=$mock_conf" + +## init the chroot +$my_mock \ + --init + +### Configure extra yum vars +echo "Configuring custom env variables for repo urls" +$my_mock \ + --no-clean \ + --shell <<EOF + mkdir -p /etc/yum/vars + echo "$distro" > /etc/yum/vars/distro +EOF + +## Needed when running shell on different arch than the host, because rpmdb is +## copied from it when creating the chroot and x86_64 rpmdb is not compatible on +## i686 +$my_mock \ + --no-clean \ + --shell <<EOF +rm -f /var/lib/rpm/__db* +rpm --rebuilddb +EOF + +### Install any extra packages if needed +if [[ -n "$extra_packages" ]]; then + echo "##### Installing extra dependencies: $extra_packages" + $my_mock \ + --no-clean \ + --install "${{extra_packages[@]}}" +fi + +### Make sure that the destination home dir exists +$my_mock \ + --no-clean \ + --shell <<EOFMAKINGTHISHARDTOMATCH +mkdir -p /tmp/run +EOFMAKINGTHISHARDTOMATCH + +### Copy workspace code to the chroot +[[ "$copy_dirs" ]] \ +&& {{ + for dir in "${{copy_dirs[@]}}"; do + $my_mock \ + --no-clean \ + --copyin "$dir" /tmp/run/"$dir" + done +}} +### Copy also the jenkins dir +$my_mock \ + --no-clean \ + --copyin "jenkins" /tmp/run/jenkins + +### Run the script +echo "##### Running inside mock" +$my_mock \ + --no-clean \ + --shell <<EOFMAKINGTHISHARDTOMATCH +SCRIPT="/tmp/run/jenkins/jobs/confs/shell-scripts/{script}" +export HOME=/tmp/run +cd +chmod +x \$SCRIPT +\$SCRIPT +EOFMAKINGTHISHARDTOMATCH diff --git a/jobs/confs/yaml/builders/mock_run.yaml b/jobs/confs/yaml/builders/mock_run.yaml new file mode 100644 index 0000000..898ee9c --- /dev/null +++ b/jobs/confs/yaml/builders/mock_run.yaml @@ -0,0 +1,6 @@ +- builder: + name: mock-run + builders: + - shell: !include-raw shell-scripts/global_setup.sh + - shell: !include-raw shell-scripts/mock_setup.sh + - shell: !include-raw shell-scripts/mock_run.sh -- To view, visit http://gerrit.ovirt.org/36033 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibac828fe5bd08b857e5649d2ed7e9466a4822507 Gerrit-PatchSet: 1 Gerrit-Project: jenkins Gerrit-Branch: master Gerrit-Owner: David Caro <dcaro...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches