Skip to content

Commit 98392b5

Browse files
author
wuhuizuo
committed
Add apt/pypi/npm mirror supports
1 parent 318c3c2 commit 98392b5

File tree

8 files changed

+69
-26
lines changed

8 files changed

+69
-26
lines changed

create_web_container.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
DOCKER_YAML=js/docker/docker-compose-build.yaml
1717
PASSWDS="$USER,hello"
18-
18+
COMPOSE_BUILD_ARGS=""
1919
# Fancy colors in the terminal
2020
if [ -t 1 ]; then
2121
RED=$(tput setaf 1)
@@ -51,6 +51,9 @@ help() {
5151
-s start the container after creation.
5252
-p list of username password pairs. Defaults to: [${PASSWDS}]
5353
-i install systemd service, with definition in /opt/emulator
54+
-n npm mirror registry.
55+
-P python package mirror index.
56+
-A deb apt source mirror.
5457
EOF
5558
exit 1
5659
}
@@ -73,18 +76,20 @@ generate_keys() {
7376
fi
7477
}
7578

76-
while getopts 'hasip:' flag; do
79+
while getopts 'hasip:n:P:A:' flag; do
7780
case "${flag}" in
7881
a) DOCKER_YAML="${DOCKER_YAML} -f js/docker/development.yaml" ;;
7982
p) PASSWDS="${OPTARG}" ;;
8083
h) help ;;
8184
s) START='yes' ;;
8285
i) INSTALL='yes' ;;
86+
n) COMPOSE_BUILD_ARGS="${COMPOSE_BUILD_ARGS} --build-arg npm_mirror=${OPTARG}" ;;
87+
P) COMPOSE_BUILD_ARGS="${COMPOSE_BUILD_ARGS} --build-arg pip_index=${OPTARG}" ;;
88+
A) COMPOSE_BUILD_ARGS="${COMPOSE_BUILD_ARGS} --build-arg apt_repo_mirror=${OPTARG}" ;;
8389
*) help ;;
8490
esac
8591
done
8692

87-
8893
# Create the javascript protobufs
8994
make -C js deps
9095

@@ -105,7 +110,7 @@ cp ~/.android/adbkey js/docker/certs
105110

106111
# compose the container
107112
pip install docker-compose >/dev/null
108-
docker-compose -f ${DOCKER_YAML} build
113+
docker-compose -f ${DOCKER_YAML} build ${COMPOSE_BUILD_ARGS}
109114
rm js/docker/certs/adbkey
110115

111116
if [ "${START}" = "yes" ]; then

emu/cloud_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def cloud_build(args):
9494
steps.append(create_build_step(system_container, args.dest))
9595
else:
9696
for metrics in [True, False]:
97-
emulator_container = EmulatorContainer(emu, system_container, args.repo, metrics)
97+
emulator_container = EmulatorContainer(emu, system_container, args.repo, metrics, args.aptmirror)
9898
emulators.add(emulator_container.props["emu_build_id"])
9999
steps.append(create_build_step(emulator_container, args.dest))
100100
images.append(emulator_container.full_name())

