Skip to content

Commit 590326a

Browse files
Merge pull request #6 from Preponderous-Software/fix/no-more-runtime-gradle
fix: optimize Docker setup with multi-stage build and streamline conf…
2 parents 5669cdf + b13d9b7 commit 590326a

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

Dockerfile

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM eclipse-temurin:21-jdk
1+
2+
# Build stage
3+
FROM eclipse-temurin:21-jdk AS build
24

35
WORKDIR /app
46

@@ -14,18 +16,27 @@ COPY settings.gradle .
1416
# Make the gradlew script executable
1517
RUN chmod +x ./gradlew
1618

17-
# Configure Gradle to use the daemon
18-
ENV GRADLE_OPTS="-Dorg.gradle.daemon=true -Dorg.gradle.configureondemand=true -Dorg.gradle.parallel=true"
19+
# Copy the source code
20+
COPY src src
21+
22+
# Build the application
23+
RUN ./gradlew build --no-daemon -x test
24+
25+
# Runtime stage
26+
FROM eclipse-temurin:21-jre
27+
28+
WORKDIR /app
1929

20-
# Environment variables for Spring Boot DevTools
21-
ENV SPRING_DEVTOOLS_RESTART_ENABLED=true
22-
ENV SPRING_DEVTOOLS_LIVERELOAD_ENABLED=true
30+
# Copy the built application from the build stage
31+
COPY --from=build /app/build/libs/*.jar app.jar
2332

24-
# Disable Docker Compose support in Spring Boot
33+
# Environment variables for Spring Boot
34+
ENV SPRING_DEVTOOLS_RESTART_ENABLED=false
35+
ENV SPRING_DEVTOOLS_LIVERELOAD_ENABLED=false
2536
ENV SPRING_DOCKER_COMPOSE_ENABLED=false
2637

2738
# Expose the port the app runs on
2839
EXPOSE 8080
2940

30-
# Command to run the application with development options
31-
CMD ["./gradlew", "bootRun", "--no-daemon", "-Dspring-boot.run.jvmArguments='-Dspring.devtools.restart.enabled=true -Dspring.devtools.livereload.enabled=true'"]
41+
# Command to run the application
42+
CMD ["java", "-jar", "app.jar"]

compose.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,8 @@ services:
99
ports:
1010
- "8080:8080"
1111
environment:
12-
- SPRING_PROFILES_ACTIVE=dev
13-
- GRADLE_OPTS="-Dorg.gradle.daemon=true -Dorg.gradle.configureondemand=true"
14-
volumes:
15-
# Share Gradle cache between builds
16-
- gradle-cache:/home/app/.gradle
17-
# Share source code for hot reloading
18-
- ./:/app
19-
# Share Gradle daemon process
20-
- ~/.gradle/daemon:/home/app/.gradle/daemon
21-
# Development-specific volume for Spring DevTools
22-
- ./build/classes:/app/build/classes
12+
- SPRING_PROFILES_ACTIVE=prod
13+
restart: unless-stopped
2314

2415
volumes:
2516
gradle-cache:

0 commit comments

Comments
 (0)