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