blob: 4acd2782fc3a085388b7895e3d5cbb02d01aa505 [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.
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
15http_proxy=${http_proxy:-}
16UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
Michael Shepos6e77d112019-02-06 19:09:14 -060017
18set -uo pipefail
19
20DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"}
21DISTRO=${DISTRO:-"ubuntu:bionic"}
22
Lei YUab2c6aa2022-10-12 15:56:34 +080023PROXY=""
24
25MIRROR=""
26if [[ -n "${UBUNTU_MIRROR}" ]]; then
27 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
28 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
29 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
30 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
31 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
32fi
33
Michael Shepos6e77d112019-02-06 19:09:14 -060034################################# docker img # #################################
35
36if [[ "${DISTRO}" == "ubuntu"* ]]; then
Lei YUab2c6aa2022-10-12 15:56:34 +080037
Patrick Williams476a7e92022-12-06 09:52:53 -060038 if [[ -n "${http_proxy}" ]]; then
39 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
40 fi
Lei YUab2c6aa2022-10-12 15:56:34 +080041
Patrick Williams476a7e92022-12-06 09:52:53 -060042 Dockerfile=$(cat << EOF
Andrew Geissler9096c692024-10-02 16:36:17 -040043FROM ${DISTRO}
Michael Shepos6e77d112019-02-06 19:09:14 -060044
Lei YUab2c6aa2022-10-12 15:56:34 +080045${PROXY}
46${MIRROR}
47
Michael Shepos6e77d112019-02-06 19:09:14 -060048ENV DEBIAN_FRONTEND noninteractive
49
50RUN apt-get update && apt-get install -yy \
51 python3 \
52 python3-dev\
53 python3-yaml \
54 python3-mako \
55 python3-pip \
56 python3-setuptools \
57 curl \
58 git \
59 wget \
60 sudo \
61 squashfs-tools
62
63# Final configuration for the workspace
Patrick Williams384d7412020-11-06 16:15:41 -060064RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
65RUN mkdir -p $(dirname "${HOME}")
66RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Michael Shepos6e77d112019-02-06 19:09:14 -060067RUN sed -i '1iDefaults umask=000' /etc/sudoers
68RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
69
70RUN /bin/bash
71EOF
Patrick Williams476a7e92022-12-06 09:52:53 -060072 )
Michael Shepos6e77d112019-02-06 19:09:14 -060073fi
74################################# docker img # #################################
75
76# Build above image
Patrick Williams384d7412020-11-06 16:15:41 -060077docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"