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# DOCKER_REG: <optional, the URL of a docker registry to utilize 13# instead of our default (public.ecr.aws/ubuntu) 14# (ex. docker.io) 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 18http_proxy=${http_proxy:-} 19UBUNTU_MIRROR=${UBUNTU_MIRROR:-""} 20 21set -uo pipefail 22 23DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"} 24DISTRO=${DISTRO:-"ubuntu:bionic"} 25docker_reg=${DOCKER_REG:-"public.ecr.aws/ubuntu"} 26 27PROXY="" 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 38################################# docker img # ################################# 39 40if [[ "${DISTRO}" == "ubuntu"* ]]; then 41 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 45 46 Dockerfile=$(cat << EOF 47FROM ${docker_reg}/${DISTRO} 48 49${PROXY} 50${MIRROR} 51 52ENV 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 68RUN 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} 71RUN sed -i '1iDefaults umask=000' /etc/sudoers 72RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers 73 74RUN /bin/bash 75EOF 76 ) 77fi 78################################# docker img # ################################# 79 80# Build above image 81docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}" 82