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. |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 12 | # DOCKER_REG: <optional, the URL of a docker registry to utilize |
Andrew Geissler | fb45daa | 2024-10-09 12:26:56 -0400 | [diff] [blame] | 13 | # instead of our default (public.ecr.aws/ubuntu) |
| 14 | # (ex. docker.io) |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 15 | # http_proxy: The HTTP address of the proxy server to connect to. |
| 16 | # Default: "", proxy is not setup if this is not set |
| 17 | |
| 18 | http_proxy=${http_proxy:-} |
| 19 | UBUNTU_MIRROR=${UBUNTU_MIRROR:-""} |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 20 | |
| 21 | set -uo pipefail |
| 22 | |
| 23 | DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"} |
| 24 | DISTRO=${DISTRO:-"ubuntu:bionic"} |
Andrew Geissler | fb45daa | 2024-10-09 12:26:56 -0400 | [diff] [blame] | 25 | docker_reg=${DOCKER_REG:-"public.ecr.aws/ubuntu"} |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 26 | |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 27 | PROXY="" |
| 28 | |
| 29 | MIRROR="" |
| 30 | if [[ -n "${UBUNTU_MIRROR}" ]]; then |
| 31 | MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \ |
| 32 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 33 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 34 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \ |
| 35 | echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list" |
| 36 | fi |
| 37 | |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 38 | ################################# docker img # ################################# |
| 39 | |
| 40 | if [[ "${DISTRO}" == "ubuntu"* ]]; then |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 41 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 42 | if [[ -n "${http_proxy}" ]]; then |
| 43 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 44 | fi |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 45 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 46 | Dockerfile=$(cat << EOF |
Andrew Geissler | b80ea07 | 2024-10-07 15:43:34 -0400 | [diff] [blame] | 47 | FROM ${docker_reg}/${DISTRO} |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 48 | |
Lei YU | ab2c6aa | 2022-10-12 15:56:34 +0800 | [diff] [blame] | 49 | ${PROXY} |
| 50 | ${MIRROR} |
| 51 | |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 52 | ENV DEBIAN_FRONTEND noninteractive |
| 53 | |
| 54 | RUN apt-get update && apt-get install -yy \ |
| 55 | python3 \ |
| 56 | python3-dev\ |
| 57 | python3-yaml \ |
| 58 | python3-mako \ |
| 59 | python3-pip \ |
| 60 | python3-setuptools \ |
| 61 | curl \ |
| 62 | git \ |
| 63 | wget \ |
| 64 | sudo \ |
| 65 | squashfs-tools |
| 66 | |
| 67 | # Final configuration for the workspace |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 68 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 69 | RUN mkdir -p $(dirname "${HOME}") |
| 70 | 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] | 71 | RUN sed -i '1iDefaults umask=000' /etc/sudoers |
| 72 | RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers |
| 73 | |
| 74 | RUN /bin/bash |
| 75 | EOF |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 76 | ) |
Michael Shepos | 6e77d11 | 2019-02-06 19:09:14 -0600 | [diff] [blame] | 77 | fi |
| 78 | ################################# docker img # ################################# |
| 79 | |
| 80 | # Build above image |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 81 | docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}" |