blob: cde66e62a388b613f02f5b7dcd43b985f200534f [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>
Michael Shepos6e77d112019-02-06 19:09:14 -06009
10set -uo pipefail
11
12DOCKER_IMG_NAME=${DOCKER_IMG_NAME:-"openbmc/ubuntu-rootfs-size"}
13DISTRO=${DISTRO:-"ubuntu:bionic"}
14
15# Determine the architecture
16ARCH=$(uname -m)
17case ${ARCH} in
18 "ppc64le")
19 DOCKER_BASE="ppc64le/"
20 ;;
21 "x86_64")
22 DOCKER_BASE=""
23 ;;
Thang Q. Nguyen051b05b2021-12-10 08:30:35 +000024 "aarch64")
25 DOCKER_BASE=""
26 ;;
Michael Shepos6e77d112019-02-06 19:09:14 -060027 *)
28 echo "Unsupported system architecture(${ARCH}) found for docker image"
29 exit 1
30esac
31
32################################# docker img # #################################
33
34if [[ "${DISTRO}" == "ubuntu"* ]]; then
35Dockerfile=$(cat << EOF
36FROM ${DOCKER_BASE}${DISTRO}
37
38ENV DEBIAN_FRONTEND noninteractive
39
40RUN apt-get update && apt-get install -yy \
41 python3 \
42 python3-dev\
43 python3-yaml \
44 python3-mako \
45 python3-pip \
46 python3-setuptools \
47 curl \
48 git \
49 wget \
50 sudo \
51 squashfs-tools
52
53# Final configuration for the workspace
Patrick Williams384d7412020-11-06 16:15:41 -060054RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
55RUN mkdir -p $(dirname "${HOME}")
56RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
Michael Shepos6e77d112019-02-06 19:09:14 -060057RUN sed -i '1iDefaults umask=000' /etc/sudoers
58RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
59
60RUN /bin/bash
61EOF
62)
63fi
64################################# docker img # #################################
65
66# Build above image
Patrick Williams384d7412020-11-06 16:15:41 -060067docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"