Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions .github/workflows/docker-image-gateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Gateway Docker Image CI

on:
push:
branches: [ "main" ]
paths:
- 'backend/**'
- 'scripts/images/gateway/**'
- '.github/workflows/docker-image-gateway.yml'
- '.github/workflows/docker-images-reusable.yml'
pull_request:
branches: [ "main" ]
paths:
- 'backend/**'
- 'scripts/images/gateway/**'
- '.github/workflows/docker-image-gateway.yml'
- '.github/workflows/docker-images-reusable.yml'
workflow_dispatch:
workflow_call:

jobs:
call-docker-build:
name: Build and Push Gateway Docker Image
uses: ./.github/workflows/docker-images-reusable.yml
permissions:
contents: read
packages: write
with:
service_name: gateway
build_dir: .
7 changes: 7 additions & 0 deletions .github/workflows/docker-images-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ jobs:
service_name: frontend
build_dir: .

gateway:
name: Gateway Image
uses: ./.github/workflows/docker-images-reusable.yml
with:
service_name: gateway
build_dir: .

backend:
name: Backend Image
uses: ./.github/workflows/docker-images-reusable.yml
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/docker-push-to-huaweicloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ jobs:
secrets:
HUAWEI_CLOUD_SWR_LOGIN_PWD: ${{ secrets.HUAWEI_CLOUD_SWR_LOGIN_PWD}}

gateway:
name: Push Gateway Image
uses: ./.github/workflows/docker-push-to-huaweicloud-reusable.yml
with:
service_name: datamate-gateway
version: ${{ inputs.version}}
secrets:
HUAWEI_CLOUD_SWR_LOGIN_PWD: ${{ secrets.HUAWEI_CLOUD_SWR_LOGIN_PWD}}

backend:
name: Push Backend Image
uses: ./.github/workflows/docker-push-to-huaweicloud-reusable.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/enterprise-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: |
mkdir -p images/datamate
LOWERCASE_REPO=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
services=("runtime" "backend" "frontend" "database" "backend-python")
services=("runtime" "backend" "frontend" "database" "backend-python" "gateway")
for service in "${services[@]}"; do
docker pull ghcr.io/$LOWERCASE_REPO/datamate-$service:latest --platform arm64
docker tag ghcr.io/$LOWERCASE_REPO/datamate-$service:latest datamate-$service:latest
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ jobs:
with:
service_name: backend-python

gateway-docker-build:
name: Build and Push Frontend Docker Image
uses: ./.github/workflows/docker-image-save.yml
with:
service_name: gateway

package-all:
needs:
- backend-docker-build
- frontend-docker-build
- database-docker-build
- backend-python-docker-build
- runtime-docker-build
- gateway-docker-build
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
50 changes: 33 additions & 17 deletions backend/api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,38 @@
</parent>

<artifactId>api-gateway</artifactId>
<packaging>jar</packaging>
<name>API Gateway</name>
<description>API网关服务</description>

<properties>
<spring-boot.version>3.5.6</spring-boot.version>
<spring-cloud.version>2025.0.0</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<groupId>com.terrabase</groupId>
<artifactId>enterprise-impl-commercial</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter-web</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
</dependency>
</dependencies>

Expand All @@ -49,6 +53,18 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<finalName>gateway</finalName>
<mainClass>com.datamate.gateway.ApiGatewayApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

/**
* API Gateway & Auth Service Application
* 统一的API网关和认证授权微服务
* 提供路由、鉴权、限流等功能
*/
@SpringBootApplication
@ComponentScan(basePackages = {
"com.datamate.gateway",
"com.datamate.shared"
})
public class ApiGatewayApplication {

public static void main(String[] args) {
Expand All @@ -26,51 +21,21 @@ public static void main(String[] args) {
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
// 数据归集服务路由
.route("data-collection", r -> r.path("/api/data-collection/**")
.uri("lb://data-collection-service"))

// 数据管理服务路由
.route("data-management", r -> r.path("/api/data-management/**")
.uri("lb://data-management-service"))

// 算子市场服务路由
.route("operator-market", r -> r.path("/api/operators/**")
.uri("lb://operator-market-service"))

// 数据清洗服务路由
.route("data-cleaning", r -> r.path("/api/cleaning/**")
.uri("lb://data-cleaning-service"))

// 数据合成服务路由
.route("data-synthesis", r -> r.path("/api/synthesis/**")
.uri("lb://data-synthesis-service"))
.uri("http://datamate-backend-python:18000"))

// 数据标注服务路由
.route("data-annotation", r -> r.path("/api/annotation/**")
.uri("lb://data-annotation-service"))
.uri("http://datamate-backend-python:18000"))

// 数据评估服务路由
.route("data-evaluation", r -> r.path("/api/evaluation/**")
.uri("lb://data-evaluation-service"))

// 流程编排服务路由
.route("pipeline-orchestration", r -> r.path("/api/pipelines/**")
.uri("lb://pipeline-orchestration-service"))

// 执行引擎服务路由
.route("execution-engine", r -> r.path("/api/execution/**")
.uri("lb://execution-engine-service"))

// 认证服务路由
.route("auth-service", r -> r.path("/api/auth/**")
.uri("lb://auth-service"))
.uri("http://datamate-backend-python:18000"))

// RAG服务路由
.route("rag-indexer", r -> r.path("/api/rag/indexer/**")
.uri("lb://rag-indexer-service"))
.route("rag-query", r -> r.path("/api/rag/query/**")
.uri("lb://rag-query-service"))
// 其他后端服务
.route("default", r -> r.path("/api/**")
.uri("http://datamate-backend:8080"))

.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.datamate.gateway.filter;

import com.terrabase.enterprise.api.dto.LoginUserDto;
import com.terrabase.enterprise.api.sdk.TerrabaseSDK;
import com.terrabase.enterprise.api.sdk.TerrabaseSDKConfig;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
* 用户信息过滤器
*
* @since 2025/12/22
*/
@Slf4j
@Component
public class UserContextFilter implements GlobalFilter {
@Value("${terrabase.jar.path:/opt/terrabase}")
private String jarPath;

@Value("${commercial.switch:false}")
private boolean isCommercial;

private TerrabaseSDK terrabaseSDK;

@PostConstruct
public void init() {
TerrabaseSDKConfig sdkConfig = TerrabaseSDKConfig.createDefault();
sdkConfig.setJarPath(jarPath);
terrabaseSDK = TerrabaseSDK.init(sdkConfig);
}

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
if (!isCommercial) {
return chain.filter(exchange);
}
try {
LoginUserDto loginUserDto = terrabaseSDK.userManagement().getCurrentUserInfo().getData().getFirst();
} catch (Exception e) {
log.error("get current user info error", e);
return chain.filter(exchange);
}
return chain.filter(exchange);
}
}
Loading