blob: ce64076fdc6b566cc21ce1a029aac2e8f70b9c1d [file] [log] [blame]
Michael Shepos6e77d112019-02-06 19:09:14 -06001#!/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 YUab2c6aa2022-10-12 15:56:34 +08009# 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 Geisslerb80ea072024-10-07 15:43:34 -040012# DOCKER_REG: <optional, the URL of a docker registry to utilize
Andrew Geisslerfb45daa2024-10-09 12:26:56 -040013# instead of our default (public.ecr.aws/ubuntu)
14# (ex. docker.io)
Lei YUab2c6aa2022-10-12 15:56:34 +080015# http_proxy: The HTTP address of the proxy server to connect to.
16# Default: "", proxy is not setup if this is not set
17
18http_proxy=${http_proxy:-}
19UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
Michael Shepos6e77d112019-02-06 19:09:14 -060020
21set -uo pipefail
22
23DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"}
24DISTRO=${DISTRO:-"ubuntu:bionic"}
Andrew Geisslerfb45daa2024-10-09 12:26:56 -040025docker_reg=${DOCKER_REG:-"public.ecr.aws/ubuntu"}
Michael Shepos6e77d112019-02-06 19:09:14 -060026
Lei YUab2c6aa2022-10-12 15:56:34 +080027PROXY=""
28
29MIRROR=""
30if [[ -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"
36fi
37
Michael Shepos6e77d112019-02-06 19:09:14 -060038################################# docker img # #################################
39
40if [[ "${DISTRO}" == "ubuntu"* ]]; then
Lei YUab2c6aa2022-10-12 15:56:34 +080041
Patrick Williams476a7e92022-12-06 09:52:53 -060042 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 YUab2c6aa2022-10-12 15:56:34 +080045
Patrick Williams476a7e92022-12-06 09:52:53 -060046 Dockerfile=$(cat << EOF
Andrew Geisslerb80ea072024-10-07 15:43:34 -040047FROM ${docker_reg}/${DISTRO}
Michael Shepos6e77d112019-02-06 19:09:14 -060048
Lei YUab2c6aa2022-10-12 15:56:34 +080049${PROXY}
50${MIRROR}
51
Michael Shepos6e77d112019-02-06 19:09:14 -060052ENV DEBIAN_FRONTEND noninteractive
53
54RUN 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 Williams384d7412020-11-06 16:15:41 -060068RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
69RUN mkdir -p $(dirname "${HOME}")
70RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Michael Shepos6e77d112019-02-06 19:09:14 -060071RUN sed -i '1iDefaults umask=000' /etc/sudoers
72RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
73
74RUN /bin/bash
75EOF
Patrick Williams476a7e92022-12-06 09:52:53 -060076 )
Michael Shepos6e77d112019-02-06 19:09:14 -060077fi
78################################# docker img # #################################
79
80# Build above image
Patrick Williams384d7412020-11-06 16:15:41 -060081docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"