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