Dockerfile 2.12 KB
Newer Older
1
FROM node:16.17.1-alpine@sha256:7584b116f368d94fab2ecc21ebbcfd5434a3427c2f96f846972821b5ad0266fc 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 12
RUN apk update && apk add git jq python3 build-base
RUN ln -s /usr/bin/python3 /usr/bin/python # sqlite3 build scripts want a 'python' binary
13 14 15 16 17 18 19 20 21 22 23 24 25
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
Sheogorath's avatar
Sheogorath committed
26

27

28 29 30
FROM base
ARG UID=10000
ENV NODE_ENV=production
31
ENV UPLOADS_MODE=0700
32

33 34 35
# Create hedgedoc user
RUN adduser -u $UID -h /hedgedoc/ -D -S hedgedoc

36
COPY --chown=$UID --from=builder /hedgedoc /hedgedoc
Sheogorath's avatar
Sheogorath committed
37 38

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

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

45 46 47
# For backwards compatibility
RUN ln -s /hedgedoc /codimd

Sheogorath's avatar
Sheogorath committed
48
# Install all dependencies and build project
49 50 51 52 53 54
RUN apk add --no-cache --no-progress --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ gosu

# 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
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
60

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