build-rootfs-size-docker: Enable proxy

Add http_proxy and UBUNTU_MIRROR support as build-setup.sh, so that it
is possible to make the script work behind a proxy and use a different
ubuntu mirror.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I833d24e3f3ccef19abfb01cdb9c62b3d8a195b35
diff --git a/build-rootfs-size-docker.sh b/build-rootfs-size-docker.sh
index 36876f4..eb2b351 100755
--- a/build-rootfs-size-docker.sh
+++ b/build-rootfs-size-docker.sh
@@ -6,6 +6,14 @@
 #   DOCKER_IMG_NAME:  <optional, the name of the docker image to generate>
 #                     default is openbmc/ubuntu-rootfs-size
 #   DISTRO:           <optional, the distro to build a docker image against>
+#   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
+
+http_proxy=${http_proxy:-}
+UBUNTU_MIRROR=${UBUNTU_MIRROR:-""}
 
 set -uo pipefail
 
@@ -29,12 +37,31 @@
         exit 1
 esac
 
+PROXY=""
+
+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 # #################################
 
 if [[ "${DISTRO}" == "ubuntu"* ]]; then
+
+if [[ -n "${http_proxy}" ]]; then
+  PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
+fi
+
 Dockerfile=$(cat << EOF
 FROM ${DOCKER_BASE}${DISTRO}
 
+${PROXY}
+${MIRROR}
+
 ENV DEBIAN_FRONTEND noninteractive
 
 RUN apt-get update && apt-get install -yy \