xref: /openbmc/openbmc-build-scripts/scripts/build-qemu-robot-docker.sh (revision b80ea07bdfebe8e2acfb566f15f29bb652f3653c)
1#!/bin/bash -xe
2#
3# Build the required docker image to run QEMU and Robot test cases
4
5# Script Variables:
6#  UBUNTU_MIRROR:    <optional, the URL of a mirror of Ubuntu to override the
7#                    default ones in /etc/apt/sources.list>
8#                    default is empty, and no mirror is used.
9#  PIP_MIRROR:       <optional, the URL of a PIP mirror>
10#                    default is empty, and no mirror is used.
11#  DOCKER_REG:       <optional, the URL of a docker registry to utilize
12#                    instead of the default docker hub
13#                    (ex. public.ecr.aws/ubuntu)
14#
15#  Parameters:
16#   parm1:  <optional, the name of the docker image to generate>
17#            default is openbmc/ubuntu-robot-qemu
18#   param2: <optional, the distro to build a docker image against>
19
20set -uo pipefail
21
22http_proxy=${http_proxy:-}
23
24DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-robot-qemu"}
25DISTRO=${2:-"ubuntu:jammy"}
26UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
27PIP_MIRROR=${PIP_MIRROR:-""}
28docker_reg=${DOCKER_REG:-"docker.io"}
29
30MIRROR=""
31if [[ -n "${UBUNTU_MIRROR}" ]]; then
32    MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
33        echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
34        echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
35        echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
36        echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
37fi
38
39PIP_MIRROR_CMD=""
40if [[ -n "${PIP_MIRROR}" ]]; then
41    PIP_HOSTNAME=$(echo "${PIP_MIRROR}" | awk -F[/:] '{print $4}')
42    PIP_MIRROR_CMD="RUN mkdir -p \${HOME}/.pip && \
43        echo \"[global]\" > \${HOME}/.pip/pip.conf && \
44        echo \"index-url=${PIP_MIRROR}\" >> \${HOME}/.pip/pip.conf &&\
45        echo \"[install]\" >> \${HOME}/.pip/pip.conf &&\
46        echo \"trusted-host=${PIP_HOSTNAME}\" >> \${HOME}/.pip/pip.conf"
47fi
48
49################################# docker img # #################################
50# Create docker image that can run QEMU and Robot Tests
51Dockerfile=$(cat << EOF
52FROM ${docker_reg}/${DISTRO}
53
54${MIRROR}
55
56ARG DEBIAN_FRONTEND=noninteractive
57
58RUN apt-get update && apt-get install -yy \
59    debianutils \
60    gawk \
61    git \
62    python2 \
63    python2-dev \
64    python-setuptools \
65    python3 \
66    python3-dev \
67    python3-setuptools \
68    socat \
69    texinfo \
70    wget \
71    gcc \
72    libffi-dev \
73    libssl-dev \
74    xterm \
75    mwm \
76    ssh \
77    vim \
78    iputils-ping \
79    sudo \
80    cpio \
81    unzip \
82    diffstat \
83    expect \
84    curl \
85    build-essential \
86    libdbus-glib-1-2 \
87    libpixman-1-0 \
88    libglib2.0-0 \
89    sshpass \
90    libasound2 \
91    libfdt1 \
92    libpcre3 \
93    libslirp-dev \
94    openssl \
95    libxml2-dev \
96    libxslt-dev \
97    python3-pip \
98    ipmitool \
99    xvfb \
100    rustc
101
102RUN apt-get update -qqy \
103  && apt-get -qqy --no-install-recommends install firefox \
104  && wget --no-verbose -O /tmp/firefox.tar.bz2 https://download-installer.cdn.mozilla.net/pub/firefox/releases/112.0.2/linux-x86_64/en-US/firefox-112.0.2.tar.bz2 \
105  && apt-get -y purge firefox \
106  && tar -C /opt -xjf /tmp/firefox.tar.bz2 \
107  && mv /opt/firefox /opt/firefox-112.0.2 \
108  && ln -fs /opt/firefox-112.0.2/firefox /usr/bin/firefox
109
110ENV HOME ${HOME}
111
112${PIP_MIRROR_CMD}
113
114RUN pip3 install \
115    tox \
116    requests \
117    retrying \
118    websocket-client \
119    json2yaml \
120    robotframework==7.0.1 \
121    robotframework-requests \
122    robotframework-jsonlibrary \
123    robotframework-sshlibrary \
124    robotframework-scplibrary \
125    pysnmp \
126    redfish>=3.1.7 \
127    beautifulsoup4 --upgrade \
128    lxml \
129    jsonschema \
130    redfishtool \
131    redfish_utilities \
132    robotframework-httplibrary \
133    robotframework-seleniumlibrary==6.0.0 \
134    robotframework-xvfb==1.2.2 \
135    robotframework-angularjs \
136    scp \
137    selenium==4.8.2 \
138    urllib3 \
139    click \
140    xvfbwrapper==0.2.9
141
142RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux64.tar.gz \
143        && tar xvzf geckodriver-*.tar.gz \
144        && mv geckodriver /usr/local/bin \
145        && chmod a+x /usr/local/bin/geckodriver
146
147RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
148RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -l -m -u ${UID} -g ${GROUPS[0]} \
149                    ${USER}
150USER ${USER}
151RUN /bin/bash
152EOF
153)
154
155################################# docker img # #################################
156
157PROXY_ARGS=""
158if [[ -n "${http_proxy}" ]]; then
159    PROXY_ARGS="--build-arg http_proxy=${http_proxy} --build-arg https_proxy=${http_proxy}"
160fi
161
162# Build above image
163# shellcheck disable=SC2086 # PROXY_ARGS is intentionally word-split.
164docker build ${PROXY_ARGS} -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"
165