Skip to content

Commit 12d91a9

Browse files
committed
feat(distroless): Provide distroless container image
This patch introduces a distroless container image, which cuts down the container content to the bare minimum. No shells, no package managers, nothing, just the hedgedoc. These constraints make this setup very robust, but also hard to debug without the right tools, therefore it's not recommended to be used by people who are not completely familiar with containers and low-level debugging tools. Nontheless this image should be very useful in Kubernetes deployments. Further, compared to the alpine container image, it'll further cut down dependencies while staying on glibc, which can prevent some common issues with musllib. The distroless image is based on Google distroless base image for nodejs: https://github.com/GoogleContainerTools/distroless/tree/55d918e07c9341f83519ab1fc6d8fe0197bca13f/nodejs Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
1 parent 3a15ab9 commit 12d91a9

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
base: [debian, alpine]
13+
base: [debian, alpine, distroless]
1414
env:
1515
HEDGEDOC_VERSION: master
1616
HEDGEDOC_IMAGE: quay.io/hedgedoc/hedgedoc-nightly

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
base: [debian, alpine]
11+
base: [debian, alpine, distroless]
1212
env:
1313
# renovate: datasource=github-tags depName=hedgedoc/hedgedoc versioning=semver
1414
HEDGEDOC_VERSION: 1.9.3

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
base: [debian, alpine]
13+
base: [debian, alpine, distroless]
1414
env:
1515
BASE: ${{ matrix.base }} # needed in tests/version.sh
1616
steps:

distroless/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)