Skip to content

Commit 6b56e2e

Browse files
MasonXonmason
andauthored
fix: Multiple building errors fixed and adapt to multiple platforms (#3)
Co-authored-by: mason <[email protected]>
1 parent 6d61812 commit 6b56e2e

File tree

1 file changed

+66
-49
lines changed

1 file changed

+66
-49
lines changed

Dockerfile

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# syntax=docker/dockerfile:1
1+
# syntax=docker/dockerfile:1.6
22
ARG NODE_VERSION=22
33
ARG PYTHON_VERSION=3.12
44
ARG POETRY_VERSION=2.1.3
55
ARG VERSION_OVERRIDE
66
ARG BRANCH_OVERRIDE
7-
ARG BUILDPLATFORM=linux/amd64
7+
ARG BUILD_CN=false
88

99
################################ Overview
1010

@@ -17,7 +17,8 @@ ARG BUILDPLATFORM=linux/amd64
1717
# 5. "prod" - Creates the final production image with the Label Studio, Nginx, and other dependencies.
1818

1919
################################ Stage: frontend-builder (build frontend assets)
20-
FROM --platform=${BUILDPLATFORM} node:${NODE_VERSION} AS frontend-builder
20+
FROM node:${NODE_VERSION} AS frontend-builder
21+
2122
ENV BUILD_NO_SERVER=true \
2223
BUILD_NO_HASH=true \
2324
BUILD_NO_CHUNKS=true \
@@ -29,24 +30,30 @@ ENV BUILD_NO_SERVER=true \
2930
WORKDIR /label-studio/web
3031

3132
# Fix Docker Arm64 Build
32-
RUN yarn config set registry https://registry.npmmirror.com/ \
33-
&& yarn config set disturl https://npmmirror.com/dist \
34-
&& yarn config set electron_mirror https://npmmirror.com/mirrors/electron/ \
35-
&& yarn config set puppeteer_download_host https://npmmirror.com/mirrors/ \
36-
&& yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver/ \
37-
&& yarn config set operadriver_cdnurl https://npmmirror.com/mirrors/operadriver/ \
38-
&& yarn config set phantomjs_cdnurl https://npmmirror.com/mirrors/phantomjs/ \
39-
&& yarn config set sass_binary_site https://npmmirror.com/mirrors/node-sass/ \
40-
&& yarn config set python_mirror https://npmmirror.com/mirrors/python/
41-
RUN yarn config set network-timeout 1200000 # HTTP timeout used when downloading packages, set to 20 minutes
42-
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/; \
42+
yarn config set network-timeout 1200000
4343

4444
COPY web/package.json .
4545
COPY web/yarn.lock .
4646
COPY web/tools tools
4747
RUN --mount=type=cache,target=${YARN_CACHE_FOLDER},sharing=locked \
4848
--mount=type=cache,target=${NX_CACHE_DIRECTORY},sharing=locked \
49-
yarn install --prefer-offline --no-progress --pure-lockfile --frozen-lockfile --ignore-engines --non-interactive --production=false
49+
--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
5057

5158
COPY web .
5259
COPY pyproject.toml ../pyproject.toml
@@ -56,9 +63,10 @@ RUN --mount=type=cache,target=${YARN_CACHE_FOLDER},sharing=locked \
5663

5764
################################ Stage: frontend-version-generator
5865
FROM frontend-builder AS frontend-version-generator
66+
5967
RUN --mount=type=cache,target=${YARN_CACHE_FOLDER},sharing=locked \
6068
--mount=type=cache,target=${NX_CACHE_DIRECTORY},sharing=locked \
61-
--mount=type=bind,source=.git,target=../.git \
69+
--mount=type=bind,source=.git,target=/label-studio/.git \
6270
yarn version:libs
6371

6472
################################ Stage: venv-builder (prepare the virtualenv)
@@ -79,14 +87,16 @@ ENV PYTHONUNBUFFERED=1 \
7987
ADD https://install.python-poetry.org /tmp/install-poetry.py
8088
RUN python /tmp/install-poetry.py
8189

82-
RUN sed -i 's#http://.*archive.ubuntu.com/#http://mirrors.aliyun.com/#' /etc/apt/sources.list && \
83-
--mount=type=cache,target="/var/cache/apt",sharing=locked \
90+
ARG BUILD_CN=false
91+
RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
8492
--mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
8593
set -eux; \
94+
if [ "$BUILD_CN" = "true" ]; then \
95+
sed -i 's#http://.*archive.ubuntu.com/#http://mirrors.aliyun.com/#' /etc/apt/sources.list; \
96+
fi; \
8697
apt-get update; \
87-
apt-get install --no-install-recommends -y \
88-
build-essential git; \
89-
apt-get autoremove -y
98+
apt-get install --no-install-recommends -y build-essential git; \
99+
apt-get clean; rm -rf /var/lib/apt/lists/*
90100

91101
WORKDIR /label-studio
92102

@@ -105,39 +115,39 @@ ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ \
105115

106116
# Install dependencies without dev packages
107117
RUN --mount=type=cache,target=$POETRY_CACHE_DIR,sharing=locked \
108-
poetry lock && \
109-
poetry check --lock && \
118+
poetry lock; \
119+
poetry check --lock; \
110120
if [ "$INCLUDE_DEV" = "true" ]; then \
111-
poetry install --no-root --extras uwsgi --with test; \
121+
poetry install --no-interaction --no-ansi --no-root --extras uwsgi --with test; \
112122
else \
113-
poetry install --no-root --without test --extras uwsgi; \
123+
poetry install --no-interaction --no-ansi --no-root --without test --extras uwsgi; \
114124
fi
115125

116126
# Install LS
117127
COPY label_studio label_studio
118128
RUN --mount=type=cache,target=$POETRY_CACHE_DIR,sharing=locked \
119129
# `--extras uwsgi` is mandatory here due to poetry bug: https://github.com/python-poetry/poetry/issues/7302
120-
poetry install --only-root --extras uwsgi && \
130+
poetry install --only-root --extras uwsgi; \
121131
python3 label_studio/manage.py collectstatic --no-input
122132

123133
################################ Stage: py-version-generator
124134
FROM venv-builder AS py-version-generator
125-
ARG VERSION_OVERRIDERUN --mount=type=cache,target="/var/cache/apt",sharing=locked --mount=type=cache,ta
135+
ARG VERSION_OVERRIDE
126136
ARG BRANCH_OVERRIDE
127137

128138
# Create version_.py and ls-version_.py
129-
RUN --mount=type=bind,source=.git,target=./.git \
139+
RUN --mount=type=bind,source=.git,target=/label-studio/.git \
130140
VERSION_OVERRIDE=${VERSION_OVERRIDE} BRANCH_OVERRIDE=${BRANCH_OVERRIDE} poetry run python label_studio/core/version.py
131141

132142
FROM python:${PYTHON_VERSION}-slim AS production
133143

134144
# update sources list to use Aliyun mirrors
135-
RUN sed -i 's#http://.*archive.ubuntu.com/#http://mirrors.aliyun.com/#' /etc/apt/sources.list && \
136-
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" > /etc/apt/sources.list && \
137-
echo "deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" >> /etc/apt/sources.list && \
138-
echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list && \
139-
echo "deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list && \
140-
echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list && \
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; \
141151
echo "deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list
142152

143153
ENV LS_DIR=/label-studio \
@@ -151,33 +161,40 @@ ENV LS_DIR=/label-studio \
151161

152162
WORKDIR $LS_DIR
153163

154-
155164
# install prerequisites for app
156-
RUN sed -i 's#http://.*archive.ubuntu.com/#http://mirrors.aliyun.com/#' /etc/apt/sources.list && \
157-
--mount=type=cache,target="/var/cache/apt",sharing=locked \
165+
ARG BUILD_CN=false
166+
RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
158167
--mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
159168
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; \
160172
apt-get update; \
161-
# apt-get upgrade -y; \
162-
apt-get install --no-install-recommends -y libexpat1 libgl1-mesa-glx libglib2.0-0 \
163-
gnupg2 curl; \
164-
apt-get autoremove -y
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/*
165180

166181
# install nginx
167-
RUN sed -i 's#http://deb.debian.org/debian#https://mirrors.tuna.tsinghua.edu.cn/debian#' && \
168-
--mount=type=cache,target="/var/cache/apt",sharing=locked \
182+
RUN --mount=type=cache,target="/var/cache/apt",sharing=locked \
169183
--mount=type=cache,target="/var/lib/apt/lists",sharing=locked \
170184
set -eux; \
185+
mkdir -p /etc/apt/keyrings; \
186+
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; \
188+
fi; \
171189
curl -sSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor -o /etc/apt/keyrings/nginx-archive-keyring.gpg >/dev/null; \
172-
DEBIAN_VERSION=$(awk -F '=' '/^VERSION_CODENAME=/ {print $2}' /etc/os-release); \
173-
printf "deb [signed-by=/etc/apt/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian ${DEBIAN_VERSION} nginx\n" > /etc/apt/sources.list.d/nginx.list; \
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; \
174191
printf "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" > /etc/apt/preferences.d/99nginx; \
175192
apt-get update; \
176-
apt-get install --no-install-recommends -y nginx; \
177-
apt-get autoremove -y
193+
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y nginx; \
194+
apt-get clean; rm -rf /var/lib/apt/lists/*
178195

179196
RUN set -eux; \
180-
mkdir -p $LS_DIR $LABEL_STUDIO_BASE_DATA_DIR $OPT_DIR && \
197+
mkdir -p $LS_DIR $LABEL_STUDIO_BASE_DATA_DIR $OPT_DIR; \
181198
chown -R 1001:0 $LS_DIR $LABEL_STUDIO_BASE_DATA_DIR $OPT_DIR /var/log/nginx /etc/nginx
182199

183200
COPY --chown=1001:0 deploy/default.conf /etc/nginx/nginx.conf
@@ -204,5 +221,5 @@ USER 1001
204221

205222
EXPOSE 8080
206223

207-
ENTRYPOINT ["./deploy/docker-entrypoint.sh"]
224+
ENTRYPOINT ["/label-studio/deploy/docker-entrypoint.sh"]
208225
CMD ["label-studio"]

0 commit comments

Comments
 (0)