ARG BUILDER_IMAGE=registry.altlinux.org/basealt/altsp:c10f1
ARG RUNTIME_IMAGE=repo.micord.ru/alt/alt-tomcat:c10f1-9.0.59-20240903

FROM $BUILDER_IMAGE AS builder

ARG MVN_FLAGS="-Pprod"

RUN apt-get update \
 && apt-get -y install git glibc-locales java-17-openjdk-devel maven node \
 && apt-get clean

ENV JAVA_HOME=/usr/lib/jvm/java
ENV LANG=ru_RU.UTF-8
ENV LANGUAGE=ru_RU.UTF-8
ENV LC_ALL=ru_RU.UTF-8

WORKDIR /app
COPY . .
RUN mkdir -p $HOME/.m2 \
# && cp -f config/pgs-settings.xml $HOME/.m2/settings.xml \
# && cp -f config/pgs-npmrc frontend/.npmrc \
 && mvn clean \
 && mvn package -T4C ${MVN_FLAGS}


FROM $RUNTIME_IMAGE
ARG ADMIN_PASSWORD=Secr3t

USER root

COPY config/tomcat /

RUN cat /etc/tomcat/webbpm.properties >> /etc/tomcat/catalina.properties \
 && sed -i -r "s/<must-be-changed>/$ADMIN_PASSWORD/g" /etc/tomcat/tomcat-users.xml \
 && chown root:tomcat /var/lib/tomcat/webapps \
 && chmod g+rw /var/lib/tomcat/webapps

USER tomcat

COPY --from=builder /app/backend/target/business-metrics*.war /var/lib/tomcat/webapps/business-metrics.war
