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:oracular"} 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 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 liboss4-salsa-asound2 \ 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 --break-system-packages \ 111 tox \ 112 requests \ 113 retrying \ 114 websocket-client \ 115 json2yaml \ 116 robotframework==7.2.2 \ 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 aenum==3.1.15 \ 138 colorama==0.4.6 \ 139 pyasn1==0.6.1 \ 140 pyasn1_modules==0.4.1 \ 141 sseclient-py==1.8.0 142 143RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux64.tar.gz \ 144 && tar xvzf geckodriver-*.tar.gz \ 145 && mv geckodriver /usr/local/bin \ 146 && chmod a+x /usr/local/bin/geckodriver 147 148# pulled from: https://gerrit.openbmc.org/c/openbmc/openbmc-build-scripts/+/71562 149# Latest Ubuntu added a default user (ubuntu), which takes 1000 UID. 150# If the user calling this build script happens to also have a UID of 1000 151# then the container no longer will work. Delete the new ubuntu user 152# so there is no conflict 153RUN userdel -r ubuntu 154RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} 155RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -l -m -u ${UID} -g ${GROUPS[0]} \ 156 ${USER} 157USER ${USER} 158RUN /bin/bash 159EOF 160) 161 162################################# docker img # ################################# 163 164PROXY_ARGS="" 165if [[ -n "${http_proxy}" ]]; then 166 PROXY_ARGS="--build-arg http_proxy=${http_proxy} --build-arg https_proxy=${http_proxy}" 167fi 168 169# Build above image 170# shellcheck disable=SC2086 # PROXY_ARGS is intentionally word-split. 171docker build ${PROXY_ARGS} -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}" 172