Files
MaliangAINovalWriter/deploy/open/Dockerfile.build
2025-09-12 14:23:26 +08:00

48 lines
1.6 KiB
Docker

# Stage 1: Build the Flutter web client
FROM ghcr.io/cirruslabs/flutter:3.22.2 as flutter_builder
# Copy Flutter project
COPY AINoval/ /flutter_app/
WORKDIR /flutter_app
# Get dependencies and build
RUN flutter pub get
RUN flutter doctor -v
RUN flutter build web --release --web-renderer html --verbose
# Stage 2: Build the Java Spring Boot server
FROM maven:3.9-eclipse-temurin-21 as java_builder
# Copy Java project
COPY AINovalServer/ /java_app/
WORKDIR /java_app
# Build the application, skipping tests to speed up the process
RUN mvn clean package -DskipTests
# Stage 3: Create the final runtime image
FROM eclipse-temurin:21-jre
ENV TZ=Asia/Shanghai \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
SPRING_PROFILES_ACTIVE=prod \
JVM_XMS=512m \
JVM_XMX=512m
# Fix JDK 21 reflective access for BigDecimal in Spring Data Mongo
ENV JAVA_TOOL_OPTIONS="--add-opens=java.base/java.math=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED"
WORKDIR /app
# Copy the server jar from the java_builder stage and rename it
COPY --from=java_builder /java_app/target/ai-novel-server-0.0.1-SNAPSHOT.jar /app/ainoval-server.jar
# Copy the built web assets from the flutter_builder stage
COPY --from=flutter_builder /flutter_app/build/web/ /app/web/
EXPOSE 18080
# Serve the prebuilt web from filesystem via Spring static locations
CMD sh -c "java -Xms${JVM_XMS} -Xmx${JVM_XMX} -Dfile.encoding=UTF-8 -Dspring.web.resources.static-locations=file:/app/web/ -jar /app/ainoval-server.jar"