Michael Shepos | d29d159 | 2019-02-06 19:14:03 -0600 | [diff] [blame] | 1 | #!/bin/bash -xe |
| 2 | |
| 3 | # This script is for running rootfs_size.py in Jenkins using docker. |
| 4 | # |
| 5 | # This script will build a docker container which will then be used to build |
| 6 | # and run the rootfs_size.py script. |
| 7 | # |
| 8 | # WORKSPACE: Required, location of unit test scripts and repository |
| 9 | # code to test |
| 10 | # SQUASHFS_FILE: Required, The squashfs file name to run rootfs_size |
| 11 | # against |
| 12 | # DISTRO: Optional, docker base image (ubuntu or fedora) |
| 13 | # DOCKER_IMG_NAME: Optional, default is openbmc/ubuntu-rootfs-size |
| 14 | |
| 15 | # Trace bash processing. Set -e so when a step fails, we fail the build |
| 16 | set -uo pipefail |
| 17 | |
| 18 | # Default variables |
| 19 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"} |
| 20 | DISTRO=${DISTRO:-ubuntu:bionic} |
| 21 | OBMC_BUILD_SCRIPTS="openbmc-build-scripts" |
| 22 | OBMC_TOOLS="openbmc-tools" |
Gunnar Mills | d819cfb | 2020-09-28 12:34:01 -0500 | [diff] [blame] | 23 | ROOTFS_SIZE_PY_DIR="rootfs_size" |
Michael Shepos | d29d159 | 2019-02-06 19:14:03 -0600 | [diff] [blame] | 24 | ROOTFS_SIZE_PY="rootfs_size.py" |
| 25 | |
| 26 | # Timestamp for job |
| 27 | echo "rootfs_size build started, $(date)" |
| 28 | |
| 29 | if [[ "${DISTRO}" == "fedora" ]]; then |
| 30 | echo "Distro (${DISTRO}) not supported, running as ubuntu" |
| 31 | DISTRO="ubuntu:bionic" |
| 32 | fi |
| 33 | |
| 34 | # Check workspace, build scripts exist |
| 35 | if [ ! -d "${WORKSPACE}" ]; then |
| 36 | echo "Workspace(${WORKSPACE}) doesn't exist, exiting..." |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | if [ ! -e "${WORKSPACE}/${SQUASHFS_FILE}" ]; then |
| 41 | echo "${WORKSPACE}/${SQUASHFS_FILE} doesn't exist, exiting..." |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then |
| 46 | echo "Clone (${OBMC_BUILD_SCRIPTS}) in ${WORKSPACE}..." |
Andrew Geissler | 3705241 | 2022-05-20 15:28:26 -0400 | [diff] [blame] | 47 | git clone https://gerrit.openbmc.org/openbmc/${OBMC_BUILD_SCRIPTS} "${WORKSPACE}"/${OBMC_BUILD_SCRIPTS} |
Michael Shepos | d29d159 | 2019-02-06 19:14:03 -0600 | [diff] [blame] | 48 | fi |
| 49 | |
| 50 | if [ ! -d "${WORKSPACE}/${OBMC_TOOLS}" ]; then |
| 51 | echo "Clone (${OBMC_TOOLS}) in ${WORKSPACE}..." |
Andrew Geissler | 3705241 | 2022-05-20 15:28:26 -0400 | [diff] [blame] | 52 | git clone https://gerrit.openbmc.org/openbmc/${OBMC_TOOLS} "${WORKSPACE}"/${OBMC_TOOLS} |
Michael Shepos | d29d159 | 2019-02-06 19:14:03 -0600 | [diff] [blame] | 53 | fi |
| 54 | |
| 55 | # Copy rootfs_size.py script into workspace |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 56 | cp "${WORKSPACE}"/${OBMC_TOOLS}/${ROOTFS_SIZE_PY_DIR}/${ROOTFS_SIZE_PY} \ |
| 57 | "${WORKSPACE}"/${ROOTFS_SIZE_PY} |
| 58 | chmod a+x "${WORKSPACE}"/${ROOTFS_SIZE_PY} |
Michael Shepos | d29d159 | 2019-02-06 19:14:03 -0600 | [diff] [blame] | 59 | |
| 60 | # Configure docker build |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 61 | cd "${WORKSPACE}"/${OBMC_BUILD_SCRIPTS} |
Michael Shepos | d29d159 | 2019-02-06 19:14:03 -0600 | [diff] [blame] | 62 | echo "Building docker image with build-rootfs-size-docker.sh" |
| 63 | |
| 64 | # Export input env variables |
| 65 | export DOCKER_IMG_NAME |
| 66 | export DISTRO |
| 67 | ./build-rootfs-size-docker.sh |
| 68 | |
| 69 | # Run the docker container with the rootfs_size execution script |
| 70 | echo "Executing docker image" |
| 71 | docker run --cap-add=sys_admin --rm=true \ |
| 72 | --network host \ |
| 73 | --privileged=true \ |
| 74 | -u "$USER" \ |
| 75 | -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \ |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 76 | -t "${DOCKER_IMG_NAME}" \ |
| 77 | "${WORKSPACE}"/${ROOTFS_SIZE_PY} --build_dir "${WORKSPACE}"/ \ |
| 78 | --squashfs_file "${SQUASHFS_FILE}" |
Michael Shepos | d29d159 | 2019-02-06 19:14:03 -0600 | [diff] [blame] | 79 | |
| 80 | # Timestamp for build |
| 81 | echo "rootfs_size build completed, $(date)" |