|
| 1 | +FROM docker.io/library/node:16.14.2-bullseye-slim@sha256:d54981fe891c9e3442ea05cb668bc8a2a3ee38609ecce52c7b5a609fadc6f64b AS base |
| 2 | + |
| 3 | +FROM base AS builder |
| 4 | + |
| 5 | + |
| 6 | +RUN apt-get update && apt-get install --no-install-recommends -y git jq ca-certificates python-is-python3 build-essential |
| 7 | + |
| 8 | + |
| 9 | +# Build arguments to change source url, branch or tag |
| 10 | +ARG CODIMD_REPOSITORY |
| 11 | +ARG HEDGEDOC_REPOSITORY=https://github.com/hedgedoc/hedgedoc.git |
| 12 | +ARG VERSION=master |
| 13 | +RUN if [ -n "${CODIMD_REPOSITORY}" ]; then echo "CODIMD_REPOSITORY is deprecated. Please use HEDGEDOC_REPOSITORY instead" && exit 1; fi |
| 14 | + |
| 15 | +# Clone the source and remove git repository but keep the HEAD file |
| 16 | +RUN git clone --depth 1 --branch "$VERSION" "$HEDGEDOC_REPOSITORY" /hedgedoc |
| 17 | +RUN git -C /hedgedoc log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1 |
| 18 | +RUN git -C /hedgedoc rev-parse HEAD > /tmp/gitref |
| 19 | +RUN rm -rf /hedgedoc/.git/* |
| 20 | +RUN mv /tmp/gitref /hedgedoc/.git/HEAD |
| 21 | +RUN jq ".repository.url = \"${HEDGEDOC_REPOSITORY}\"" /hedgedoc/package.json > /hedgedoc/package.new.json |
| 22 | +RUN mv /hedgedoc/package.new.json /hedgedoc/package.json |
| 23 | + |
| 24 | + |
| 25 | +# Install app dependencies and build |
| 26 | +WORKDIR /hedgedoc |
| 27 | +RUN yarn install --production=false --frozen-lockfile |
| 28 | +RUN yarn run build |
| 29 | +RUN yarn install --production=true --frozen-lockfile |
| 30 | +RUN rm -f /hedgedoc/config.json |
| 31 | +RUN ln -s /files/config.json /hedgedoc/config.json |
| 32 | +COPY --chown=$UID /resources/healthcheck.mjs /hedgedoc/healthcheck.mjs |
| 33 | + |
| 34 | +# Use distroless image |
| 35 | +FROM gcr.io/distroless/nodejs:16@sha256:0f6640867b28a635af23d8c8e2b15d73de412a04af3320d747fe0ab64987e512 |
| 36 | + |
| 37 | +ARG UID=10000 |
| 38 | +ENV NODE_ENV=production |
| 39 | +ENV UPLOADS_MODE=0700 |
| 40 | + |
| 41 | +COPY --chown=$UID --from=builder /hedgedoc /hedgedoc |
| 42 | +COPY ["resources/config.json", "/files/"] |
| 43 | + |
| 44 | +HEALTHCHECK --interval=5s CMD node healthcheck.mjs |
| 45 | +WORKDIR /hedgedoc |
| 46 | +EXPOSE 3000 |
| 47 | +USER $UID |
| 48 | + |
| 49 | +CMD ["app.js"] |
0 commit comments