FROM node:8.17.0-buster

WORKDIR /app

ARG GIT_TOKEN

RUN rm /etc/apt/sources.list
RUN echo "deb http://archive.debian.org/debian buster main" > /etc/apt/sources.list
RUN echo "deb http://archive.debian.org/debian-security buster/updates main" >> /etc/apt/sources.list
RUN echo "deb http://archive.debian.org/debian buster-updates main" >> /etc/apt/sources.list

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
    libpng-dev \
    libimagequant-dev \
    && rm -rf /var/lib/apt/lists/*

COPY pp-frontend/package.json pp-frontend/yarn.lock ./pp-frontend/
RUN sed -i "s|git+ssh://git@github.com/theorchard/js-util-poeditor.git|git+https://${GIT_TOKEN}@github.com/theorchard/js-util-poeditor.git|g" pp-frontend/package.json && \
    sed -i "s|git+ssh://git@github.com/theorchard/frontend-react-components.git#v1.4.47|git+https://${GIT_TOKEN}@github.com/theorchard/frontend-react-components.git#v1.4.47|g" pp-frontend/package.json

WORKDIR /app/pp-frontend
RUN yarn install --ignore-engines

WORKDIR /app
COPY package.json package-lock.json* ./
RUN sed -i 's|git://|git+https://|g' package.json && npm install

COPY .eslintrc.js .stylelintrc .editorconfig ./
COPY gulpfile.js ./
COPY gulp-config/ ./gulp-config/
COPY src/ ./src/
COPY pp-frontend/ ./pp-frontend/

WORKDIR /app/pp-frontend
RUN yarn deploy

WORKDIR /app
RUN npm run gulp build

RUN ls -la /app /app/pp-frontend /app/common/production/redesign
