Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | |
| 3 | # This build script is for running the Jenkins unit test builds using docker. |
| 4 | # |
Andrew Geissler | 6136357 | 2019-01-03 14:00:10 -0600 | [diff] [blame^] | 5 | # UNIT_TEST_PKG = Required, repository which has been extracted and is to |
| 6 | # be tested. |
| 7 | # WORKSPACE = Required, location of unit test scripts and repository code to |
| 8 | # test. |
Andrew Jeffery | 4b4a6bc | 2018-03-08 12:58:48 +1030 | [diff] [blame] | 9 | # DISTRO = Docker base image. Ubuntu and Fedora are supported. |
Andrew Jeffery | 4b4a6bc | 2018-03-08 12:58:48 +1030 | [diff] [blame] | 10 | # dbus_sys_config_file = <path of the dbus config file> |
Andrew Geissler | a6b93bf | 2019-01-03 10:23:38 -0600 | [diff] [blame] | 11 | # BRANCH = <optional, branch to build from each of the openbmc/respositories> |
| 12 | # default is master, which will be used if input branch not |
| 13 | # provided or not found |
| 14 | # DOCKER_IMG_NAME = Default is openbmc/ubuntu-unit-test-master with a |
| 15 | # -$BRANCH replacing -master if $BRANCH provided |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 16 | |
| 17 | # Trace bash processing. Set -e so when a step fails, we fail the build |
| 18 | set -uo pipefail |
| 19 | |
| 20 | # Default variables |
Andrew Geissler | a6b93bf | 2019-01-03 10:23:38 -0600 | [diff] [blame] | 21 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-unit-test-${BRANCH:-master}"} |
Patrick Venture | 52164fd | 2018-08-28 16:12:47 -0700 | [diff] [blame] | 22 | DISTRO=${DISTRO:-ubuntu:bionic} |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 23 | OBMC_BUILD_SCRIPTS="openbmc-build-scripts" |
| 24 | UNIT_TEST_PY_DIR="scripts" |
| 25 | UNIT_TEST_PY="unit-test.py" |
Andrew Geissler | a28286d | 2018-01-10 11:00:00 -0800 | [diff] [blame] | 26 | FORMAT_CODE_SH="format-code.sh" |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 27 | DBUS_UNIT_TEST_PY="dbus-unit-test.py" |
| 28 | DBUS_SYS_CONFIG_FILE=${dbus_sys_config_file:-"/usr/share/dbus-1/system.conf"} |
Andrew Jeffery | a153ee3 | 2018-03-09 13:22:04 +1030 | [diff] [blame] | 29 | MAKEFLAGS="${MAKEFLAGS:-""}" |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 30 | DOCKER_WORKDIR="${DOCKER_WORKDIR:-$WORKSPACE}" |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 31 | |
| 32 | # Timestamp for job |
| 33 | echo "Unit test build started, $(date)" |
| 34 | |
Andrew Jeffery | 316ebd3 | 2018-03-08 13:05:32 +1030 | [diff] [blame] | 35 | if [[ "${DISTRO}" == "fedora" ]]; then |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 36 | echo "Distro (${DISTRO}) not supported, running as ubuntu" |
| 37 | DISTRO="ubuntu:latest" |
| 38 | fi |
| 39 | |
| 40 | # Check workspace, build scripts, and package to be unit tested exists |
| 41 | if [ ! -d "${WORKSPACE}" ]; then |
| 42 | echo "Workspace(${WORKSPACE}) doesn't exist, exiting..." |
| 43 | exit 1 |
| 44 | fi |
| 45 | if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then |
| 46 | echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..." |
| 47 | exit 1 |
| 48 | fi |
| 49 | if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then |
| 50 | echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..." |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | # Copy unit test script into workspace |
| 55 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \ |
| 56 | ${WORKSPACE}/${UNIT_TEST_PY} |
| 57 | chmod a+x ${WORKSPACE}/${UNIT_TEST_PY} |
| 58 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 59 | # Copy dbus unit test script into workspace |
| 60 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${DBUS_UNIT_TEST_PY} \ |
| 61 | ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 62 | chmod a+x ${WORKSPACE}/${DBUS_UNIT_TEST_PY} |
| 63 | |
Andrew Geissler | a28286d | 2018-01-10 11:00:00 -0800 | [diff] [blame] | 64 | # Copy format code script into workspace |
| 65 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${FORMAT_CODE_SH} \ |
| 66 | ${WORKSPACE}/${FORMAT_CODE_SH} |
| 67 | chmod a+x ${WORKSPACE}/${FORMAT_CODE_SH} |
| 68 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 69 | # Configure docker build |
| 70 | cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS} |
| 71 | echo "Building docker image with build-unit-test-docker.sh" |
Andrew Geissler | a6b93bf | 2019-01-03 10:23:38 -0600 | [diff] [blame] | 72 | # Export input env variables |
| 73 | export DOCKER_IMG_NAME |
| 74 | export DISTRO |
| 75 | export BRANCH |
| 76 | ./build-unit-test-docker.sh |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 77 | |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 78 | # Unit test and parameters |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 79 | UNIT_TEST="${DOCKER_WORKDIR}/${UNIT_TEST_PY},-w,${DOCKER_WORKDIR},-p,${UNIT_TEST_PKG},-v" |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 80 | |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 81 | # Run the docker unit test container with the unit test execution script |
| 82 | echo "Executing docker image" |
| 83 | docker run --cap-add=sys_admin --rm=true \ |
James Feist | 878df5c | 2018-07-26 14:54:28 -0700 | [diff] [blame] | 84 | --network host \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 85 | --privileged=true \ |
William A. Kennington III | be6aab2 | 2018-12-06 15:01:54 -0800 | [diff] [blame] | 86 | -u "$USER" \ |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 87 | -w "${DOCKER_WORKDIR}" -v "${WORKSPACE}":"${DOCKER_WORKDIR}" \ |
Andrew Jeffery | a153ee3 | 2018-03-09 13:22:04 +1030 | [diff] [blame] | 88 | -e "MAKEFLAGS=${MAKEFLAGS}" \ |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 89 | -t ${DOCKER_IMG_NAME} \ |
William A. Kennington III | d70980f | 2018-11-08 15:14:27 -0800 | [diff] [blame] | 90 | "${DOCKER_WORKDIR}"/${DBUS_UNIT_TEST_PY} -u ${UNIT_TEST} \ |
Leonel Gonzalez | 13ca380 | 2017-03-07 14:08:44 -0600 | [diff] [blame] | 91 | -f ${DBUS_SYS_CONFIG_FILE} |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 92 | |
| 93 | # Timestamp for build |
| 94 | echo "Unit test build completed, $(date)" |