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> |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 9 | |
| 10 | set -uo pipefail |
| 11 | |
| 12 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"} |
| 13 | DISTRO=${DISTRO:-"ubuntu:bionic"} |
| 14 | |
| 15 | # Determine the architecture |
| 16 | ARCH=$(uname -m) |
| 17 | case ${ARCH} in |
| 18 | "ppc64le") |
| 19 | DOCKER_BASE="ppc64le/" |
| 20 | ;; |
| 21 | "x86_64") |
| 22 | DOCKER_BASE="" |
| 23 | ;; |
Thang Q. Nguyen | 051b05b | 2021-12-10 08:30:35 +0000 | [diff] [blame] | 24 | "aarch64") |
Thang Q. Nguyen | f98f1a8 | 2021-12-22 01:59:19 +0000 | [diff] [blame] | 25 | DOCKER_BASE="arm64v8/" |
Thang Q. Nguyen | 051b05b | 2021-12-10 08:30:35 +0000 | [diff] [blame] | 26 | ;; |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 27 | *) |
| 28 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 29 | exit 1 |
| 30 | esac |
| 31 | |
| 32 | ################################# docker img # ################################# |
| 33 | |
| 34 | if [[ "${DISTRO}" == "ubuntu"* ]]; then |
| 35 | Dockerfile=$(cat << EOF |
| 36 | FROM ${DOCKER_BASE}${DISTRO} |
| 37 | |
| 38 | ENV DEBIAN_FRONTEND noninteractive |
| 39 | |
| 40 | RUN apt-get update && apt-get install -yy \ |
| 41 | python3 \ |
| 42 | python3-dev\ |
| 43 | python3-yaml \ |
| 44 | python3-mako \ |
| 45 | python3-pip \ |
| 46 | python3-setuptools \ |
| 47 | curl \ |
| 48 | git \ |
| 49 | wget \ |
| 50 | sudo \ |
| 51 | squashfs-tools |
| 52 | |
| 53 | # Final configuration for the workspace |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 54 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 55 | RUN mkdir -p $(dirname "${HOME}") |
| 56 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 57 | RUN sed -i '1iDefaults umask=000' /etc/sudoers |
| 58 | RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers |
| 59 | |
| 60 | RUN /bin/bash |
| 61 | EOF |
| 62 | ) |
| 63 | fi |
| 64 | ################################# docker img # ################################# |
| 65 | |
| 66 | # Build above image |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 67 | docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}" |