Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
128 lines (101 loc) · 5.83 KB
/
Copy pathDockerfile
File metadata and controls
128 lines (101 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
################################################################################
# docshot: the Go binary listens on :3000 and supervises Gotenberg on
# 127.0.0.1:3001 (internal). Three stages: build -> runtime -> flattened final.
################################################################################
ARG GOTENBERG_VERSION=8.37
################################################################################
# Stage 1: build the Go binary (no CGO)
################################################################################
FROM golang:1.27-trixie AS build
WORKDIR /src
# Dependencies first, so they stay cached until go.mod/go.sum change.
COPY go.mod go.sum ./
RUN go mod download
COPY cmd ./cmd
COPY internal ./internal
ARG VERSION=dev
RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o /docshot ./cmd/docshot
################################################################################
# Stage 2: runtime packages on top of Gotenberg
################################################################################
FROM gotenberg/gotenberg:${GOTENBERG_VERSION} AS runtime
USER root
# - apt-get upgrade: Debian security updates (Chromium, LibreOffice, OpenSSL...) without waiting for a Gotenberg rebuild
# - ffmpeg and the per-format helpers (tiff, archives, djvu, xps, dot, raw)
# - libwebp.so symlinks: gen2brain/webp dlopens them for native WebP encoding
# - /tmp/docshot: disk cache, owned by the runtime user so a named volume inherits it
RUN apt-get update \
&& apt-get upgrade -y --no-install-recommends \
&& apt-get install -y --no-install-recommends ffmpeg libwebp7 libwebpdemux2 \
libtiff-tools libarchive-tools djvulibre-bin libgxps-utils graphviz libraw-bin \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& lib="$(dirname /usr/lib/*-linux-gnu/libwebp.so.7)" \
&& ln -sf libwebp.so.7 "$lib/libwebp.so" && ln -sf libwebpdemux.so.2 "$lib/libwebpdemux.so" \
&& install -d -o gotenberg -g gotenberg /tmp/docshot
COPY --from=build /docshot /usr/bin/docshot
# Chromium phones home on its own (Optimization Guide, component updates, Gaia
# ListAccounts, network time...). Gotenberg's proxy blocks it, but the attempts still
# show up in network logs. The wrapper therefore:
# - skips Debian's /usr/bin/chromium launcher (it loads Google API keys, remote extensions),
# - points the Gaia and component-updater URLs at a closed loopback port,
# - appends the features to switch off to Gotenberg's own --disable-features
# (Chromium honours only the last one).
RUN printf '%s\n' '#!/bin/sh' \
'off=OptimizationHints,OptimizationGuideModelDownloading,OptimizationHintsFetching,OptimizationTargetPrediction,OptimizationGuideOnDeviceModel,Translate,MediaRouter,CertificateTransparencyComponentUpdater,SigninInterceptBubble,SyncPromo,DiscoverFeed,AutofillServerCommunication,NetworkTimeServiceQuerying' \
'for a; do shift; case "$a" in --disable-features=*) a="$a,$off"; seen=1;; esac; set -- "$@" "$a"; done' \
'[ -n "$seen" ] || set -- "$@" "--disable-features=$off"' \
'export GOOGLE_API_KEY=no GOOGLE_DEFAULT_CLIENT_ID=no GOOGLE_DEFAULT_CLIENT_SECRET=no' \
'exec /usr/lib/chromium/chromium --media-router=0 --disable-pings --disable-background-networking \' \
' --disable-component-update --disable-sync --disable-domain-reliability --no-pings \' \
' --no-default-browser-check --disable-client-side-phishing-detection --disable-default-apps \' \
' --metrics-recording-only --disable-component-extensions-with-background-pages \' \
' --gaia-url=http://127.0.0.1:9 --component-updater=url-source=http://127.0.0.1:9/ "$@"' \
> /usr/local/bin/chromium-offline \
&& chmod 755 /usr/local/bin/chromium-offline
USER gotenberg
################################################################################
# Stage 3: flatten into one layer
#
# As separate layers, the upgraded Chromium and LibreOffice would sit on top of
# the base's old copies (~1 GB). FROM scratch drops the base image's config, so
# its ENV and WORKDIR are restated below: re-check them after a
# GOTENBERG_VERSION bump.
################################################################################
FROM scratch
# hadolint ignore=DL3067
COPY --from=runtime / /
# Restated from the Gotenberg base image.
ENV PATH=/opt/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
TZ=UTC \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
PDFTK_BIN_PATH=/usr/bin/pdftk \
QPDF_BIN_PATH=/usr/bin/qpdf \
EXIFTOOL_BIN_PATH=/usr/bin/exiftool \
PDFCPU_BIN_PATH=/usr/bin/pdfcpu \
GOTENBERG_VERSIONS_DIR_PATH=/opt/gotenberg/versions \
OTEL_TRACES_EXPORTER=none \
OTEL_METRICS_EXPORTER=none \
OTEL_LOGS_EXPORTER=none \
CHROMIUM_BIN_PATH=/usr/local/bin/chromium-offline \
CHROMIUM_HYPHEN_DATA_DIR_PATH=/opt/gotenberg/chromium-hyphen-data \
LIBREOFFICE_BIN_PATH=/usr/lib/libreoffice/program/soffice.bin \
UNOCONVERTER_BIN_PATH=/usr/bin/unoconverter
WORKDIR /home/gotenberg
ARG VERSION=dev
LABEL org.opencontainers.image.version=$VERSION
USER gotenberg
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 CMD ["/usr/bin/docshot", "-healthcheck"]
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/bin/docshot"]
################################################################################
# Gotenberg's command line, as docshot starts it for untrusted input:
# no JavaScript, no network (public and private IPs), no downloadFrom, no webhooks.
################################################################################
CMD ["gotenberg", \
"--chromium-disable-javascript=true", \
"--chromium-deny-public-ips=true", "--chromium-deny-private-ips=true", \
"--libreoffice-deny-public-ips=true", "--libreoffice-deny-private-ips=true", \
"--api-disable-download-from=true", "--webhook-disable=true", \
"--api-timeout=150s", "--log-level=warn"]