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> 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 15http_proxy=${http_proxy:-} 16UBUNTU_MIRROR=${UBUNTU_MIRROR:-""} 17 18set -uo pipefail 19 20DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"} 21DISTRO=${DISTRO:-"ubuntu:bionic"} 22 23PROXY="" 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 34################################# docker img # ################################# 35 36if [[ "${DISTRO}" == "ubuntu"* ]]; then 37 38 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 41 42 Dockerfile=$(cat << EOF 43FROM ${DISTRO} 44 45${PROXY} 46${MIRROR} 47 48ENV 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 64RUN 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} 67RUN sed -i '1iDefaults umask=000' /etc/sudoers 68RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers 69 70RUN /bin/bash 71EOF 72 ) 73fi 74################################# docker img # ################################# 75 76# Build above image 77docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}" 78