Skip to content

Commit f78475e

Browse files
authored
Develop hsc (#58)
feature: 优化镜像构建/部署
1 parent d84152b commit f78475e

File tree

27 files changed

+540
-304
lines changed

27 files changed

+540
-304
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Python Backend Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'backend/**'
8+
- 'scripts/images/datamate-python/**'
9+
- '.github/workflows/docker-image-backend-python.yml'
10+
pull_request:
11+
branches: [ "main" ]
12+
paths:
13+
- 'backend/**'
14+
- 'scripts/images/datamate-python/**'
15+
- '.github/workflows/docker-image-backend-python.yml'
16+
workflow_dispatch:
17+
18+
jobs:
19+
call-docker-build:
20+
name: Build and Push Backend Python Docker Image
21+
uses: ./.github/workflows/docker-images-reusable.yml
22+
permissions:
23+
contents: read
24+
packages: write
25+
with:
26+
service_name: backend-python
27+
build_dir: .

Makefile

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ MAKEFLAGS += --no-print-directory
33
WITH_MINERU ?= false # 默认不构建mineru
44
VERSION ?= latest
55
NAMESPACE ?= datamate
6+
REGISTRY ?= "ghcr.io/modelengine-group/"
67

78
ifdef COMSPEC
89
# Windows 环境
@@ -17,7 +18,7 @@ build-%:
1718
$(MAKE) $*-docker-build
1819

1920
.PHONY: build
20-
build: backend-docker-build frontend-docker-build runtime-docker-build $(if $(WITH_MINERU),mineru-docker-build)
21+
build: backend-docker-build frontend-docker-build runtime-docker-build
2122

2223
.PHONY: create-namespace
2324
create-namespace:
@@ -42,7 +43,24 @@ else
4243
endif
4344

4445
.PHONY: install
45-
install: install-datamate
46+
install:
47+
ifeq ($(origin INSTALLER), undefined)
48+
@echo "Choose a deployment method:"
49+
@echo "1. Docker/Docker-Compose"
50+
@echo "2. Kubernetes/Helm"
51+
@echo -n "Enter choice: "
52+
@read choice; \
53+
case $$choice in \
54+
1) INSTALLER=docker ;; \
55+
2) INSTALLER=k8s ;; \
56+
*) echo "Invalid choice" && exit 1 ;; \
57+
esac; \
58+
$(MAKE) datamate-$$INSTALLER-install; \
59+
$(MAKE) milvus-$$INSTALLER-install
60+
else
61+
$(MAKE) datamate-$(INSTALLER)-install; \
62+
$(MAKE) milvus-$(INSTALLER)-install
63+
endif
4664

4765
.PHONY: uninstall-%
4866
uninstall-%:
@@ -63,7 +81,24 @@ else
6381
endif
6482

6583
.PHONY: uninstall
66-
uninstall: uninstall-datamate
84+
uninstall:
85+
ifeq ($(origin INSTALLER), undefined)
86+
@echo "Choose a deployment method:"
87+
@echo "1. Docker/Docker-Compose"
88+
@echo "2. Kubernetes/Helm"
89+
@echo -n "Enter choice: "
90+
@read choice; \
91+
case $$choice in \
92+
1) INSTALLER=docker ;; \
93+
2) INSTALLER=k8s ;; \
94+
*) echo "Invalid choice" && exit 1 ;; \
95+
esac; \
96+
$(MAKE) milvus-$$INSTALLER-uninstall; \
97+
$(MAKE) datamate-$$INSTALLER-uninstall
98+
else
99+
$(MAKE) milvus-$(INSTALLER)-uninstall; \
100+
$(MAKE) datamate-$(INSTALLER)-uninstall
101+
endif
67102

68103
# build
69104
.PHONY: backend-docker-build
@@ -92,6 +127,11 @@ deer-flow-docker-build:
92127
.PHONY: mineru-docker-build
93128
mineru-docker-build:
94129
docker build -t datamate-mineru:$(VERSION) . -f scripts/images/mineru/Dockerfile
130+
131+
.PHONY: backend-python-docker-build
132+
backend-python-docker-build:
133+
docker build -t datamate-backend-python:$(VERSION) . -f scripts/images/datamate-python/Dockerfile
134+
95135
.PHONY: backend-docker-install
96136
backend-docker-install:
97137
cd deployment/docker/datamate && docker compose up -d backend
@@ -118,7 +158,7 @@ runtime-docker-uninstall:
118158

119159
.PHONY: mineru-docker-install
120160
mineru-docker-install:
121-
cd deployment/docker/datamate && cp .env.example .env && docker compose up -d datamate-mineru
161+
cd deployment/docker/datamate && export REGISTRY=$(REGISTRY) && docker compose up -d datamate-mineru
122162

