# Stage 1: Build the application
FROM maven:3.9.6-eclipse-temurin-17-alpine AS builder

# Set the working directory
WORKDIR /home/container

# Copy the source code
COPY . .

# Build the jar
RUN mvn package -q -Dmaven.test.skip -DskipTests -T2C

# Stage 2: Create the final lightweight image
FROM eclipse-temurin:17.0.11_9-jre-focal

# Set the working directory
WORKDIR /home/container

# Copy the built jar file from the builder stage
COPY --from=builder /home/container/target/Bat.jar .

# Export the port
ENV PORT=8080
EXPOSE $PORT

# Run the jar file
CMD java -jar Bat.jar -Djava.awt.headless=true