Dockerfile 2.1 KB
Newer Older
1
FROM node:16.18.1-bullseye-slim@sha256:f6935acdafe69f822d887e26863314ebbc211f9662b7f4d21ea5531832cfdb20 AS base
Sheogorath's avatar
Sheogorath committed
2

3
FROM base AS builder
Sheogorath's avatar
Sheogorath committed
4
# Build arguments to change source url, branch or tag
5
ARG CODIMD_REPOSITORY
6
ARG HEDGEDOC_REPOSITORY=https://github.com/hedgedoc/hedgedoc.git
Sheogorath's avatar
Sheogorath committed
7
ARG VERSION=master
8 9
RUN if [ -n "${CODIMD_REPOSITORY}" ]; then echo "CODIMD_REPOSITORY is deprecated. Please use HEDGEDOC_REPOSITORY instead" && exit 1; fi

10
# Clone the source and remove git repository but keep the HEAD file
11
RUN apt-get update && apt-get install --no-install-recommends -y git jq ca-certificates python-is-python3 build-essential
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
RUN git clone --depth 1 --branch "$VERSION" "$HEDGEDOC_REPOSITORY" /hedgedoc
RUN git -C /hedgedoc log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1
RUN git -C /hedgedoc rev-parse HEAD > /tmp/gitref
RUN rm -rf /hedgedoc/.git/*
RUN mv /tmp/gitref /hedgedoc/.git/HEAD
RUN jq ".repository.url = \"${HEDGEDOC_REPOSITORY}\"" /hedgedoc/package.json > /hedgedoc/package.new.json
RUN mv /hedgedoc/package.new.json /hedgedoc/package.json

# Install app dependencies and build
WORKDIR /hedgedoc
RUN yarn install --production=false --pure-lockfile
RUN yarn run build
RUN yarn install --production=true --pure-lockfile


FROM base
ARG UID=10000
Sheogorath's avatar
Sheogorath committed
29
ENV NODE_ENV=production
30
ENV UPLOADS_MODE=0700
Sheogorath's avatar
Sheogorath committed
31

32
RUN apt-get update && \
33
    apt-get install --no-install-recommends -y gosu && \
34 35
    rm -r /var/lib/apt/lists/*

36 37 38
# Create hedgedoc user
RUN adduser --uid $UID --home /hedgedoc/ --disabled-password --system hedgedoc

39
COPY --chown=$UID --from=builder /hedgedoc /hedgedoc
Sheogorath's avatar
Sheogorath committed
40 41

# Add configuraton files
42
COPY ["resources/config.json", "/files/"]
Sheogorath's avatar
Sheogorath committed
43

David Mehren's avatar
David Mehren committed
44 45 46 47
# Healthcheck
COPY --chown=$UID /resources/healthcheck.mjs /hedgedoc/healthcheck.mjs
HEALTHCHECK --interval=5s CMD node healthcheck.mjs

48 49 50 51 52 53 54
# For backwards compatibility
RUN ln -s /hedgedoc /codimd

# Symlink configuration files
RUN rm -f /hedgedoc/config.json
RUN ln -s /files/config.json /hedgedoc/config.json

55
WORKDIR /hedgedoc
Sheogorath's avatar
Sheogorath committed
56 57
EXPOSE 3000

Sandro Jäckel's avatar
Sandro Jäckel committed
58
COPY ["resources/docker-entrypoint.sh", "/usr/local/bin/docker-entrypoint.sh"]
Sheogorath's avatar
Sheogorath committed
59 60

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
61

62
CMD ["node", "app.js"]