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