Dockerfile 3.42 KB
Newer Older
1
FROM node:12.18.0-slim
Sheogorath's avatar
Sheogorath committed
2 3

# Build arguments to change source url, branch or tag
4
ARG CODIMD_REPOSITORY=https://github.com/codimd/server.git
Sheogorath's avatar
Sheogorath committed
5
ARG VERSION=master
6
ARG UID=10000
Sheogorath's avatar
Sheogorath committed
7 8

# Set some default config variables
9
ARG DEBIAN_FRONTEND=noninteractive
Sandro Jäckel's avatar
Sandro Jäckel committed
10
ENV DOCKERIZE_VERSION=v0.6.1
Sheogorath's avatar
Sheogorath committed
11 12
ENV NODE_ENV=production

13 14 15 16 17 18
RUN apt-get update && \
    apt-get install --no-install-recommends -y \
      ca-certificates \
      wget && \
    rm -r /var/lib/apt/lists/*

Sheogorath's avatar
Sheogorath committed
19 20 21 22
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
    tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
    rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

23
ENV GOSU_VERSION 1.11
24
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
25
COPY ["resources/gosu-gpg.key", "/tmp/gosu.key"]
26
RUN set -ex; \
27 28 29
    apt-get update && \
    apt-get install --no-install-recommends -qy \
      gpg && \
30 31 32
    dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
    wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
    wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
33 34
    \
    # verify the signature
35
    export GNUPGHOME="$(mktemp -d)"; \
Sheogorath's avatar
Sheogorath committed
36
    gpg --no-tty --import /tmp/gosu.key; \
37 38
    gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
    rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
39
    \
40
    chmod +x /usr/local/bin/gosu; \
41
    # verify that the binary works
42 43 44 45
    gosu nobody true && \
    apt-get autoremove --purge -qy \
      gpg && \
    rm -r /var/lib/apt/lists/*
46

Sheogorath's avatar
Sheogorath committed
47
# Add configuraton files
48
COPY ["resources/config.json", "resources/.sequelizerc", "/files/"]
Sheogorath's avatar
Sheogorath committed
49

50 51 52 53 54 55
RUN export dev_apt=( \
      "bzip2" \
      "git" \
      "jq" \
    ) && \
    apt-get update && \
56
    apt-get install --no-install-recommends -y \
57
      "${dev_apt[@]}" \
Sandro Jäckel's avatar
Sandro Jäckel committed
58 59
      # Add fonts for PDF export
      fonts-noto && \
60
    \
Sheogorath's avatar
Sheogorath committed
61
    # Clone the source
62
    git clone --depth 1 --branch "$VERSION" "$CODIMD_REPOSITORY" /codimd && \
Sheogorath's avatar
Sheogorath committed
63
    # Print the cloned version and clean up git files
64
    cd /codimd && \
Sheogorath's avatar
Sheogorath committed
65
    git log --pretty=format:'%ad %h %d' --abbrev-commit --date=short -1 && echo && \
66
    git rev-parse HEAD > /tmp/gitref && \
67
    rm -rf /codimd/.git && \
68
    \
69 70 71 72 73
    # Mime the git repository for fullversion
    mkdir /codimd/.git && \
    mv /tmp/gitref /codimd/.git/HEAD && \
    jq ".repository.url = \"${CODIMD_REPOSITORY}\"" /codimd/package.json > /codimd/package.new.json && \
    mv /codimd/package.new.json /codimd/package.json && \
74
    \
Sheogorath's avatar
Sheogorath committed
75
    # Symlink configuration files
Sandro Jäckel's avatar
Sandro Jäckel committed
76 77 78 79
    rm -f /codimd/config.json && \
    ln -s /files/config.json /codimd/config.json && \
    rm -f /codimd/.sequelizerc && \
    ln -s /files/.sequelizerc /codimd/.sequelizerc && \
80
    \
Sheogorath's avatar
Sheogorath committed
81
    # Install NPM dependencies and build project
82 83
    yarn install --pure-lockfile && \
    yarn install --production=false --pure-lockfile && \
Sheogorath's avatar
Sheogorath committed
84
    npm run build && \
85
    \
Sheogorath's avatar
Sheogorath committed
86
    # Clean up this layer
87
    yarn install && \
Sheogorath's avatar
Sheogorath committed
88
    yarn cache clean && \
89
    apt-get autoremove --purge -qy "${dev_apt[@]}" && \
Sandro Jäckel's avatar
Sandro Jäckel committed
90
    rm -r /var/lib/apt/lists/* && \
91
    # Create codimd user
92
    adduser --uid $UID --home /codimd/ --disabled-password --system codimd && \
93
    chown -R codimd /codimd/
Sheogorath's avatar
Sheogorath committed
94

95
WORKDIR /codimd
Sheogorath's avatar
Sheogorath committed
96 97
EXPOSE 3000

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

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

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