FROM node:12.16-alpine as builder
# FROM node:12.16-alpine

# Update everything and install needed dependencies
RUN apk add --update graphicsmagick tzdata git tini su-exec

USER root

# Install all needed dependencies
RUN apk --update add --virtual build-dependencies python build-base ca-certificates && \
	npm_config_user=root npm install -g full-icu lerna

ENV NODE_ICU_DATA /usr/local/lib/node_modules/full-icu

WORKDIR /data

COPY lerna.json .
COPY package.json .
COPY packages/cli/ ./packages/cli/
COPY packages/core/ ./packages/core/
COPY packages/editor-ui/ ./packages/editor-ui/
COPY packages/nodes-base/ ./packages/nodes-base/
COPY packages/workflow/ ./packages/workflow/
RUN rm -rf node_modules packages/*/node_modules packages/*/dist

RUN npm install --loglevel notice
RUN lerna bootstrap --hoist
RUN npm run build


FROM node:12.16-alpine

WORKDIR /data

# Install all needed dependencies
RUN npm_config_user=root npm install -g full-icu

USER root

ENV NODE_ICU_DATA /usr/local/lib/node_modules/full-icu

COPY --from=builder /data ./

RUN apk add --update graphicsmagick tzdata git tini su-exec

COPY docker/images/n8n-dev/docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["tini", "--", "/docker-entrypoint.sh"]

EXPOSE 5678/tcp