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