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> |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 9 | # UBUNTU_MIRROR: [optional] The URL of a mirror of Ubuntu to override the |
| 10 | # default ones in /etc/apt/sources.list |
| 11 | # default is empty, and no mirror is used. |
| 12 | # http_proxy: The HTTP address of the proxy server to connect to. |
| 13 | # Default: "", proxy is not setup if this is not set |
| 14 | |
| 15 | http_proxy=${http_proxy:-} |
| 16 | UBUNTU_MIRROR=${UBUNTU_MIRROR:-""} |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 17 | |
| 18 | set -uo pipefail |
| 19 | |
| 20 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"} |
| 21 | DISTRO=${DISTRO:-"ubuntu:bionic"} |
| 22 | |
| 23 | # Determine the architecture |
| 24 | ARCH=$(uname -m) |
| 25 | case ${ARCH} in |
| 26 | "ppc64le") |
| 27 | DOCKER_BASE="ppc64le/" |
| 28 | ;; |
| 29 | "x86_64") |
| 30 | DOCKER_BASE="" |
| 31 | ;; |
Thang Q. Nguyen | 051b05b | 2021-12-10 08:30:35 +0000 | [diff] [blame] | 32 | "aarch64") |
Thang Q. Nguyen | f98f1a8 | 2021-12-22 01:59:19 +0000 | [diff] [blame] | 33 | DOCKER_BASE="arm64v8/" |
Thang Q. Nguyen | 051b05b | 2021-12-10 08:30:35 +0000 | [diff] [blame] | 34 | ;; |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 35 | *) |
| 36 | echo "Unsupported system architecture(${ARCH}) found for docker image" |
| 37 | exit 1 |
| 38 | esac |
| 39 | |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 40 | PROXY="" |
| 41 | |
| 42 | MIRROR="" |
| 43 | if [[ -n "${UBUNTU_MIRROR}" ]]; then |
| 44 | MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \ |
| 45 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 46 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 47 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 48 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list" |
| 49 | fi |
| 50 | |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 51 | ################################# docker img # ################################# |
| 52 | |
| 53 | if [[ "${DISTRO}" == "ubuntu"* ]]; then |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 54 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 55 | if [[ -n "${http_proxy}" ]]; then |
| 56 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 57 | fi |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 58 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 59 | Dockerfile=$(cat << EOF |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 60 | FROM ${DOCKER_BASE}${DISTRO} |
| 61 | |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 62 | ${PROXY} |
| 63 | ${MIRROR} |
| 64 | |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 65 | ENV DEBIAN_FRONTEND noninteractive |
| 66 | |
| 67 | RUN apt-get update && apt-get install -yy \ |
| 68 | python3 \ |
| 69 | python3-dev\ |
| 70 | python3-yaml \ |
| 71 | python3-mako \ |
| 72 | python3-pip \ |
| 73 | python3-setuptools \ |
| 74 | curl \ |
| 75 | git \ |
| 76 | wget \ |
| 77 | sudo \ |
| 78 | squashfs-tools |
| 79 | |
| 80 | # Final configuration for the workspace |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 81 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 82 | RUN mkdir -p $(dirname "${HOME}") |
| 83 | 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] | 84 | RUN sed -i '1iDefaults umask=000' /etc/sudoers |
| 85 | RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers |
| 86 | |
| 87 | RUN /bin/bash |
| 88 | EOF |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 89 | ) |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 90 | fi |
| 91 | ################################# docker img # ################################# |
| 92 | |
| 93 | # Build above image |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 94 | docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}" |