72 lines
2.1 KiB
Docker
72 lines
2.1 KiB
Docker
# ============================================================
|
|
# EEG Portal - Multi-stage Docker Build
|
|
# Stage 1: Frontend (Node) -> Stage 2: Backend (Maven) -> Stage 3: Runtime (JRE)
|
|
# ============================================================
|
|
|
|
# ---- Stage 1: Build Angular Frontend ----
|
|
FROM node:24-slim AS frontend-build
|
|
|
|
WORKDIR /app/eeg_frontend
|
|
|
|
COPY eeg_frontend/package.json eeg_frontend/package-lock.json* ./
|
|
RUN npm ci --prefer-offline
|
|
|
|
COPY eeg_frontend/openapi.yaml ./
|
|
RUN npx openapi-generator-cli generate -i ./openapi.yaml -g typescript-angular -o ./src/app/api
|
|
|
|
COPY eeg_frontend/ ./
|
|
RUN npm run build -- --configuration production
|
|
|
|
# ---- Stage 2: Build Spring Boot Backend ----
|
|
FROM maven:3.9-eclipse-temurin-21 AS backend-build
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy parent POM and module POMs first (dependency caching)
|
|
COPY pom.xml ./
|
|
COPY eeg_backend/pom.xml eeg_backend/
|
|
COPY eeg_frontend/pom.xml eeg_frontend/
|
|
|
|
# Download dependencies (cached unless POMs change)
|
|
RUN mvn dependency:go-offline -pl eeg_backend -am -B
|
|
|
|
# Copy source code
|
|
COPY eeg_backend/src eeg_backend/src
|
|
|
|
# Copy Angular build output into Spring Boot static resources
|
|
COPY --from=frontend-build /app/eeg_frontend/dist/eeg_frontend/browser/ eeg_backend/src/main/resources/static/
|
|
|
|
# Build the backend JAR (skip tests in Docker)
|
|
RUN mvn package -pl eeg_backend -am -DskipTests -B
|
|
|
|
# ---- Stage 3: Runtime ----
|
|
FROM eclipse-temurin:21-jre-jammy
|
|
|
|
WORKDIR /app
|
|
|
|
# Install curl for health check
|
|
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create non-root user
|
|
RUN groupadd -r eeg && useradd -r -g eeg -d /app -s /sbin/nologin eeg
|
|
|
|
# Copy the built JAR
|
|
COPY --from=backend-build /app/eeg_backend/target/*.jar app.jar
|
|
|
|
# Set ownership
|
|
RUN chown -R eeg:eeg /app
|
|
|
|
USER eeg
|
|
|
|
EXPOSE 8080
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
|
|
CMD curl -f http://localhost:8080/actuator/health || exit 1
|
|
|
|
ENTRYPOINT ["java", \
|
|
"-XX:+UseContainerSupport", \
|
|
"-XX:MaxRAMPercentage=75.0", \
|
|
"-Djava.security.egd=file:/dev/./urandom", \
|
|
"-jar", "app.jar", \
|
|
"--spring.profiles.active=prod"]
|