123163
.PHONY: mineru-docker-uninstall
124164
mineru-docker-uninstall:
@@ -134,31 +174,40 @@ mineru-k8s-uninstall:
134174

135175
.PHONY: datamate-docker-install
136176
datamate-docker-install:
137-
cd deployment/docker/datamate && cp .env.example .env && docker compose -f docker-compose.yml up -d
177+
cd deployment/docker/datamate && export REGISTRY=$(REGISTRY) && docker compose -f docker-compose.yml up -d
138178

139179
.PHONY: datamate-docker-uninstall
140180
datamate-docker-uninstall:
141-
cd deployment/docker/datamate && docker compose -f docker-compose.yml down -v
181+
cd deployment/docker/datamate && docker compose -f docker-compose.yml --profile mineru down -v
142182

143183
.PHONY: deer-flow-docker-install
144184
deer-flow-docker-install:
145-
cd deployment/docker/datamate && cp .env.deer-flow.example .env && docker compose -f docker-compose.yml up -d
185+
cd deployment/docker/datamate && export NGINX_CONF="./backend-with-deer-flow.conf" && export REGISTRY=$(REGISTRY) && docker compose -f docker-compose.yml up -d
146186
cp -n runtime/deer-flow/.env.example runtime/deer-flow/.env
147187
cp -n runtime/deer-flow/conf.yaml.example runtime/deer-flow/conf.yaml
148-
cp runtime/deer-flow/.env deployment/docker/deer-flow/.env && cp runtime/deer-flow/conf.yaml deployment/docker/deer-flow/conf.yaml
149-
cd deployment/docker/deer-flow && docker compose -f docker-compose.yml up -d
188+
cp runtime/deer-flow/.env deployment/docker/deer-flow/.env
189+
cp runtime/deer-flow/conf.yaml deployment/docker/deer-flow/conf.yaml
190+
cd deployment/docker/deer-flow && export REGISTRY=$(REGISTRY) && docker compose -f docker-compose.yml up -d
150191

151192
.PHONY: deer-flow-docker-uninstall
152193
deer-flow-docker-uninstall:
153194
@if docker compose ls --filter name=datamate | grep -q datamate; then \
154-
cd deployment/docker/datamate && docker compose -f docker-compose.yml up -d; \
195+
cd deployment/docker/datamate && export REGISTRY=$(REGISTRY) && docker compose -f docker-compose.yml up -d; \
155196
fi
156197
cd deployment/docker/deer-flow && docker compose -f docker-compose.yml down
157198

199+
.PHONY: milvus-docker-install
200+
milvus-docker-install:
201+
cd deployment/docker/milvus && docker compose -f docker-compose.yml up -d
202+
203+
.PHONY: milvus-docker-uninstall
204+
milvus-docker-uninstall:
205+
cd deployment/docker/milvus && docker compose -f docker-compose.yml down
206+
158207
.PHONY: datamate-k8s-install
159208
datamate-k8s-install: create-namespace
160209
kubectl create configmap datamate-init-sql --from-file=scripts/db/ --dry-run=client -o yaml | kubectl apply -f - -n $(NAMESPACE)
161-
helm upgrade datamate deployment/helm/datamate/ -n $(NAMESPACE) --install
210+
helm upgrade datamate deployment/helm/datamate/ -n $(NAMESPACE) --install --set global.image.repository=$(REPOSITORY)
162211

163212
.PHONY: datamate-k8s-uninstall
164213
datamate-k8s-uninstall:
@@ -167,14 +216,17 @@ datamate-k8s-uninstall:
167216

168217
.PHONY: deer-flow-k8s-install
169218
deer-flow-k8s-install:
170-
helm upgrade datamate deployment/helm/datamate/ -n $(NAMESPACE) --install --set global.deerFlow.enable=true
219+
helm upgrade datamate deployment/helm/datamate/ -n $(NAMESPACE) --install --set global.deerFlow.enable=true --set global.image.repository=$(REPOSITORY)
171220
cp runtime/deer-flow/.env deployment/helm/deer-flow/charts/public/.env
172221
cp runtime/deer-flow/conf.yaml deployment/helm/deer-flow/charts/public/conf.yaml
173-
helm upgrade deer-flow deployment/helm/deer-flow -n $(NAMESPACE) --install
222+
helm upgrade deer-flow deployment/helm/deer-flow -n $(NAMESPACE) --install --set global.image.repository=$(REPOSITORY)
174223

