feat(infra): 添加 Docker Compose 配置和后端 Dockerfile (T004)
This commit is contained in:
7
.dockerignore
Normal file
7
.dockerignore
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
.git
|
||||||
|
.claude
|
||||||
|
specs
|
||||||
|
docs
|
||||||
|
target
|
||||||
|
*.md
|
||||||
|
.gitignore
|
||||||
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Build stage: uses Maven + JDK 17 (Alpine) to compile and package the application.
|
||||||
|
FROM maven:3.9-eclipse-temurin-17-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy pom.xml first to leverage Docker layer caching for dependency downloads.
|
||||||
|
COPY pom.xml .
|
||||||
|
RUN mvn dependency:go-offline -q
|
||||||
|
|
||||||
|
# Copy source and build the fat JAR, skipping tests.
|
||||||
|
COPY src ./src
|
||||||
|
RUN mvn clean package -DskipTests -q
|
||||||
|
|
||||||
|
# Runtime stage: slim JRE-only image for a smaller production footprint.
|
||||||
|
FROM eclipse-temurin:17-jre-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /app/target/*.jar app.jar
|
||||||
|
EXPOSE 8080
|
||||||
|
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||||
99
docker-compose.yml
Normal file
99
docker-compose.yml
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: label_db
|
||||||
|
POSTGRES_USER: label
|
||||||
|
POSTGRES_PASSWORD: label_password
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U label -d label_db"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
command: redis-server --requirepass redis_password
|
||||||
|
ports:
|
||||||
|
- "6379:6379"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "-a", "redis_password", "ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
# RustFS is an S3-compatible object storage service.
|
||||||
|
# Using MinIO as a drop-in S3 API substitute for development/testing.
|
||||||
|
# Replace with the actual RustFS image in production environments.
|
||||||
|
rustfs:
|
||||||
|
image: minio/minio:latest
|
||||||
|
command: server /data --console-address ":9001"
|
||||||
|
environment:
|
||||||
|
MINIO_ROOT_USER: minioadmin
|
||||||
|
MINIO_ROOT_PASSWORD: minioadmin
|
||||||
|
ports:
|
||||||
|
- "9000:9000"
|
||||||
|
- "9001:9001"
|
||||||
|
volumes:
|
||||||
|
- rustfs_data:/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
|
backend:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
environment:
|
||||||
|
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/label_db
|
||||||
|
SPRING_DATASOURCE_USERNAME: label
|
||||||
|
SPRING_DATASOURCE_PASSWORD: label_password
|
||||||
|
SPRING_DATA_REDIS_HOST: redis
|
||||||
|
SPRING_DATA_REDIS_PORT: 6379
|
||||||
|
SPRING_DATA_REDIS_PASSWORD: redis_password
|
||||||
|
RUSTFS_ENDPOINT: http://rustfs:9000
|
||||||
|
RUSTFS_ACCESS_KEY: minioadmin
|
||||||
|
RUSTFS_SECRET_KEY: minioadmin
|
||||||
|
AI_SERVICE_BASE_URL: http://ai-service:8000
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
redis:
|
||||||
|
condition: service_healthy
|
||||||
|
rustfs:
|
||||||
|
condition: service_healthy
|
||||||
|
# NOTE: /actuator/health requires spring-boot-starter-actuator in pom.xml.
|
||||||
|
# Currently pom.xml does not include it. Either add the dependency (recommended)
|
||||||
|
# or replace this check with a simple TCP port check.
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--spider", "-q", "http://localhost:8080/actuator/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 60s
|
||||||
|
|
||||||
|
# Placeholder AI service — replace with the actual FastAPI image in production.
|
||||||
|
ai-service:
|
||||||
|
image: python:3.11-slim
|
||||||
|
command: ["python3", "-m", "http.server", "8000"]
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
|
||||||
|
# Placeholder frontend — replace with the actual Nginx + static build in production.
|
||||||
|
frontend:
|
||||||
|
image: nginx:alpine
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
rustfs_data:
|
||||||
Reference in New Issue
Block a user