FROM maven:latest AS builder

COPY . /src
WORKDIR /src

RUN mvn clean install

FROM tomcat:8.5
ARG PROJECT_NAME=centralino_brigate
ARG PROJECT_VERS=0.1.0

RUN cd /usr/local/tomcat/webapps.dist/ \
 && for FILE in *; do \
        echo "Symlinking: $FILE -> /usr/local/tomcat/webapps/$FILE"; \
        ln -s $PWD/$FILE /usr/local/tomcat/webapps/$FILE; \
    done
COPY docker/tomcat-users.xml /usr/local/tomcat/conf/
COPY docker/host-manager/context.xml /usr/local/tomcat/webapps.dist/host-manager/META-INF/context.xml
COPY docker/manager/context.xml /usr/local/tomcat/webapps.dist/manager/META-INF/context.xml
COPY --from=builder /src/target/${PROJECT_NAME}-${PROJECT_VERS}.war /usr/local/tomcat/webapps/