Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 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 | |
| 11 | set -uo pipefail |
| 12 | |
| 13 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"} |
| 14 | DISTRO=${DISTRO:-"ubuntu:bionic"} |
| 15 | |
| 16 | # Determine the architecture |
| 17 | ARCH=$(uname -m) |
| 18 | case ${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 |
| 28 | esac |
| 29 | |
| 30 | ################################# docker img # ################################# |
| 31 | |
| 32 | if [[ "${DISTRO}" == "ubuntu"* ]]; then |
| 33 | Dockerfile=$(cat << EOF |
| 34 | FROM ${DOCKER_BASE}${DISTRO} |
| 35 | |
| 36 | ENV DEBIAN_FRONTEND noninteractive |
| 37 | |
| 38 | RUN 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 |
| 52 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 53 | RUN mkdir -p $(dirname ${HOME}) |
| 54 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 55 | RUN sed -i '1iDefaults umask=000' /etc/sudoers |
| 56 | RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers |
| 57 | |
| 58 | RUN /bin/bash |
| 59 | EOF |
| 60 | ) |
| 61 | fi |
| 62 | ################################# docker img # ################################# |
| 63 | |
| 64 | # Build above image |
| 65 | docker build --network=host -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}" |