#
# Stage 1: Build image creation
#
FROM node:10.9.0-alpine

## Environement variables
ARG BUILD_VERSION_STDLIB
ENV BUILD_VERSION_STDLIB=${BUILD_VERSION_STDLIB}

ARG BUILD_ENVIRONMENT
ENV BUILD_ENVIRONMENT=${BUILD_ENVIRONMENT}

ARG BUILD_VERSION_MDOT
ENV BUILD_VERSION_MDOT=${BUILD_VERSION_MDOT}

## Update the system
RUN apk update && apk add bash

## Node-gyp needs python
RUN apk add --update \
    openssh-client \
    git \
    python \
    python-dev \
    py-pip \
    build-base \
  && pip install virtualenv \
  && rm -rf /var/cache/apk/*

## Add SSH keys for npm to be able to clone the FSL
RUN mkdir -p /root/.ssh/
COPY docker/env/dev/ssh/* /root/.ssh/
RUN chmod -R 600 /root/.ssh/*

## Configure npm
RUN npm set progress=false
RUN npm config set registry https://registry.npmjs.org/

## Add source code
COPY . /var/www/deliveryApi/frontend/

## Build the source code
RUN cd /var/www/deliveryApi/frontend && ./build.sh



#
# Runtime image creation
#
FROM node:10.9.0-alpine  

## Update the system
RUN apk update && apk add bash

## Add code compiled
COPY --from=0 /var/www/deliveryApi/frontend/deploy   /var/www/deliveryApi/frontend/deploy
COPY --from=0 /var/www/deliveryApi/frontend/testcafe /var/www/deliveryApi/frontend/testcafe

