FROM ecr.clients.internal.justin.tv/nodejs:14.15.0-1 AS prepare-monorepo
ENV YARN_VERSION 1.22.10
WORKDIR /opt/tachyon
RUN npm install --global yarn@$YARN_VERSION
COPY .prettierrc .npmrc .yarnclean babel.configurator.js jest.configurator.js lerna.json README.md CHANGELOG.md package.json tsconfig.base.json stylelint.config.js .eslintrc.js .eslintignore yarn.lock ./
COPY internal-docs/ ./internal-docs/
COPY patterns/ ./patterns/
COPY policies/ ./policies/
COPY processes/ ./processes/
COPY jest.config/ ./jest.config/
COPY native-apps/ ./native-apps/
COPY package-examples/ ./package-examples/
COPY patches/ ./patches/
COPY prototyper/ ./prototyper/
COPY schema/ ./schema/
COPY templates/ ./templates/
COPY packages/ ./packages/
COPY apps/ ./apps/
RUN yarn install --frozen-lockfile

FROM prepare-monorepo AS build-packages
RUN yarn build:packages

FROM build-packages AS build-starshot
ARG SENTRY_AUTH_TOKEN
ARG GIT_COMMIT=no_hash
ENV NODE_ENV=production DOCKER_PRODUCTION=true
RUN yarn build:sst
RUN yarn docker:prune
RUN yarn nuke:deps
RUN rm -rf .prettierrc stylelint.config.js .eslintrc.js .eslintignore apps/moonbase apps/sky-map apps/status apps/tomorrow apps/valence package-examples/ prototyper/ internal-docs/ packages/tachyon-core/relay-build/ patterns/ policies/ schema/ templates/ README.md CHANGELOG.md
RUN yarn install --frozen-lockfile --ignore-scripts --ignore-optional --production && yarn cache clean
RUN yarn patch-package

FROM ecr.clients.internal.justin.tv/nodejs-dumb-init:14.15.0-1 AS starshot-production
ENV NODE_ENV production
ENV PORT 3003
WORKDIR /opt/tachyon
COPY --from=build-starshot /opt/tachyon /opt/tachyon
EXPOSE 3003

FROM build-packages AS build-tomorrow
ARG SENTRY_AUTH_TOKEN
ARG GIT_COMMIT=no_hash
ENV NODE_ENV=production DOCKER_PRODUCTION=true
RUN yarn build:tmw
RUN yarn docker:prune
RUN yarn nuke:deps
RUN rm -rf .prettierrc stylelint.config.js .eslintrc.js .eslintignore apps/moonbase apps/sky-map apps/starshot apps/status apps/valence package-examples/ prototyper/ internal-docs/ packages/tachyon-core/relay-build/ patterns/ policies/ processes/ jest.config/ native-apps/ schema/ templates/ README.md CHANGELOG.md
RUN yarn install --frozen-lockfile --ignore-scripts --ignore-optional --production && yarn cache clean
RUN yarn patch-package

FROM ecr.clients.internal.justin.tv/nodejs-dumb-init:14.15.0-1 AS tomorrow-production
ENV NODE_ENV production
ENV PORT 3003
WORKDIR /opt/tachyon
COPY --from=build-tomorrow /opt/tachyon /opt/tachyon
EXPOSE 3003

FROM build-packages AS build-valence
ARG SENTRY_AUTH_TOKEN
ARG GIT_COMMIT=no_hash
ENV NODE_ENV=production DOCKER_PRODUCTION=true
RUN yarn build:vlc
RUN yarn docker:prune
RUN yarn nuke:deps
RUN rm -rf .prettierrc stylelint.config.js .eslintrc.js .eslintignore apps/moonbase apps/sky-map apps/status apps/tomorrow apps/starshot package-examples/ prototyper/ internal-docs/ packages/tachyon-core/relay-build/ patterns/ policies/ processes/ jest.config/ native-apps/ schema/ templates/ README.md CHANGELOG.md
RUN yarn install --frozen-lockfile --ignore-scripts --ignore-optional --production && yarn cache clean
RUN yarn patch-package

FROM ecr.clients.internal.justin.tv/nodejs-dumb-init:14.15.0-1 AS valence-production
ENV NODE_ENV production
ENV PORT 3003
WORKDIR /opt/tachyon
COPY --from=build-valence /opt/tachyon /opt/tachyon
EXPOSE 3003

FROM build-packages AS build-moonbase
ARG SENTRY_AUTH_TOKEN
ARG GIT_COMMIT=no_hash
ENV NODE_ENV=production DOCKER_PRODUCTION=true
RUN yarn build:mnb
RUN yarn docker:prune
RUN yarn nuke:deps
RUN rm -rf .prettierrc stylelint.config.js .eslintrc.js .eslintignore apps/sky-map apps/status apps/tomorrow apps/starshot apps/valence package-examples/ prototyper/ internal-docs/ packages/tachyon-core/relay-build/ patterns/ policies/ processes/ jest.config/ native-apps/ schema/ templates/ README.md CHANGELOG.md
RUN yarn install --frozen-lockfile --ignore-scripts --ignore-optional --production && yarn cache clean
RUN yarn patch-package

FROM ecr.clients.internal.justin.tv/nodejs-dumb-init:14.15.0-1 AS moonbase-production
ENV NODE_ENV production
ENV PORT 3003
WORKDIR /opt/tachyon
COPY --from=build-moonbase /opt/tachyon /opt/tachyon
EXPOSE 3003
