misc: add turbo monorepo util

Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
Co-authored-by: David Mehren <git@herrmehren.de>
Co-authored-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
Signed-off-by: David Mehren <git@herrmehren.de>
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Erik Michelson 2022-12-12 00:46:30 +01:00 committed by Tilman Vatteroth
parent e3512d3a87
commit 305b6f5910
41 changed files with 785 additions and 1218 deletions

View file

@ -14,58 +14,35 @@ FROM docker.io/node:19-alpine@sha256:72b0f918ad76b5ef68c6243869fab5800d7393c1dcc
# Add tini to handle signals
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals
RUN apk add --no-cache tini
ENTRYPOINT ["tini"]
ENTRYPOINT ["tini", "--"]
ENV YARN_CACHE_FOLDER /tmp/.yarn
USER node
WORKDIR /usr/src/app
## Stage 1: Code with all dependencies
FROM base as code-with-deps
RUN apk add --no-cache libc6-compat
USER node
WORKDIR /usr/src/app
COPY --chown=node .yarn/plugins .yarn/plugins
COPY --chown=node .yarn/patches .yarn/patches
COPY --chown=node .yarn/releases .yarn/releases
COPY --chown=node .yarnrc.yml .yarnrc.yml
COPY --chown=node package.json package.json
COPY --chown=node yarn.lock yarn.lock
COPY --chown=node backend/package.json backend/
COPY --chown=node commons/package.json commons/
COPY --chown=node frontend/package.json frontend/
COPY --chown=node . .
# Install dependencies first to not invalidate the cache on every source change
RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \
yarn install --immutable && yarn workspaces focus @hedgedoc/backend
yarn install --immutable && yarn workspaces focus hedgedoc @hedgedoc/backend @hedgedoc/commons
COPY --chown=node commons/ commons/
COPY --chown=node backend/nest-cli.json backend/tsconfig.json backend/tsconfig.build.json backend/
COPY --chown=node backend/src backend/src
WORKDIR /usr/src/app/commons
RUN yarn build
## Stage 2a: Dev config files and tests
FROM code-with-deps as development
## Stage 2a: Compile TypeScript
FROM code-with-deps as builder
USER node
WORKDIR /usr/src/app
COPY --chown=node eslint-local-rules.js eslint-local-rules.js
COPY --chown=node backend/.eslintrc.js backend/.prettierrc.json backend/jest-e2e.json backend/
COPY --chown=node backend/test backend/test
ARG TURBO_TEAM
ARG TURBO_API
ARG TURBO_TOKEN
CMD ["node", "-r", "ts-node/register", "src/main.ts"]
RUN yarn turbo run build --filter=backend --no-cache --no-daemon
## Stage 2b: Compile TypeScript
FROM code-with-deps as builder
USER node
WORKDIR /usr/src/app/backend
RUN yarn run build
## Stage 3a: Install only prod dependencies
## Stage 2b: Install only prod dependencies
FROM code-with-deps as prod-dependencies
USER node
WORKDIR /usr/src/app
@ -73,7 +50,7 @@ WORKDIR /usr/src/app
RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \
yarn workspaces focus --production @hedgedoc/backend
## Stage 3a: Final image, only production dependencies
## Stage 3: Final image, only production dependencies
FROM base as prod
LABEL org.opencontainers.image.title='HedgeDoc production image'
@ -94,7 +71,7 @@ COPY --chown=node --from=builder /usr/src/app/backend/dist backend/dist
COPY --chown=node backend/public backend/public
COPY --chown=node commons/package.json /usr/src/app/commons/package.json
COPY --chown=node --from=prod-dependencies /usr/src/app/commons/dist commons/dist
COPY --chown=node --from=builder /usr/src/app/commons/dist commons/dist
WORKDIR /usr/src/app/backend
CMD ["node", "dist/main.js"]