emu/containers/emulator_container.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class EmulatorContainer(DockerContainer):
3030
"""
3131
NO_METRICS_MESSAGE = "No metrics are collected when running this container."
3232

33-
def __init__(self, emulator, system_image_container, repository=None, metrics=False, extra=""):
33+
def __init__(self, emulator, system_image_container, repository=None, metrics=False, extra="", apt_mirror=""):
3434
self.emulator_zip = AndroidReleaseZip(emulator)
3535
self.system_image_container = system_image_container
3636
self.metrics = metrics
@@ -51,6 +51,7 @@ def __init__(self, emulator, system_image_container, repository=None, metrics=Fa
5151
self.props["metrics"] = metrics_msg
5252
self.props["emu_build_id"] = self.emulator_zip.build_id()
5353
self.props["from_base_img"] = system_image_container.full_name()
54+
self.props["run_apt_repo_replace"] = apt_mirror
5455

5556
for expect in [
5657
"ro.build.version.sdk",

emu/emu_docker.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def create_docker_image(args):
9595
if args.sys:
9696
continue
9797

98-
emu_docker = EmulatorContainer(emu, sys_docker, args.repo, cfg.collect_metrics(), args.extra)
98+
emu_docker = EmulatorContainer(emu, sys_docker, args.repo, cfg.collect_metrics(), args.extra, args.aptmirror)
9999
emu_docker.build(args.dest)
100100

101101
if args.start:
@@ -129,7 +129,7 @@ def create_docker_image_interactive(args):
129129
if not sys_docker.available() and not sys_docker.can_pull():
130130
sys_docker.build(args.dest)
131131

132-
emu_docker = EmulatorContainer(emu_zip, sys_docker, args.repo, metrics)
132+
emu_docker = EmulatorContainer(emu_zip, sys_docker, args.repo, metrics, args.aptmirror)
133133
emu_docker.build(args.dest)
134134

135135
if args.start:
@@ -220,6 +220,12 @@ def main():
220220
"All exposed ports are forwarded, and your private adbkey (if available) is injected but not stored.",
221221
)
222222
create_parser.add_argument("--sys", action="store_true", help="Process system image layer only.")
223+
create_parser.add_argument(
224+
"--aptmirror",
225+
default="",
226+
help="Apt repo mirror for apt installing."
227+
'For example http://ftp2.cn.debian.org/',
228+
)
223229
create_parser.set_defaults(func=create_docker_image)
224230

225231
create_inter = subparsers.add_parser(
@@ -249,6 +255,12 @@ def main():
249255
action="store_true",
250256
help="Display arm images. Note that arm images are not hardware accelerated and are *extremely* slow.",
251257
)
258+
create_inter.add_argument(
259+
"--aptmirror",
260+
default="",
261+
help="Apt repo mirror for apt installing. "
262+
'For example http://ftp2.cn.debian.org/',
263+
)
252264
create_inter.set_defaults(func=create_docker_image_interactive)
253265

254266
dist_parser = subparsers.add_parser(
@@ -268,6 +280,12 @@ def main():
268280
dist_parser.add_argument(
269281
"--sys", action="store_true", help="Write system image steps, otherwise write emulator steps."
270282
)
283+
dist_parser.add_argument(
284+
"--aptmirror",
285+
default="",
286+
help="Apt repo mirror for apt installing."
287+
'For example http://ftp2.cn.debian.org/',
288+
)
271289
dist_parser.add_argument(
272290
"emuzip",
273291
help="Zipfile containing the a publicly released emulator, or (canary|stable|[0-9]+) to use the latest canary, stable, or build id of the emulator to use. "

emu/templates/Dockerfile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
# limitations under the License.
1414
{{from_base_img}}
1515

16+
{{run_apt_repo_replace}}
17+
1618
# Install all the required emulator dependencies.
1719
# You can get these by running ./android/scripts/unix/run_tests.sh --verbose --verbose --debs | grep apt | sort -u
1820
# pulse audio is needed due to some webrtc dependencies.
1921
RUN apt-get update && apt-get install -y --no-install-recommends \
20-
# Emulator & video bridge dependencies
22+
# Emulator & video bridge dependencies
2123
libc6 libdbus-1-3 libfontconfig1 libgcc1 \
2224
libpulse0 libtinfo5 libx11-6 libxcb1 libxdamage1 \
2325
libnss3 libxcomposite1 libxcursor1 libxi6 \
2426
libxext6 libxfixes3 zlib1g libgl1 pulseaudio socat \
25-
# Enable turncfg through usage of curl
27+
# Enable turncfg through usage of curl
2628
curl ca-certificates && \
2729
apt-get clean && \
2830
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
@@ -61,11 +63,11 @@ CMD ["/android/sdk/launch-emulator.sh"]
6163

6264
# Note we should use gRPC status endpoint to check for health once the canary release is out.
6365
HEALTHCHECK --interval=30s \
64-
--timeout=30s \
65-
--start-period=30s \
66-
--retries=3 \
67-
CMD /android/sdk/platform-tools/adb shell getprop dev.bootcomplete | grep "1"
66+
--timeout=30s \
67+
--start-period=30s \
68+
--retries=3 \
69+
CMD /android/sdk/platform-tools/adb shell getprop dev.bootcomplete | grep "1"
6870

6971
LABEL maintainer="{{user}}" \
70-
com.google.android.emulator.description="Pixel 2 Emulator, running API {{api}}" \
71-
com.google.android.emulator.version="{{tag}}-{{api}}-{{abi}}/{{emu_build_id}}"
72+
com.google.android.emulator.description="Pixel 2 Emulator, running API {{api}}" \
73+
com.google.android.emulator.version="{{tag}}-{{api}}-{{abi}}/{{emu_build_id}}"

emu/templates/Dockerfile.emulator

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
# limitations under the License.
1414
FROM {{from_base_img}} AS emulator
1515

16+
{{run_apt_repo_replace}}
17+
1618
# Install all the required emulator dependencies.
1719
# You can get these by running ./android/scripts/unix/run_tests.sh --verbose --verbose --debs | grep apt | sort -u
1820
# pulse audio is needed due to some webrtc dependencies.
1921
RUN apt-get update && apt-get install -y --no-install-recommends \
20-
# Emulator & video bridge dependencies
22+
# Emulator & video bridge dependencies
2123
libc6 libdbus-1-3 libfontconfig1 libgcc1 \
2224
libpulse0 libtinfo5 libx11-6 libxcb1 libxdamage1 \
2325
libnss3 libxcomposite1 libxcursor1 libxi6 \
2426
libxext6 libxfixes3 zlib1g libgl1 pulseaudio socat \
25-
# Enable turncfg through usage of curl
27+
# Enable turncfg through usage of curl
2628
curl ca-certificates && \
2729
apt-get clean && \
2830
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
@@ -61,10 +63,10 @@ CMD ["/android/sdk/launch-emulator.sh"]
6163

6264
# Note we should use gRPC status endpoint to check for health once the canary release is out.
6365
HEALTHCHECK --interval=30s \
64-
--timeout=30s \
65-
--start-period=30s \
66-
--retries=3 \
67-
CMD /android/sdk/platform-tools/adb shell getprop dev.bootcomplete | grep "1"
66+
--timeout=30s \
67+
--start-period=30s \
68+
--retries=3 \
69+
CMD /android/sdk/platform-tools/adb shell getprop dev.bootcomplete | grep "1"
6870

6971
LABEL maintainer="{{user}}" \
70-
com.google.android.emulator.version="{{emu_build_id}}"
72+
com.google.android.emulator.version="{{emu_build_id}}"

js/docker/nginx.Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
FROM tiangolo/node-frontend:10 as build-stage
33
WORKDIR /app
44
COPY package*.json /app/
5+
ARG npm_mirror
6+
RUN if [ x"${npm_mirror}" != "x" ]; then \
7+
npm config set registry ${npm_mirror}; \
8+
fi
59
RUN npm install
610
COPY ./ /app/
711
ARG configuration=production

js/jwt-provider/Dockerfile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
FROM debian:stretch-slim
15-
RUN apt-get update -y
16-
RUN apt-get install -y python-pip python-dev build-essential
15+
ARG apt_repo_mirror
16+
RUN if [ x"$apt_repo_mirror" != "x" ]; then \
17+
sed -i -E "s#http(s)?://[^\/]+#${apt_repo_mirror}#g" /etc/apt/sources.list; \
18+
fi
19+
RUN apt-get update -y && \
20+
apt-get install -y python-pip python-dev build-essential && \
21+
apt-get clean && \
22+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
1723
COPY . /app
1824
WORKDIR /app
19-
RUN pip install -r requirements.txt
25+
ARG pip_index
26+
RUN if [ x"$pip_index" = "x" ]; then \
27+
pip install -r requirements.txt; \
28+
else \
29+
pip install -i ${pip_index} -r requirements.txt; \
30+
fi
2031
ENTRYPOINT ["python"]
2132
CMD ["jwt-provider.py"]

0 commit comments

Comments
 (0)