1#!/bin/bash -xe
2#
3# Build the required docker image to run rootfs_size.py
4#
5# Script Variables:
6#   DOCKER_IMG_NAME:  <optional, the name of the docker image to generate>
7#                     default is openbmc/ubuntu-rootfs-size
8#   DISTRO:           <optional, the distro to build a docker image against>
9#                     default is ubuntu:bionic
10
11set -uo pipefail
12
13DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"}
14DISTRO=${DISTRO:-"ubuntu:bionic"}
15
16# Determine the architecture
17ARCH=$(uname -m)
18case ${ARCH} in
19    "ppc64le")
20        DOCKER_BASE="ppc64le/"
21        ;;
22    "x86_64")
23        DOCKER_BASE=""
24        ;;
25    *)
26        echo "Unsupported system architecture(${ARCH}) found for docker image"
27        exit 1
28esac
29
30################################# docker img # #################################
31
32if [[ "${DISTRO}" == "ubuntu"* ]]; then
33Dockerfile=$(cat << EOF
34FROM ${DOCKER_BASE}${DISTRO}
35
36ENV DEBIAN_FRONTEND noninteractive
37
38RUN apt-get update && apt-get install -yy \
39    python3 \
40    python3-dev\
41    python3-yaml \
42    python3-mako \
43    python3-pip \
44    python3-setuptools \
45    curl \
46    git \
47    wget \
48    sudo \
49    squashfs-tools
50
51# Final configuration for the workspace
52RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
53RUN mkdir -p $(dirname ${HOME})
54RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
55RUN sed -i '1iDefaults umask=000' /etc/sudoers
56RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
57
58RUN /bin/bash
59EOF
60)
61fi
62################################# docker img # #################################
63
64# Build above image
65docker build --network=host -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}"
66