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-12-01 14:21:40 -05:00
|
|
|
FROM docker.io/node:20-alpine@sha256:32427bc0620132b2d9e79e405a1b27944d992501a20417a7f407427cc4c2b672 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
|
2022-12-11 18:46:30 -05:00
|
|
|
ENTRYPOINT ["tini", "--"]
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2023-03-02 15:18:13 -05:00
|
|
|
ENV YARN_CACHE_FOLDER=/tmp/.yarn
|
2022-02-12 11:15:06 -05:00
|
|
|
|
|
|
|
## Stage 1: Code with all dependencies
|
|
|
|
FROM base as code-with-deps
|
2023-10-08 12:55:02 -04:00
|
|
|
RUN apk add --no-cache libc6-compat git
|
2022-12-11 18:46:30 -05:00
|
|
|
|
2022-02-12 11:15:06 -05:00
|
|
|
USER node
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
2022-12-11 18:46:30 -05:00
|
|
|
COPY --chown=node . .
|
2022-11-02 11:24:45 -04:00
|
|
|
|
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-12-11 18:46:30 -05:00
|
|
|
yarn install --immutable && yarn workspaces focus hedgedoc @hedgedoc/backend @hedgedoc/commons
|
2022-12-04 16:43:12 -05:00
|
|
|
|
2022-12-11 18:46:30 -05:00
|
|
|
## Stage 2a: Compile TypeScript
|
|
|
|
FROM code-with-deps as builder
|
2022-02-12 11:15:06 -05:00
|
|
|
USER node
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
2022-12-11 18:46:30 -05:00
|
|
|
ARG TURBO_TEAM
|
|
|
|
ARG TURBO_API
|
|
|
|
ARG TURBO_TOKEN
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2023-09-07 13:56:20 -04:00
|
|
|
RUN yarn build --filter=backend --no-cache --no-daemon
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2022-12-11 18:46:30 -05:00
|
|
|
## Stage 2b: Install only prod dependencies
|
2022-11-02 11:24:45 -04:00
|
|
|
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-12-11 18:46:30 -05:00
|
|
|
## Stage 3: Final image, only production dependencies
|
2022-02-12 11:15:06 -05:00
|
|
|
FROM base as prod
|
|
|
|
|
2023-02-21 06:54:07 -05:00
|
|
|
LABEL org.opencontainers.image.title='HedgeDoc production backend image'
|
2022-02-12 11:15:06 -05:00
|
|
|
LABEL org.opencontainers.image.url='https://hedgedoc.org'
|
|
|
|
LABEL org.opencontainers.image.source='https://github.com/hedgedoc/hedgedoc'
|
2023-02-21 06:54:07 -05:00
|
|
|
LABEL org.opencontainers.image.documentation='https://github.com/hedgedoc/hedgedoc/blob/develop/docs/content/dev/docker.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
|
|
|
|
|
2023-02-04 08:44:57 -05:00
|
|
|
COPY --chown=node package.json package.json
|
2022-11-02 11:24:45 -04:00
|
|
|
COPY --chown=node --from=prod-dependencies /usr/src/app/node_modules ./node_modules
|
2022-02-12 11:15:06 -05:00
|
|
|
|
2023-02-04 08:44:57 -05:00
|
|
|
COPY --chown=node backend/package.json backend/package.json
|
2023-09-24 04:27:52 -04:00
|
|
|
COPY --chown=node --from=builder /usr/src/app/backend/dist/src backend/dist
|
2023-02-04 08:44:57 -05:00
|
|
|
COPY --chown=node backend/public backend/public
|
|
|
|
|
|
|
|
COPY --chown=node commons/package.json /usr/src/app/commons/package.json
|
2022-12-11 18:46:30 -05:00
|
|
|
COPY --chown=node --from=builder /usr/src/app/commons/dist commons/dist
|
2023-02-04 08:44:57 -05:00
|
|
|
|
|
|
|
WORKDIR /usr/src/app/backend
|
|
|
|
CMD ["node", "dist/main.js"]
|