FROM registry.yandex.net/maps/ubuntu_xenial-node_10-monitorings:11.2.1 as build

ARG STATIC_CLIENT_KEY
ARG QTOOLS_TOKEN

WORKDIR /tmp/build

COPY .npmrc package.json package-lock.json ./
RUN npm ci

COPY . .
RUN make build-production
RUN QTOOLS_TOKEN=$QTOOLS_TOKEN \
    STATIC_CLIENT_KEY=$STATIC_CLIENT_KEY \
    NODE_TLS_REJECT_UNAUTHORIZED=0 \
    make publish-static
RUN npm prune --production

FROM registry.yandex.net/maps/ubuntu_xenial-node_10-monitorings:11.2.1
WORKDIR /usr/local/app

COPY --from=build /tmp/build/out out
COPY --from=build /tmp/build/.qtools.json .
COPY --from=build /tmp/build/node_modules node_modules

COPY .configs/nginx/extension.conf /etc/nginx/include.d/extension.conf

RUN maps_init

ENV MAPS_NODEJS_APP /usr/local/app/out/app/app.js
CMD ["/start.sh"]
