unit-test: Set git proxy in docker
Some repos will download externalprojects via git, and it could be
slow in some network environment.
Set git proxy in $HOME/.gitconfig in the docker container so that git
could use the proxy to speedup the download.
Tested: Verify it's faster to run repo-ci on dbus-sensors that downloads
nlohmann-json project via git. Without this change, it's very
slow and eventually fails due to timeout.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Ifd480dc7d4003ec21251d6077caf33baf3b622ef
diff --git a/build-unit-test-docker.sh b/build-unit-test-docker.sh
index d5ddcd4..12e90fc 100755
--- a/build-unit-test-docker.sh
+++ b/build-unit-test-docker.sh
@@ -14,6 +14,8 @@
# 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.
+# http_proxy The HTTP address of the proxy server to connect to.
+# Default: "", proxy is not setup if this is not set
set -xeuo pipefail
@@ -21,6 +23,7 @@
DISTRO=${DISTRO:-"ubuntu:focal"}
BRANCH=${BRANCH:-"master"}
UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
+http_proxy=${http_proxy:-}
# Determine the architecture
ARCH=$(uname -m)
@@ -180,6 +183,12 @@
fi
+PROXY_CMD=""
+if [[ -n "${http_proxy}" ]]; then
+ PROXY_CMD="RUN echo \"[http]\" > \$HOME/.gitconfig && \
+ echo \"proxy = ${http_proxy}\" >> \$HOME/.gitconfig"
+fi
+
Dockerfile=$(cat << EOF
FROM ${DOCKER_BASE}${DISTRO} as openbmc-base
@@ -507,13 +516,14 @@
RUN sed -i '1iDefaults umask=000' /etc/sudoers
RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
+${PROXY_CMD}
+
RUN /bin/bash
EOF
)
fi
################################# docker img # #################################
-http_proxy=${http_proxy:-}
proxy_args=""
if [[ -n "${http_proxy}" ]]; then
proxy_args="--build-arg http_proxy=${http_proxy} --build-arg https_proxy=${http_proxy}"