Skip to content

Commit 2f0d76f

Browse files
committed
feat: label-studio构建脚本
1 parent 1ac1bb6 commit 2f0d76f

File tree

7 files changed

+70
-213
lines changed

7 files changed

+70
-213
lines changed

.github/workflows/docker-image-backend.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ on:
55
branches: [ "main" ]
66
paths:
77
- 'backend/**'
8+
- '!backend/api-gateway/**'
89
- 'scripts/images/backend/**'
910
- '.github/workflows/docker-image-backend.yml'
1011
- '.github/workflows/docker-images-reusable.yml'
1112
pull_request:
1213
branches: [ "main" ]
1314
paths:
1415
- 'backend/**'
16+
- '!backend/api-gateway/**'
1517
- 'scripts/images/backend/**'
1618
- '.github/workflows/docker-image-backend.yml'
1719
- '.github/workflows/docker-images-reusable.yml'

.github/workflows/docker-image-gateway.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ on:
44
push:
55
branches: [ "main" ]
66
paths:
7-
- 'backend/**'
7+
- 'backend/api-gateway/**'
88
- 'scripts/images/gateway/**'
99
- '.github/workflows/docker-image-gateway.yml'
1010
- '.github/workflows/docker-images-reusable.yml'
1111
pull_request:
1212
branches: [ "main" ]
1313
paths:
14-
- 'backend/**'
14+
- 'backend/api-gateway/**'
1515
- 'scripts/images/gateway/**'
1616
- '.github/workflows/docker-image-gateway.yml'
1717
- '.github/workflows/docker-images-reusable.yml'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Label Studio Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'scripts/images/label-studio/**'
8+
- '.github/workflows/docker-image-label-studio.yml'
9+
- '.github/workflows/docker-images-reusable.yml'
10+
pull_request:
11+
branches: [ "main" ]
12+
paths:
13+
- 'scripts/images/label-studio/**'
14+
- '.github/workflows/docker-image-label-studio.yml'
15+
- '.github/workflows/docker-images-reusable.yml'
16+
workflow_dispatch:
17+
workflow_call:
18+
19+
jobs:
20+
call-docker-build:
21+
name: Build and Push Label Studio Docker Image
22+
uses: ./.github/workflows/docker-images-reusable.yml
23+
permissions:
24+
contents: read
25+
packages: write
26+
with:
27+
service_name: label-studio
28+
build_dir: .

.github/workflows/enterprise-package.yml

Lines changed: 0 additions & 110 deletions
This file was deleted.

.github/workflows/package.yml

Lines changed: 0 additions & 78 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ endef
155155
# ========== Build Targets ==========
156156

157157
# Valid build targets
158-
VALID_BUILD_TARGETS := backend database frontend runtime backend-python deer-flow mineru mineru-npu gateway
158+
VALID_BUILD_TARGETS := backend database frontend runtime backend-python deer-flow mineru mineru-npu gateway label-studio
159159

160160
# Generic docker build target with service name as parameter
161161
# Automatically prefixes image names with "datamate-" unless it's deer-flow
@@ -231,7 +231,6 @@ else
231231
fi
232232
@$(MAKE) label-studio-$(INSTALLER)-uninstall DELETE_VOLUMES_CHOICE=$$DELETE_VOLUMES_CHOICE; \
233233
$(MAKE) milvus-$(INSTALLER)-uninstall DELETE_VOLUMES_CHOICE=$$DELETE_VOLUMES_CHOICE; \
234-
$(MAKE) datamate-$(INSTALLER)-uninstall DELETE_VOLUMES_CHOICE=$$DELETE_VOLUMES_CHOICE; \
235234
$(MAKE) deer-flow-$(INSTALLER)-uninstall DELETE_VOLUMES_CHOICE=$$DELETE_VOLUMES_CHOICE; \
236235
$(MAKE) datamate-$(INSTALLER)-uninstall DELETE_VOLUMES_CHOICE=$$DELETE_VOLUMES_CHOICE
237236
endif

scripts/images/label-studio/Dockerfile

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
# syntax=docker/dockerfile:1
21
ARG NODE_VERSION=22
32
ARG PYTHON_VERSION=3.13
43
ARG POETRY_VERSION=2.1.4
54
ARG VERSION_OVERRIDE
65
ARG BRANCH_OVERRIDE
76

7+
ARG GIT_REPO=https://github.com/ModelEngine-Group/Label-Studio.git
8+
ARG GIT_BRANCH=ls-release/1.21.0.wsi
9+
10+
################################ Stage: downloader (Source Code)
11+
FROM alpine/git AS downloader
12+
ARG GIT_REPO
13+
ARG GIT_BRANCH
14+
WORKDIR /label-studio
15+
16+
RUN git clone --branch ${GIT_BRANCH} ${GIT_REPO} .
17+
818
################################ Overview
919

1020
# This Dockerfile builds a Label Studio environment.
@@ -31,24 +41,32 @@ WORKDIR /label-studio/web
3141
RUN yarn config set registry https://registry.npmjs.org/
3242
RUN yarn config set network-timeout 1200000 # HTTP timeout used when downloading packages, set to 20 minutes
3343

34-
COPY web/package.json .
35-
COPY web/yarn.lock .
36-
COPY web/tools tools
44+
# [修改] 从 downloader 阶段复制 package.json 和 lock 文件
45+
COPY --from=downloader /label-studio/web/package.json .
46+
COPY --from=downloader /label-studio/web/yarn.lock .
47+
COPY --from=downloader /label-studio/web/tools tools
48+
3749
RUN --mount=type=cache,target=/root/web/.yarn,id=yarn-cache,sharing=locked \
3850
--mount=type=cache,target=/root/web/.nx,id=nx-cache,sharing=locked \
3951
yarn install --prefer-offline --no-progress --pure-lockfile --frozen-lockfile --ignore-engines --non-interactive --production=false
4052

