blob: eb2b351507c7935355747673eb9533bf9f366ae5 [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
23# Determine the architecture
24ARCH=$(uname -m)
25case ${ARCH} in
26 "ppc64le")
27 DOCKER_BASE="ppc64le/"
28 ;;
29 "x86_64")
30 DOCKER_BASE=""
31 ;;
Thang Q. Nguyen051b05b2021-12-10 08:30:35 +000032 "aarch64")
Thang Q. Nguyenf98f1a82021-12-22 01:59:19 +000033 DOCKER_BASE="arm64v8/"
Thang Q. Nguyen051b05b2021-12-10 08:30:35 +000034 ;;
Michael Shepos6e77d112019-02-06 19:09:14 -060035 *)
36 echo "Unsupported system architecture(${ARCH}) found for docker image"
37 exit 1
38esac
39
Lei YUab2c6aa2022-10-12 15:56:34 +080040PROXY=""
41
42MIRROR=""
43if [[ -n "${UBUNTU_MIRROR}" ]]; then
44 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
45 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
46 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
47 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
48 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
49fi
50
Michael Shepos6e77d112019-02-06 19:09:14 -060051################################# docker img # #################################
52
53if [[ "${DISTRO}" == "ubuntu"* ]]; then
Lei YUab2c6aa2022-10-12 15:56:34 +080054
55if [[ -n "${http_proxy}" ]]; then
56 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
57fi
58
Michael Shepos6e77d112019-02-06 19:09:14 -060059Dockerfile=$(cat << EOF
60FROM ${DOCKER_BASE}${DISTRO}
61
Lei YUab2c6aa2022-10-12 15:56:34 +080062${PROXY}
63${MIRROR}
64
Michael Shepos6e77d112019-02-06 19:09:14 -060065ENV DEBIAN_FRONTEND noninteractive
66
67RUN apt-get update && apt-get install -yy \
68 python3 \
69 python3-dev\
70 python3-yaml \
71 python3-mako \
72 python3-pip \
73 python3-setuptools \
74 curl \
75 git \
76 wget \
77 sudo \
78 squashfs-tools
79
80# Final configuration for the workspace
Patrick Williams384d7412020-11-06 16:15:41 -060081RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
82RUN mkdir -p $(dirname "${HOME}")
83RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Michael Shepos6e77d112019-02-06 19:09:14 -060084RUN sed -i '1iDefaults umask=000' /etc/sudoers
85RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
86
87RUN /bin/bash
88EOF
89)
90fi
91################################# docker img # #################################
92
93# Build above image
Patrick Williams384d7412020-11-06 16:15:41 -060094docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"