175224
.PHONY: deer-flow-k8s-uninstall
176225
deer-flow-k8s-uninstall:
177226
helm uninstall deer-flow -n $(NAMESPACE) --ignore-not-found
227+
@if helm ls -n $(NAMESPACE) --filter datamate | grep -q datamate; then \
228+
helm upgrade datamate deployment/helm/datamate/ -n $(NAMESPACE) --set global.deerFlow.enable=false; \
229+
fi
178230

179231
.PHONY: milvus-k8s-install
180232
milvus-k8s-install:

deployment/docker/datamate/.env.deer-flow.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

deployment/docker/datamate/.env.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

deployment/docker/datamate/backend-with-deer-flow.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ server {
99

1010
add_header Set-Cookie "NEXT_LOCALE=zh";
1111

12+
location /api/synthesis/ {
13+
proxy_pass http://datamate-backend-python:18000/api/synthesis/;
14+
proxy_set_header Host $host;
15+
proxy_set_header X-Real-IP $remote_addr;
16+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
17+
}
18+
19+
location /api/annotation/ {
20+
proxy_pass http://datamate-backend-python:18000/api/annotation/;
21+
proxy_set_header Host $host;
22+
proxy_set_header X-Real-IP $remote_addr;
23+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
24+
}
25+
1226
location /api/ {
1327
proxy_pass http://datamate-backend:8080/api/;
1428
proxy_set_header Host $host;

deployment/docker/datamate/docker-compose.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
# 1) backend
33
datamate-backend:
44
container_name: datamate-backend
5-
image: datamate-backend
5+
image: ${REGISTRY:-}datamate-backend
66
restart: on-failure
77
privileged: true
88
volumes:
@@ -18,7 +18,7 @@ services:
1818
# 1) backend (Python)
1919
datamate-backend-python:
2020
container_name: datamate-backend-python
21-
image: datamate-backend-python
21+
image: ${REGISTRY:-}datamate-backend-python
2222
restart: on-failure
2323
privileged: true
2424
environment:
@@ -34,13 +34,13 @@ services:
3434
# 2) frontend(NodePort 30000)
3535
datamate-frontend:
3636
container_name: datamate-frontend
37-
image: datamate-frontend
37+
image: ${REGISTRY:-}datamate-frontend
3838
restart: on-failure
3939
ports:
4040
- "30000:80" # nodePort → hostPort
4141
volumes:
4242
- frontend_log_volume:/var/log/datamate/frontend
43-
- $NGINX_CONF:/etc/nginx/conf.d/backend.conf
43+
- ${NGINX_CONF:-./backend.conf}:/etc/nginx/conf.d/backend.conf
4444
networks: [ datamate ]
4545
depends_on:
4646
- datamate-backend
@@ -71,7 +71,7 @@ services:
7171
# 3) runtime
7272
datamate-runtime:
7373
container_name: datamate-runtime
74-
image: datamate-runtime
74+
image: ${REGISTRY:-}datamate-runtime
7575
restart: on-failure
7676
environment:
7777
RAY_DEDUP_LOGS: "0"
@@ -81,7 +81,6 @@ services:
8181
MYSQL_USER: "root"
8282
MYSQL_PASSWORD: "password"
8383
MYSQL_DATABASE: "datamate"
84-
PDF_FORMATTER_BASE_URL: "http://datamate-mineru:9001"
8584
command:
8685
- python
8786
- /opt/runtime/datamate/operator_runtime.py
@@ -135,6 +134,8 @@ volumes:
135134
name: datamate-operator-upload-volume
136135
operator-runtime-volume:
137136
name: datamate-operator-runtime-volume
137+
mineru_log_volume:
138+
name: datamate-mineru_log_volume
138139

139140
networks:
140141
datamate:

deployment/docker/deer-flow/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
deer-flow-backend:
3-
image: deer-flow-backend
3+
image: ${REGISTRY:-}deer-flow-backend
44
container_name: deer-flow-backend
55
env_file:
66
- .env
@@ -11,7 +11,7 @@ services:
1111
- datamate
1212

1313
deer-flow-frontend:
14-
image: deer-flow-frontend
14+
image: ${REGISTRY:-}deer-flow-frontend
1515
container_name: deer-flow-frontend
1616
env_file:
1717
- .env

deployment/docker/milvus/docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.5'
2-
31
services:
42
etcd:
53
container_name: milvus-etcd
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: v2
2+
name: backend-python
3+
description: A Helm chart for Kubernetes
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.0.1
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: "0.0.1"
25+
26+
dependencies:
27+
- name: database
28+
repository: file://../database
29+
version: 0.0.1

0 commit comments

Comments
 (0)