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# default is ubuntu:focal 17 18set -uo pipefail 19 20http_proxy=${http_proxy:-} 21 22DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-robot-qemu"} 23DISTRO=${2:-"ubuntu:focal"} 24UBUNTU_MIRROR=${UBUNTU_MIRROR:-""} 25PIP_MIRROR=${PIP_MIRROR:-""} 26 27# Determine our architecture, ppc64le or the other one 28if [ "$(uname -m)" == "ppc64le" ]; then 29 DOCKER_BASE="ppc64le/" 30else 31 DOCKER_BASE="" 32fi 33 34MIRROR="" 35if [[ -n "${UBUNTU_MIRROR}" ]]; then 36 MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \ 37 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \ 38 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \ 39 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \ 40 echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list" 41fi 42 43PIP_MIRROR_CMD="" 44if [[ -n "${PIP_MIRROR}" ]]; then 45 PIP_HOSTNAME=$(echo "${PIP_MIRROR}" | awk -F[/:] '{print $4}') 46 PIP_MIRROR_CMD="RUN mkdir -p \${HOME}/.pip && \ 47 echo \"[global]\" > \${HOME}/.pip/pip.conf && \ 48 echo \"index-url=${PIP_MIRROR}\" >> \${HOME}/.pip/pip.conf &&\ 49 echo \"[install]\" >> \${HOME}/.pip/pip.conf &&\ 50 echo \"trusted-host=${PIP_HOSTNAME}\" >> \${HOME}/.pip/pip.conf" 51fi 52 53################################# docker img # ################################# 54# Create docker image that can run QEMU and Robot Tests 55Dockerfile=$(cat << EOF 56FROM ${DOCKER_BASE}${DISTRO} 57 58${MIRROR} 59 60ARG DEBIAN_FRONTEND=noninteractive 61 62RUN apt-get update && apt-get install -yy \ 63 debianutils \ 64 gawk \ 65 git \ 66 python \ 67 python-dev \ 68 python-setuptools \ 69 python3 \ 70 python3-dev \ 71 python3-setuptools \ 72 socat \ 73 texinfo \ 74 wget \ 75 gcc \ 76 libffi-dev \ 77 libssl-dev \ 78 xterm \ 79 mwm \ 80 ssh \ 81 vim \ 82 iputils-ping \ 83 sudo \ 84 cpio \ 85 unzip \ 86 diffstat \ 87 expect \ 88 curl \ 89 build-essential \ 90 libpixman-1-0 \ 91 libglib2.0-0 \ 92 sshpass \ 93 libasound2 \ 94 libfdt1 \ 95 libpcre3 \ 96 openssl \ 97 libxml2-dev \ 98 libxslt-dev \ 99 python3-pip \ 100 ipmitool \ 101 xvfb 102 103RUN apt-get update -qqy \ 104 && apt-get -qqy --no-install-recommends install firefox \ 105 && wget --no-verbose -O /tmp/firefox.tar.bz2 https://download-installer.cdn.mozilla.net/pub/firefox/releases/72.0/linux-x86_64/en-US/firefox-72.0.tar.bz2 \ 106 && apt-get -y purge firefox \ 107 && tar -C /opt -xjf /tmp/firefox.tar.bz2 \ 108 && mv /opt/firefox /opt/firefox-72.0 \ 109 && ln -fs /opt/firefox-72.0/firefox /usr/bin/firefox 110 111ENV HOME ${HOME} 112 113${PIP_MIRROR_CMD} 114 115RUN pip3 install \ 116 tox \ 117 requests \ 118 retrying \ 119 websocket-client \ 120 json2yaml \ 121 robotframework \ 122 robotframework-requests \ 123 robotframework-sshlibrary \ 124 robotframework-scplibrary \ 125 pysnmp \ 126 redfish \ 127 beautifulsoup4 --upgrade \ 128 lxml \ 129 jsonschema \ 130 redfishtool \ 131 redfish_utilities \ 132 robotframework-httplibrary \ 133 robotframework-seleniumlibrary \ 134 robotframework-xvfb \ 135 robotframework-angularjs \ 136 scp \ 137 selenium==3.141.0 \ 138 urllib3 \ 139 xvfbwrapper 140 141RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.29.0/geckodriver-v0.29.0-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} -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