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 | # |
| 5 | # It uses a few variables which are part of Jenkins build job matrix: |
| 6 | # distro = fedora|ubuntu|ubuntu:14.04|ubuntu:16.04 |
| 7 | # WORKSPACE = <location of unit test execution script> |
| 8 | |
| 9 | # Trace bash processing. Set -e so when a step fails, we fail the build |
| 10 | set -uo pipefail |
| 11 | |
| 12 | # Default variables |
| 13 | DOCKER_IMG_NAME="openbmc/ubuntu-unit-test" |
| 14 | DISTRO=${distro:-ubuntu:latest} |
| 15 | WORKSPACE=${WORKSPACE:-${TMP}/unit-test${RANDOM}} |
| 16 | OBMC_BUILD_SCRIPTS="openbmc-build-scripts" |
| 17 | UNIT_TEST_PY_DIR="scripts" |
| 18 | UNIT_TEST_PY="unit-test.py" |
| 19 | |
| 20 | # Timestamp for job |
| 21 | echo "Unit test build started, $(date)" |
| 22 | |
| 23 | # Currently only support ubuntu:latest due to systemd requirements |
| 24 | if [[ "${DISTRO}" == "ubuntu"* ]]; then |
| 25 | DISTRO="ubuntu:latest" |
| 26 | elif [[ "${DISTRO}" == "fedora" ]]; then |
| 27 | echo "Distro (${DISTRO}) not supported, running as ubuntu" |
| 28 | DISTRO="ubuntu:latest" |
| 29 | fi |
| 30 | |
| 31 | # Check workspace, build scripts, and package to be unit tested exists |
| 32 | if [ ! -d "${WORKSPACE}" ]; then |
| 33 | echo "Workspace(${WORKSPACE}) doesn't exist, exiting..." |
| 34 | exit 1 |
| 35 | fi |
| 36 | if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then |
| 37 | echo "Package(${OBMC_BUILD_SCRIPTS}) not found in ${WORKSPACE}, exiting..." |
| 38 | exit 1 |
| 39 | fi |
| 40 | if [ ! -d "${WORKSPACE}/${UNIT_TEST_PKG}" ]; then |
| 41 | echo "Package(${UNIT_TEST_PKG}) not found in ${WORKSPACE}, exiting..." |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | # Copy unit test script into workspace |
| 46 | cp ${WORKSPACE}/${OBMC_BUILD_SCRIPTS}/${UNIT_TEST_PY_DIR}/${UNIT_TEST_PY} \ |
| 47 | ${WORKSPACE}/${UNIT_TEST_PY} |
| 48 | chmod a+x ${WORKSPACE}/${UNIT_TEST_PY} |
| 49 | |
| 50 | # Configure docker build |
| 51 | cd ${WORKSPACE}/${OBMC_BUILD_SCRIPTS} |
| 52 | echo "Building docker image with build-unit-test-docker.sh" |
| 53 | ./build-unit-test-docker.sh ${DOCKER_IMG_NAME} ${DISTRO} |
| 54 | |
| 55 | # Run the docker unit test container with the unit test execution script |
| 56 | echo "Executing docker image" |
| 57 | docker run --cap-add=sys_admin --rm=true \ |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 58 | -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \ |
Matthew Barth | 33df879 | 2016-12-19 14:30:17 -0600 | [diff] [blame] | 59 | -t ${DOCKER_IMG_NAME} \ |
| 60 | ${WORKSPACE}/${UNIT_TEST_PY} -w ${WORKSPACE} -p ${UNIT_TEST_PKG} -v |
Matthew Barth | c5dec75 | 2016-11-18 13:14:37 -0600 | [diff] [blame] | 61 | |
| 62 | # Timestamp for build |
| 63 | echo "Unit test build completed, $(date)" |