Docker

Build stage

FROM gradle:8.11.1-jdk21 AS builder
WORKDIR /app

Copy gradle files first for better caching

COPY build.gradle settings.gradle ./
COPY gradle gradle
COPY gradlew ./

Download dependencies (cached layer)

RUN gradle dependencies –no-daemon

Copy source and build

COPY src src
RUN gradle clean build -x test –no-daemon

Runtime stage

FROM openjdk:21-jdk-slim
WORKDIR /app

Copy jar file

COPY –from=builder /app/build/libs/*.jar app.jar

Render uses PORT environment variable

EXPOSE $PORT

Run application with dynamic port

CMD [“sh”, “-c”, “java -jar -Dserver.port=$PORT -Dspring.profiles.active=render app.jar”]

Share this article:
Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *