build-qemu-robot-docker: Use apt mirror
When UBUNTU_MIRROR is set, use apt mirror to speed up the apt downloads.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Ie2ae670a2f0c019c082e87f55c3e3b8eddd4e8d0
diff --git a/scripts/build-qemu-robot-docker.sh b/scripts/build-qemu-robot-docker.sh
index 581fe8e..5daca44 100755
--- a/scripts/build-qemu-robot-docker.sh
+++ b/scripts/build-qemu-robot-docker.sh
@@ -1,6 +1,11 @@
#!/bin/bash -xe
#
# Build the required docker image to run QEMU and Robot test cases
+
+# Script Variables:
+# UBUNTU_MIRROR: <optional, the URL of a mirror of Ubuntu to override the
+# default ones in /etc/apt/sources.list>
+# default is empty, and no mirror is used.
#
# Parameters:
# parm1: <optional, the name of the docker image to generate>
@@ -14,6 +19,7 @@
DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-robot-qemu"}
DISTRO=${2:-"ubuntu:bionic"}
+UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
# Determine our architecture, ppc64le or the other one
if [ $(uname -m) == "ppc64le" ]; then
@@ -22,11 +28,22 @@
DOCKER_BASE=""
fi
+MIRROR=""
+if [[ -n "${UBUNTU_MIRROR}" ]]; then
+ MIRROR="RUN echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME) main restricted universe multiverse\" > /etc/apt/sources.list && \
+ echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-updates main restricted universe multiverse\" >> /etc/apt/sources.list && \
+ echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-security main restricted universe multiverse\" >> /etc/apt/sources.list && \
+ echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-proposed main restricted universe multiverse\" >> /etc/apt/sources.list && \
+ echo \"deb ${UBUNTU_MIRROR} \$(. /etc/os-release && echo \$VERSION_CODENAME)-backports main restricted universe multiverse\" >> /etc/apt/sources.list"
+fi
+
################################# docker img # #################################
# Create docker image that can run QEMU and Robot Tests
Dockerfile=$(cat << EOF
FROM ${DOCKER_BASE}${DISTRO}
+${MIRROR}
+
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -yy \