Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 33 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,28 @@ ARG BRANCH_OVERRIDE
# 5. "prod" - Creates the final production image with the Label Studio, Nginx, and other dependencies.

################################ Stage: frontend-builder (build frontend assets)
FROM --platform=${BUILDPLATFORM} node:${NODE_VERSION}-trixie AS frontend-builder
FROM --platform=${BUILDPLATFORM} node:${NODE_VERSION}-alpine AS frontend-builder
ENV BUILD_NO_SERVER=true \
BUILD_NO_HASH=true \
BUILD_NO_CHUNKS=true \
BUILD_MODULE=true \
YARN_CACHE_FOLDER=/root/web/.yarn \
NX_CACHE_DIRECTORY=/root/web/.nx \
NODE_ENV=production
NODE_ENV=production \
NODE_OPTIONS="--max-old-space-size=4096"

WORKDIR /label-studio/web

# Fix Docker Arm64 Build
RUN yarn config set registry https://registry.npmjs.org/
RUN yarn config set network-timeout 1200000 # HTTP timeout used when downloading packages, set to 20 minutes
RUN apk add --no-cache \
build-base \
pkgconfig \
cairo-dev \
giflib-dev \
libjpeg-turbo-dev \
libpng-dev \
pango-dev \
git \
python3

COPY web/package.json .
COPY web/yarn.lock .
Expand All @@ -52,8 +60,9 @@ RUN --mount=type=cache,target=/root/web/.yarn,id=yarn-cache,sharing=locked \
yarn version:libs

################################ Stage: venv-builder (prepare the virtualenv)
FROM python:${PYTHON_VERSION}-slim-trixie AS venv-builder
FROM python:${PYTHON_VERSION}-alpine AS venv-builder
ARG POETRY_VERSION
ARG PYTHON_VERSION

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
Expand All @@ -67,17 +76,16 @@ ENV PYTHONUNBUFFERED=1 \
POETRY_VIRTUALENVS_PREFER_ACTIVE_PYTHON=true \
PATH="/opt/poetry/bin:$PATH"

RUN apk add --no-cache \
build-base \
git \
linux-headers \
python3-dev \
pcre2-dev

ADD https://install.python-poetry.org /tmp/install-poetry.py
RUN python /tmp/install-poetry.py

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
set -eux; \
apt-get update; \
apt-get install --no-install-recommends -y \
build-essential git; \
apt-get autoremove -y

WORKDIR /label-studio

ENV VENV_PATH="/label-studio/.venv"
Expand All @@ -92,7 +100,7 @@ COPY pyproject.toml poetry.lock README.md ./
ARG INCLUDE_DEV=false

# Install dependencies
RUN --mount=type=cache,target=/.poetry-cache,id=poetry-cache,sharing=locked \
RUN --mount=type=cache,target=/.poetry-cache,id=poetry-cache-alpine,sharing=locked \
poetry check --lock && \
if [ "$INCLUDE_DEV" = "true" ]; then \
poetry install --no-root --extras uwsgi --with test; \
Expand All @@ -102,7 +110,7 @@ RUN --mount=type=cache,target=/.poetry-cache,id=poetry-cache,sharing=locked \

# Install LS
COPY label_studio label_studio
RUN --mount=type=cache,target=/.poetry-cache,id=poetry-cache,sharing=locked \
RUN --mount=type=cache,target=/.poetry-cache,id=poetry-cache-alpine,sharing=locked \
# `--extras uwsgi` is mandatory here due to poetry bug: https://github.com/python-poetry/poetry/issues/7302
poetry install --only-root --extras uwsgi && \
python3 label_studio/manage.py collectstatic --no-input
Expand All @@ -117,7 +125,7 @@ RUN --mount=type=bind,source=.git,target=./.git \
VERSION_OVERRIDE=${VERSION_OVERRIDE} BRANCH_OVERRIDE=${BRANCH_OVERRIDE} poetry run python label_studio/core/version.py

################################### Stage: prod
FROM python:${PYTHON_VERSION}-slim-trixie AS production
FROM python:${PYTHON_VERSION}-alpine AS production

ENV LS_DIR=/label-studio \
HOME=/label-studio \
Expand All @@ -131,14 +139,14 @@ ENV LS_DIR=/label-studio \
WORKDIR $LS_DIR

# install prerequisites for app
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
set -eux; \
apt-get update; \
apt-get upgrade -y; \
apt-get install --no-install-recommends -y libexpat1 libgl1 libglx-mesa0 libglib2.0-0t64 \
gnupg2 curl nginx; \
apt-get autoremove -y
RUN apk add --no-cache \
expat \
mesa-gl \
glib \
curl \
nginx \
bash \
procps

RUN set -eux; \
mkdir -p $LS_DIR $LABEL_STUDIO_BASE_DATA_DIR $OPT_DIR && \
Expand Down
Loading