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