41-
COPY web/ .
42-
COPY pyproject.toml ../pyproject.toml
53+
# [修改] 从 downloader 阶段复制前端源码
54+
COPY --from=downloader /label-studio/web/ .
55+
# [修改] 从 downloader 阶段复制 pyproject.toml
56+
COPY --from=downloader /label-studio/pyproject.toml ../pyproject.toml
57+
4358
RUN --mount=type=cache,target=/root/web/.yarn,id=yarn-cache,sharing=locked \
4459
--mount=type=cache,target=/root/web/.nx,id=nx-cache,sharing=locked \
4560
yarn run build
4661

4762
################################ Stage: frontend-version-generator
4863
FROM frontend-builder AS frontend-version-generator
64+
# [修改] 之前是 bind mount 本地 .git,现在需要将 downloader 的 .git 目录复制进来
65+
# 注意:WORKDIR 目前是 /label-studio/web,所以我们将 git 放在上级目录以匹配原逻辑
66+
COPY --from=downloader /label-studio/.git ../.git
67+
4968
RUN --mount=type=cache,target=/root/web/.yarn,id=yarn-cache,sharing=locked \
5069
--mount=type=cache,target=/root/web/.nx,id=nx-cache,sharing=locked \
51-
--mount=type=bind,source=.git,target=../.git \
5270
yarn version:libs
5371

5472
################################ Stage: venv-builder (prepare the virtualenv)
@@ -80,14 +98,12 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
8098

8199
WORKDIR /label-studio
82100

83-
84101
ENV VENV_PATH="/label-studio/.venv"
85102
ENV PATH="$VENV_PATH/bin:$PATH"
86103

87104
## Starting from this line all packages will be installed in $VENV_PATH
88105

89-
# Copy dependency files
90-
COPY pyproject.toml poetry.lock README.md ./
106+
COPY --from=downloader /label-studio/pyproject.toml /label-studio/poetry.lock /label-studio/README.md ./
91107

92108
# Set a default build argument for including dev dependencies
93109
ARG INCLUDE_DEV=false
@@ -102,9 +118,8 @@ RUN --mount=type=cache,target=/.poetry-cache,id=poetry-cache,sharing=locked \
102118
fi
103119

104120
# Install LS
105-
COPY label_studio label_studio
121+
COPY --from=downloader /label-studio/label_studio label_studio
106122
RUN --mount=type=cache,target=/.poetry-cache,id=poetry-cache,sharing=locked \
107-
# `--extras uwsgi` is mandatory here due to poetry bug: https://github.com/python-poetry/poetry/issues/7302
108123
poetry install --only-root --extras uwsgi && \
109124
python3 label_studio/manage.py collectstatic --no-input
110125

@@ -113,9 +128,10 @@ FROM venv-builder AS py-version-generator
113128
ARG VERSION_OVERRIDE
114129
ARG BRANCH_OVERRIDE
115130

131+
COPY --from=downloader /label-studio/.git ./.git
132+
116133
# Create version_.py and ls-version_.py
117-
RUN --mount=type=bind,source=.git,target=./.git \
118-
VERSION_OVERRIDE=${VERSION_OVERRIDE} BRANCH_OVERRIDE=${BRANCH_OVERRIDE} poetry run python label_studio/core/version.py
134+
RUN VERSION_OVERRIDE=${VERSION_OVERRIDE} BRANCH_OVERRIDE=${BRANCH_OVERRIDE} poetry run python label_studio/core/version.py
119135

120136
################################### Stage: prod
121137
FROM python:${PYTHON_VERSION}-slim-trixie AS production
@@ -146,15 +162,15 @@ RUN set -eux; \
146162
mkdir -p $LS_DIR $LABEL_STUDIO_BASE_DATA_DIR $OPT_DIR && \
147163
chown -R 1001:0 $LS_DIR $LABEL_STUDIO_BASE_DATA_DIR $OPT_DIR /var/log/nginx /etc/nginx
148164

149-
COPY --chown=1001:0 deploy/default.conf /etc/nginx/nginx.conf
165+
COPY --chown=1001:0 --from=downloader /label-studio/deploy/default.conf /etc/nginx/nginx.conf
150166

151167
# Copy essential files for installing Label Studio and its dependencies
152-
COPY --chown=1001:0 pyproject.toml .
153-
COPY --chown=1001:0 poetry.lock .
154-
COPY --chown=1001:0 README.md .
155-
COPY --chown=1001:0 LICENSE LICENSE
156-
COPY --chown=1001:0 licenses licenses
157-
COPY --chown=1001:0 deploy deploy
168+
COPY --chown=1001:0 --from=downloader /label-studio/pyproject.toml .
169+
COPY --chown=1001:0 --from=downloader /label-studio/poetry.lock .
170+
COPY --chown=1001:0 --from=downloader /label-studio/README.md .
171+
COPY --chown=1001:0 --from=downloader /label-studio/LICENSE LICENSE
172+
COPY --chown=1001:0 --from=downloader /label-studio/licenses licenses
173+
COPY --chown=1001:0 --from=downloader /label-studio/deploy deploy
158174

159175
# Copy files from build stages
160176
COPY --chown=1001:0 --from=venv-builder $LS_DIR $LS_DIR

0 commit comments

Comments
 (0)