2022-02-12 11:15:06 -05:00
|
|
|
# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
#
|
|
|
|
# This Dockerfile uses features which are only available in BuildKit - see
|
|
|
|
# https://docs.docker.com/go/buildkit/ for more information.
|
|
|
|
#
|
|
|
|
# To build the image, run `docker build` command from the root of the
|
|
|
|
# repository:
|
|
|
|
#
|
|
|
|
# DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile .
|
|
|
|
|
|
|
|
## Stage 0: Base image with only yarn and package.json
|
2023-01-06 21:02:12 -05:00
|
|
|
FROM docker.io/node:19-alpine@sha256:88e1842dc5fa44e40aea2d097685612c15c5f32b18d8b55766355de53dd5d5a7 as base
|
2022-02-12 11:15:06 -05:00
|
|
|
# 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"]
|
|
|
|
|
2022-11-02 11:24:45 -04:00
|
|
|
ENV YARN_CACHE_FOLDER /tmp/.yarn
|
2022-02-12 11:15:06 -05:00
|
|
|
USER node
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
|
|
|
## Stage 1: Code with all dependencies
|
|
|
|
FROM base as code-with-deps
|
|
|
|
USER node
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
2022-11-02 11:24:45 -04:00
|
|
|
COPY --chown=node .yarn/plugins .yarn/plugins
|
2022-12-04 16:43:12 -05:00
|
|
|
COPY --chown=node .yarn/patches .yarn/patches
|
2022-11-02 11:24:45 -04:00
|
|
|
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/
|
2022-12-04 16:43:12 -05:00
|
|
|
COPY --chown=node commons/package.json commons/
|
2022-11-02 11:24:45 -04:00
|
|
|
COPY --chown=node frontend/package.json frontend/
|
|
|
|
|
2022-02-12 11:15:06 -05:00
|
|
|
# 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 \
|
2022-11-02 11:24:45 -04:00
|
|
|
yarn install --immutable && yarn workspaces focus @hedgedoc/backend
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2022-12-04 16:43:12 -05:00
|
|
|
COPY --chown=node commons/ commons/
|
2022-11-02 11:24:45 -04:00
|
|
|
COPY --chown=node backend/nest-cli.json backend/tsconfig.json backend/tsconfig.build.json backend/
|
|
|
|
COPY --chown=node backend/src backend/src
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2022-12-04 16:43:12 -05:00
|
|
|
WORKDIR /usr/src/app/commons
|
|
|
|
|
|
|
|
RUN yarn build
|
|
|
|
|
2022-02-12 11:15:06 -05:00
|
|
|
## Stage 2a: Dev config files and tests
|
|
|
|
FROM code-with-deps as development
|
|
|
|
USER node
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
2022-11-02 11:24:45 -04:00
|
|
|
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
|
2022-02-12 11:15:06 -05:00
|
|
|
|
|
|
|
CMD ["node", "-r", "ts-node/register", "src/main.ts"]
|
|
|
|
|
|
|
|
## Stage 2b: Compile TypeScript
|
|
|
|
FROM code-with-deps as builder
|
|
|
|
USER node
|
2022-11-02 11:24:45 -04:00
|
|
|
WORKDIR /usr/src/app/backend
|
2022-02-12 11:15:06 -05:00
|
|
|
|
|
|
|
RUN yarn run build
|
|
|
|
|
2022-11-02 11:24:45 -04:00
|
|
|
## Stage 3a: Install only prod dependencies
|
|
|
|
FROM code-with-deps as prod-dependencies
|
|
|
|
USER node
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
|
|
|
RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \
|
|
|
|
yarn workspaces focus --production @hedgedoc/backend
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2022-11-02 11:24:45 -04:00
|
|
|
## Stage 3a: Final image, only production dependencies
|
2022-02-12 11:15:06 -05:00
|
|
|
FROM base as prod
|
|
|
|
|
|
|
|
LABEL org.opencontainers.image.title='HedgeDoc production image'
|
|
|
|
LABEL org.opencontainers.image.url='https://hedgedoc.org'
|
|
|
|
LABEL org.opencontainers.image.source='https://github.com/hedgedoc/hedgedoc'
|
2022-11-02 11:24:45 -04:00
|
|
|
LABEL org.opencontainers.image.documentation='https://github.com/hedgedoc/hedgedoc/blob/develop/docs/docker/README.md'
|
2022-02-12 11:15:06 -05:00
|
|
|
LABEL org.opencontainers.image.licenses='AGPL-3.0'
|
|
|
|
|
|
|
|
USER node
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
|
2022-11-02 11:24:45 -04:00
|
|
|
COPY --chown=node --from=builder /usr/src/app/backend/dist ./
|
|
|
|
COPY --chown=node backend/package.json package.json
|
|
|
|
COPY --chown=node --from=prod-dependencies /usr/src/app/node_modules ./node_modules
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2022-11-02 11:24:45 -04:00
|
|
|
CMD ["node", "main.js"]
|