Dockerfile 1.91 KB
Newer Older
1
FROM node:16.9.0-alpine@sha256:697313d55634a94b36cc5cf75a687b210c7e4a8e433e64d80893bcfca9b11de8 AS base
Sheogorath's avatar
Sheogorath committed
2

3 4 5 6 7
FROM base AS basebuilder
RUN apk update


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

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# Clone the source and remove git repository but keep the HEAD file
RUN apk add git jq
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 rm -rf node_modules
RUN yarn install --production=true --pure-lockfile
Sheogorath's avatar
Sheogorath committed
30

31

32 33 34 35 36
FROM base
ARG UID=10000
ENV NODE_ENV=production

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

41 42 43
# For backwards compatibility
RUN ln -s /hedgedoc /codimd

Sheogorath's avatar
Sheogorath committed
44
# Install all dependencies and build project
45 46 47 48 49 50 51 52
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

# Create hedgedoc user
RUN adduser -u $UID -h /hedgedoc/ -D -S hedgedoc
Sheogorath's avatar
Sheogorath committed
53

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

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

60
CMD ["npm", "start"]