# Build image
FROM node:16 as builder
ARG RELEASE

# Needed as yarn repos is on https
RUN apt-get update && apt-get install -y \
    apt-transport-https

# Installing yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn

# Preparing build environment
WORKDIR /build
COPY package.json yarn.lock .postcssrc ./
RUN yarn config set registry https://npm.yandex-team.ru
RUN yarn install

# Building
RUN echo ${RELEASE} >release_id
COPY lib ./lib
COPY packages ./packages
COPY scripts ./scripts
COPY src ./src
COPY .tanker ./.tanker
COPY .babelrc ./

RUN yarn run build


# Production image
FROM ubuntu:16.04

RUN echo deb http://nginx.org/packages/ubuntu/ xenial nginx >> /etc/apt/sources.list.d/nginx.list \
 && echo deb-src http://nginx.org/packages/ubuntu/ xenial nginx >> /etc/apt/sources.list.d/nginx.list

RUN apt-get update && apt-get install -y --allow-unauthenticated \
    nginx

COPY config/nginx.conf /nginx.conf
COPY --from=builder /build/dist/index.html /build/dist/index.js /build/dist/index.css ./app/
COPY --from=builder /build/dist/*.svg ./app/

EXPOSE 80

CMD nginx -c /nginx.conf
