# Build from the repo root: docker build -f apps/backend/Dockerfile .
FROM eclipse-temurin:25.0.4_7-jdk-noble AS build

# The Maven wrapper checks the .zip it downloads; without unzip it would fetch a .tar.gz that fails the check.
RUN apt-get update && apt-get install -y --no-install-recommends unzip && rm -rf /var/lib/apt/lists/*

WORKDIR /build

# Dependencies first, so they are cached until the pom changes
COPY apps/backend/.mvn .mvn
COPY apps/backend/mvnw apps/backend/pom.xml ./
RUN ./mvnw -B -q quarkus:go-offline

COPY apps/backend/src src
RUN ./mvnw -B -q package -DskipTests

FROM eclipse-temurin:25.0.4_7-jre-noble

ENV PORT=6000

# The app writes access.log and crashes/ to its working directory.
RUN useradd --system --create-home mancala && install -d -o mancala /home/mancala/app
WORKDIR /home/mancala/app
COPY --from=build --chown=mancala /build/target/quarkus-app/ ./
USER mancala

EXPOSE ${PORT}

CMD ["java", "-jar", "quarkus-run.jar"]
