From bc33194b6ebd4958ab8507bc2e4d4d1712e1eb3a Mon Sep 17 00:00:00 2001 From: wh Date: Thu, 9 Apr 2026 13:08:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(infra):=20=E6=B7=BB=E5=8A=A0=20Docker=20Co?= =?UTF-8?q?mpose=20=E9=85=8D=E7=BD=AE=E5=92=8C=E5=90=8E=E7=AB=AF=20Dockerf?= =?UTF-8?q?ile=20(T004)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 7 ++++ Dockerfile | 18 +++++++++ docker-compose.yml | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1f495ed --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.claude +specs +docs +target +*.md +.gitignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c8aa788 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..09a1dbe --- /dev/null +++ b/docker-compose.yml @@ -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: