# Use the official maven/Java 21 image to create a build artifact.
FROM maven:3.9.6-eclipse-temurin-21 as builder

LABEL authors="Luigelo Davila <lui>, João Nuno Carvalho <>, "

# Set the working directory in the image to /app
WORKDIR /app

# Copy the pom.xml file to our app directory
COPY pom.xml .

# Download all required dependencies into one layer
RUN mvn dependency:go-offline -B

# Copy the rest of the code
COPY src /app/src

# Build the project
RUN mvn clean package

# Use Amazon Correto for base image.
FROM amazoncorretto:21 as runtime

# Set the working directory in the image to /app
WORKDIR /app

# Copy the jar to the production image from the builder stage.
COPY --from=builder /app/target/*.jar /app/

# Install required packages
RUN yum update && yum install -y \
    wget \
    unzip \
    x11-apps \
    xauth \
    xserver-xorg-video-dummy \
    libxext6 \
    libxrender1 \
    libxtst6 \
    libfreetype6 \
    fontconfig \
    x11-xserver-utils \
    && rm -rf /var/lib/apt/lists/*

# Install JavaFX
RUN wget https://download2.gluonhq.com/openjfx/21.0.2/openjfx-21.0.2_linux-x64_bin-sdk.zip -O javafx-sdk.zip && \
    unzip javafx-sdk.zip && \
    rm javafx-sdk.zip

# Set the PATH environment variable for JavaFX
ENV PATH_TO_FX=/app/javafx-sdk-21.0.2/lib
ENV PATH=$PATH_TO_FX:$PATH