FROM maven:3.9-eclipse-temurin-21 AS build

WORKDIR /src

# Copy pom first so Docker can cache dependencies.
COPY pom.xml .

RUN --mount=type=cache,target=/root/.m2 \
    mvn -B -DskipTests dependency:go-offline

COPY src ./src

RUN --mount=type=cache,target=/root/.m2 \
    mvn -B -DskipTests package


FROM eclipse-temurin:21-jre

WORKDIR /app

RUN useradd -r -u 10001 closure

COPY --from=build /src/target/closure-compilerd-0.1.0.jar /app/closure-compilerd.jar

# Optional: put your JS source tree/configs here if you want the container
# to compile files from inside the image.
COPY example ./example

USER closure

ENV CLOSURED_ROOT=/work
ENV CLOSURED_PORT=8080
ENV CLOSURED_WORKERS=2

EXPOSE 8080

ENTRYPOINT ["java", "-Xms256m", "-Xmx2g", "-jar", "/app/closure-compilerd.jar"]
