FROM alpine:3.22 AS svelte_build
RUN apk add npm
RUN adduser -Dh /home/svelte svelte
ADD frontend /home/svelte/Umbrella/frontend
RUN chown -R svelte /home/svelte/Umbrella
USER svelte
WORKDIR /home/svelte/Umbrella/frontend
RUN npm install && npm run build


FROM alpine:3.22 AS java_build
RUN apk add gradle
ADD . /Umbrella
WORKDIR /Umbrella
COPY --from=svelte_build /home/svelte/Umbrella/frontend/dist web/src/main/resources/web
RUN gradle --no-daemon build


FROM alpine
RUN apk --no-cache add bash fontconfig font-opensans graphviz openjdk21-jre tzdata weasyprint \
 && adduser -D umbrella
WORKDIR /home/umbrella

EXPOSE 80
CMD java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:9999 -jar jar/backend.jar

ADD https://github.com/plantuml/plantuml/releases/download/v1.2025.10/plantuml-1.2025.10.jar /home/umbrella/plantuml.jar
COPY --from=java_build /Umbrella/backend/build/libs/backend.jar /home/umbrella/jar/
RUN mkdir .config \
 && ln -s /host/config.json .config/Umbrella.json \
 && chmod a+rx plantuml.jar \
 && chown -R umbrella . \
 && ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
USER umbrella
