Skip to content

Commit 54f307d

Browse files
Improve Dockerfile for build speed (#5)
- Update yarn config for Chinese registry - Simplify conditional statements - Remove outdated Aliyun mirror settings - Adjust apt sources for Debian mirrors - Install nginx in a single command Co-authored-by: Haihui.Wang <[email protected]>
1 parent 6b56e2e commit 54f307d

File tree

1 file changed

+25
-53
lines changed

1 file changed

+25
-53
lines changed

Dockerfile

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,20 @@ ENV BUILD_NO_SERVER=true \
3030
WORKDIR /label-studio/web
3131

3232
# Fix Docker Arm64 Build
33-
RUN yarn config set registry https://registry.npmmirror.com/; \
34-
yarn config set disturl https://npmmirror.com/dist; \
35-
yarn config set electron_mirror https://npmmirror.com/mirrors/electron/; \
36-
yarn config set puppeteer_download_host https://npmmirror.com/mirrors/; \
37-
yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver/; \
38-
yarn config set operadriver_cdnurl https://npmmirror.com/mirrors/operadriver/; \
39-
yarn config set phantomjs_cdnurl https://npmmirror.com/mirrors/phantomjs/; \
40-
yarn config set sass_binary_site https://npmmirror.com/mirrors/node-sass/; \
41-
yarn config set python_mirror https://npmmirror.com/mirrors/python/; \
33+
RUN set -eux; \
34+
if [ "${BUILD_CN:-false}" = "true" ]; then \
35+
yarn config set registry https://registry.npmmirror.com/ && \
36+
yarn config set disturl https://npmmirror.com/dist && \
37+
yarn config set electron_mirror https://npmmirror.com/mirrors/electron/ && \
38+
yarn config set puppeteer_download_host https://npmmirror.com/mirrors/ && \
39+
yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver/ && \
40+
yarn config set operadriver_cdnurl https://npmmirror.com/mirrors/operadriver/ && \
41+
yarn config set phantomjs_cdnurl https://npmmirror.com/mirrors/phantomjs/ && \
42+
yarn config set sass_binary_site https://npmmirror.com/mirrors/node-sass/ && \
43+
yarn config set python_mirror https://npmmirror.com/mirrors/python/; \
44+
else \
45+
yarn config set registry https://registry.npmjs.org/; \
46+
fi; \
4247
yarn config set network-timeout 1200000
4348

4449
COPY web/package.json .
@@ -47,13 +52,7 @@ COPY web/tools tools
4752
RUN --mount=type=cache,target=${YARN_CACHE_FOLDER},sharing=locked \
4853
--mount=type=cache,target=${NX_CACHE_DIRECTORY},sharing=locked \
4954
--mount=type=cache,target=/root/.cache/yarn,sharing=locked \
50-
yarn install \
51-
--prefer-offline \
52-
--no-progress \
53-
--frozen-lockfile \
54-
--ignore-engines \
55-
--non-interactive \
56-
--production=false
55+
yarn install --prefer-offline --no-progress --frozen-lockfile --ignore-engines --non-interactive --production=false
5756

5857
COPY web .
5958
COPY pyproject.toml ../pyproject.toml
@@ -92,7 +91,7 @@ RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
9291
--mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
9392
set -eux; \
9493
if [ "$BUILD_CN" = "true" ]; then \
95-
sed -i 's#http://.*archive.ubuntu.com/#http://mirrors.aliyun.com/#' /etc/apt/sources.list; \
94+
sed -i 's#http://deb.debian.org/#https://mirrors.tuna.tsinghua.edu.cn/#' /etc/apt/sources.list.d/debian.sources; \
9695
fi; \
9796
apt-get update; \
9897
apt-get install --no-install-recommends -y build-essential git; \
@@ -110,13 +109,16 @@ COPY pyproject.toml poetry.lock README.md ./
110109

111110
# Set a default build argument for including dev dependencies
112111
ARG INCLUDE_DEV=false
113-
ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ \
114-
PIP_TRUSTED_HOST=mirrors.aliyun.com
115112

116113
# Install dependencies without dev packages
117114
RUN --mount=type=cache,target=$POETRY_CACHE_DIR,sharing=locked \
118-
poetry lock; \
119-
poetry check --lock; \
115+
if [ "$BUILD_CN" = "true" ]; then \
116+
poetry config repositories.tuna https://pypi.tuna.tsinghua.edu.cn/simple/ && \
117+
poetry config pypi-token.pypi --unset && \
118+
poetry source add --priority=primary tuna https://pypi.tuna.tsinghua.edu.cn/simple/; \
119+
fi && \
120+
poetry lock && \
121+
poetry check --lock && \
120122
if [ "$INCLUDE_DEV" = "true" ]; then \
121123
poetry install --no-interaction --no-ansi --no-root --extras uwsgi --with test; \
122124
else \
@@ -141,15 +143,6 @@ RUN --mount=type=bind,source=.git,target=/label-studio/.git \
141143

142144
FROM python:${PYTHON_VERSION}-slim AS production
143145

144-
# update sources list to use Aliyun mirrors
145-
RUN sed -i 's#http://.*archive.ubuntu.com/#http://mirrors.aliyun.com/#' /etc/apt/sources.list; \
146-
echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" > /etc/apt/sources.list; \
147-
echo "deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" >> /etc/apt/sources.list; \
148-
echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list; \
149-
echo "deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list; \
150-
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list; \
151-
echo "deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list
152-
153146
ENV LS_DIR=/label-studio \
154147
HOME=/label-studio \
155148
LABEL_STUDIO_BASE_DATA_DIR=/label-studio/data \
@@ -165,32 +158,11 @@ WORKDIR $LS_DIR
165158
ARG BUILD_CN=false
166159
RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
167160
--mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
168-
set -eux; \
169-
if [ "$BUILD_CN" = "true" ]; then \
170-
sed -i 's#http://.*archive.ubuntu.com/#http://mirrors.aliyun.com/#' /etc/apt/sources.list; \
171-
fi; \
172-
apt-get update; \
173-
apt-get install --no-install-recommends -y \
174-
libexpat1 \
175-
libgl1-mesa-glx \
176-
libglib2.0-0 \
177-
gnupg2 \
178-
curl; \
179-
apt-get clean; rm -rf /var/lib/apt/lists/*
180-
181-
# install nginx
182-
RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
183-
--mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
184-
set -eux; \
185-
mkdir -p /etc/apt/keyrings; \
186161
if [ "$BUILD_CN" = "true" ]; then \
187-
sed -i 's#http://deb.debian.org/debian#https://mirrors.tuna.tsinghua.edu.cn/debian#' /etc/apt/sources.list; \
162+
sed -i 's#http://deb.debian.org/#https://mirrors.tuna.tsinghua.edu.cn/#' /etc/apt/sources.list.d/debian.sources; \
188163
fi; \
189-
curl -sSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor -o /etc/apt/keyrings/nginx-archive-keyring.gpg >/dev/null; \
190-
echo "deb [signed-by=/etc/apt/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian $(. /etc/os-release && echo $VERSION_CODENAME) nginx" > /etc/apt/sources.list.d/nginx.list; \
191-
printf "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" > /etc/apt/preferences.d/99nginx; \
192164
apt-get update; \
193-
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y nginx; \
165+
apt-get install --no-install-recommends -y libexpat1 libgl1 libglx-mesa0 libglib2.0-0t64 gnupg2 curl nginx; \
194166
apt-get clean; rm -rf /var/lib/apt/lists/*
195167

196168
RUN set -eux; \

0 commit comments

Comments
 (0)