blob: 6b34d07ed3557fdc76be9ac2775585ed48075c22 [file] [log] [blame]
Michael Sheposd29d1592019-02-06 19:14:03 -06001#!/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
16set -uo pipefail
17
18# Default variables
19DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"}
20DISTRO=${DISTRO:-ubuntu:bionic}
21OBMC_BUILD_SCRIPTS="openbmc-build-scripts"
22OBMC_TOOLS="openbmc-tools"
Gunnar Millsd819cfb2020-09-28 12:34:01 -050023ROOTFS_SIZE_PY_DIR="rootfs_size"
Michael Sheposd29d1592019-02-06 19:14:03 -060024ROOTFS_SIZE_PY="rootfs_size.py"
25
26# Timestamp for job
27echo "rootfs_size build started, $(date)"
28
29if [[ "${DISTRO}" == "fedora" ]]; then
30 echo "Distro (${DISTRO}) not supported, running as ubuntu"
31 DISTRO="ubuntu:bionic"
32fi
33
34# Check workspace, build scripts exist
35if [ ! -d "${WORKSPACE}" ]; then
36 echo "Workspace(${WORKSPACE}) doesn't exist, exiting..."
37 exit 1
38fi
39
40if [ ! -e "${WORKSPACE}/${SQUASHFS_FILE}" ]; then
41 echo "${WORKSPACE}/${SQUASHFS_FILE} doesn't exist, exiting..."
42 exit 1
43fi
44
45if [ ! -d "${WORKSPACE}/${OBMC_BUILD_SCRIPTS}" ]; then
46 echo "Clone (${OBMC_BUILD_SCRIPTS}) in ${WORKSPACE}..."
Andrew Geissler37052412022-05-20 15:28:26 -040047 git clone https://gerrit.openbmc.org/openbmc/${OBMC_BUILD_SCRIPTS} "${WORKSPACE}"/${OBMC_BUILD_SCRIPTS}
Michael Sheposd29d1592019-02-06 19:14:03 -060048fi
49
50if [ ! -d "${WORKSPACE}/${OBMC_TOOLS}" ]; then
51 echo "Clone (${OBMC_TOOLS}) in ${WORKSPACE}..."
Andrew Geissler37052412022-05-20 15:28:26 -040052 git clone https://gerrit.openbmc.org/openbmc/${OBMC_TOOLS} "${WORKSPACE}"/${OBMC_TOOLS}
Michael Sheposd29d1592019-02-06 19:14:03 -060053fi
54
55# Copy rootfs_size.py script into workspace
Patrick Williams384d7412020-11-06 16:15:41 -060056cp "${WORKSPACE}"/${OBMC_TOOLS}/${ROOTFS_SIZE_PY_DIR}/${ROOTFS_SIZE_PY} \
57"${WORKSPACE}"/${ROOTFS_SIZE_PY}
58chmod a+x "${WORKSPACE}"/${ROOTFS_SIZE_PY}
Michael Sheposd29d1592019-02-06 19:14:03 -060059
60# Configure docker build
Patrick Williams384d7412020-11-06 16:15:41 -060061cd "${WORKSPACE}"/${OBMC_BUILD_SCRIPTS}
Michael Sheposd29d1592019-02-06 19:14:03 -060062echo "Building docker image with build-rootfs-size-docker.sh"
63
64# Export input env variables
65export DOCKER_IMG_NAME
66export DISTRO
67./build-rootfs-size-docker.sh
68
69# Run the docker container with the rootfs_size execution script
70echo "Executing docker image"
71docker run --cap-add=sys_admin --rm=true \
72 --network host \
73 --privileged=true \
74 -u "$USER" \
75 -w "${WORKSPACE}" -v "${WORKSPACE}":"${WORKSPACE}" \
Patrick Williams384d7412020-11-06 16:15:41 -060076 -t "${DOCKER_IMG_NAME}" \
77 "${WORKSPACE}"/${ROOTFS_SIZE_PY} --build_dir "${WORKSPACE}"/ \
78 --squashfs_file "${SQUASHFS_FILE}"
Michael Sheposd29d1592019-02-06 19:14:03 -060079
80# Timestamp for build
81echo "rootfs_size build completed, $(date)"