mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-18 05:02:15 +01:00
feat: improve Dockerfiles for a better DX
This commit is contained in:
140
build/Dockerfile
140
build/Dockerfile
@@ -1,11 +1,15 @@
|
|||||||
# Note: ARG instructions do not create additional layers.
|
# ARG instructions do not create additional layers. Instead, next layers will
|
||||||
# Instead, next layers will concatenate them.
|
# concatenate them. Also, we have to repeat ARG instructions in each build
|
||||||
|
# stage that uses them.
|
||||||
ARG GOLANG_VERSION
|
ARG GOLANG_VERSION
|
||||||
# Note: we have to repeat ARG instructions in each build stage that uses them.
|
|
||||||
ARG GOTENBERG_VERSION
|
ARG GOTENBERG_VERSION
|
||||||
|
|
||||||
FROM golang:$GOLANG_VERSION AS builder
|
# ----------------------------------------------
|
||||||
|
# Gotenberg binary build stage
|
||||||
|
# ----------------------------------------------
|
||||||
|
FROM golang:$GOLANG_VERSION AS binary-stage
|
||||||
|
|
||||||
|
ARG GOTENBERG_VERSION
|
||||||
ENV CGO_ENABLED 0
|
ENV CGO_ENABLED 0
|
||||||
|
|
||||||
# Define the working directory outside of $GOPATH (we're using go modules).
|
# Define the working directory outside of $GOPATH (we're using go modules).
|
||||||
@@ -21,14 +25,18 @@ RUN go mod download &&\
|
|||||||
COPY cmd ./cmd
|
COPY cmd ./cmd
|
||||||
COPY pkg ./pkg
|
COPY pkg ./pkg
|
||||||
|
|
||||||
# Build the binary.
|
|
||||||
ARG GOTENBERG_VERSION
|
|
||||||
|
|
||||||
RUN go build -o gotenberg -ldflags "-X 'github.com/gotenberg/gotenberg/v7/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg/main.go
|
RUN go build -o gotenberg -ldflags "-X 'github.com/gotenberg/gotenberg/v7/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg/main.go
|
||||||
|
|
||||||
|
# ----------------------------------------------
|
||||||
|
# Final stage
|
||||||
|
# ----------------------------------------------
|
||||||
FROM debian:11-slim
|
FROM debian:11-slim
|
||||||
|
|
||||||
ARG GOTENBERG_VERSION
|
ARG GOTENBERG_VERSION
|
||||||
|
ARG GOTENBERG_USER_GID
|
||||||
|
ARG GOTENBERG_USER_UID
|
||||||
|
ARG NOTO_COLOR_EMOJI_VERSION
|
||||||
|
ARG PDFTK_VERSION
|
||||||
|
|
||||||
LABEL author="Julien Neuhart" \
|
LABEL author="Julien Neuhart" \
|
||||||
description="A Docker-powered stateless API for PDF files." \
|
description="A Docker-powered stateless API for PDF files." \
|
||||||
@@ -36,43 +44,33 @@ LABEL author="Julien Neuhart" \
|
|||||||
version="$GOTENBERG_VERSION" \
|
version="$GOTENBERG_VERSION" \
|
||||||
website="https://gotenberg.dev"
|
website="https://gotenberg.dev"
|
||||||
|
|
||||||
# Improve fonts subpixel hinting and smoothing.
|
|
||||||
# Credits:
|
|
||||||
# https://github.com/arachnys/athenapdf/issues/69.
|
|
||||||
# https://github.com/arachnys/athenapdf/commit/ba25a8d80a25d08d58865519c4cd8756dc9a336d.
|
|
||||||
COPY build/fonts.conf /etc/fonts/conf.d/100-gotenberg.conf
|
|
||||||
|
|
||||||
# Simple wrapper around Java and PDFtk.
|
|
||||||
COPY build/pdftk.sh /usr/bin/pdftk
|
|
||||||
|
|
||||||
# Setup the Docker image.
|
|
||||||
ARG GOTENBERG_USER_GID
|
|
||||||
ARG GOTENBERG_USER_UID
|
|
||||||
ARG NOTO_COLOR_EMOJI_VERSION
|
|
||||||
ARG PDFTK_VERSION
|
|
||||||
|
|
||||||
# Script for installing either Google Chrome stable on amd64 architecture or
|
|
||||||
# Chromium on other architectures.
|
|
||||||
# See https://github.com/gotenberg/gotenberg/issues/328.
|
|
||||||
COPY build/install-chromium.sh /tmp/install-chromium.sh
|
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
# Create a non-root user.
|
# Create a non-root user.
|
||||||
# All processes in the Docker container will run with this dedicated user.
|
# All processes in the Docker container will run with this dedicated user.
|
||||||
groupadd --gid "$GOTENBERG_USER_GID" gotenberg &&\
|
groupadd --gid "$GOTENBERG_USER_GID" gotenberg &&\
|
||||||
useradd --uid "$GOTENBERG_USER_UID" --gid gotenberg --shell /bin/bash --home /home/gotenberg --no-create-home gotenberg &&\
|
useradd --uid "$GOTENBERG_USER_UID" --gid gotenberg --shell /bin/bash --home /home/gotenberg --no-create-home gotenberg &&\
|
||||||
mkdir /home/gotenberg &&\
|
mkdir /home/gotenberg &&\
|
||||||
chown gotenberg: /home/gotenberg &&\
|
chown gotenberg: /home/gotenberg
|
||||||
# Install dependencies required for the next instructions or debugging.
|
|
||||||
|
RUN \
|
||||||
|
# Install system dependencies required for the next instructions or debugging.
|
||||||
# Note: tini is a helper for reaping zombie processes.
|
# Note: tini is a helper for reaping zombie processes.
|
||||||
apt-get update -qq &&\
|
apt-get update -qq &&\
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends curl gnupg htop tini python3 default-jre-headless &&\
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends curl gnupg htop tini python3 default-jre-headless &&\
|
||||||
ln -s /usr/bin/htop /usr/bin/top &&\
|
ln -s /usr/bin/htop /usr/bin/top &&\
|
||||||
|
# Cleanup.
|
||||||
|
# Note: the Debian image does automatically a clean after each install thanks to a hook.
|
||||||
|
# Therefore, there is no need for apt-get clean.
|
||||||
|
# See https://stackoverflow.com/a/24417119/3248473.
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
RUN \
|
||||||
# Install fonts.
|
# Install fonts.
|
||||||
# Credits:
|
# Credits:
|
||||||
# https://github.com/arachnys/athenapdf/blob/master/cli/Dockerfile.
|
# https://github.com/arachnys/athenapdf/blob/master/cli/Dockerfile.
|
||||||
# https://help.accusoft.com/PrizmDoc/v12.1/HTML/Installing_Asian_Fonts_on_Ubuntu_and_Debian.html.
|
# https://help.accusoft.com/PrizmDoc/v12.1/HTML/Installing_Asian_Fonts_on_Ubuntu_and_Debian.html.
|
||||||
curl -o ./ttf-mscorefonts-installer_3.8_all.deb http://httpredir.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.8_all.deb &&\
|
curl -o ./ttf-mscorefonts-installer_3.8_all.deb http://httpredir.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.8_all.deb &&\
|
||||||
|
apt-get update -qq &&\
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
|
||||||
./ttf-mscorefonts-installer_3.8_all.deb \
|
./ttf-mscorefonts-installer_3.8_all.deb \
|
||||||
culmus \
|
culmus \
|
||||||
@@ -115,53 +113,69 @@ RUN \
|
|||||||
# https://github.com/gotenberg/gotenberg/pull/325.
|
# https://github.com/gotenberg/gotenberg/pull/325.
|
||||||
# https://github.com/googlefonts/noto-emoji.
|
# https://github.com/googlefonts/noto-emoji.
|
||||||
curl -Ls "https://github.com/googlefonts/noto-emoji/raw/$NOTO_COLOR_EMOJI_VERSION/fonts/NotoColorEmoji.ttf" -o /usr/local/share/fonts/NotoColorEmoji.ttf &&\
|
curl -Ls "https://github.com/googlefonts/noto-emoji/raw/$NOTO_COLOR_EMOJI_VERSION/fonts/NotoColorEmoji.ttf" -o /usr/local/share/fonts/NotoColorEmoji.ttf &&\
|
||||||
# Install Google Chrome / Chromium.
|
# Cleanup.
|
||||||
/tmp/install-chromium.sh &&\
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
# Install LibreOffice.
|
|
||||||
|
RUN \
|
||||||
|
# Install either Google Chrome stable on amd64 architecture or
|
||||||
|
# Chromium on other architectures.
|
||||||
|
# See https://github.com/gotenberg/gotenberg/issues/328.
|
||||||
|
/bin/bash -c \
|
||||||
|
'set -e &&\
|
||||||
|
if [[ "$(dpkg --print-architecture)" == "amd64" ]]; then \
|
||||||
|
curl https://dl.google.com/linux/linux_signing_key.pub | apt-key add - &&\
|
||||||
|
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list &&\
|
||||||
|
apt-get update -qq &&\
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends --allow-unauthenticated google-chrome-stable &&\
|
||||||
|
mv /usr/bin/google-chrome-stable /usr/bin/chromium; \
|
||||||
|
else \
|
||||||
|
apt-get update -qq &&\
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium; \
|
||||||
|
fi' &&\
|
||||||
|
# Verify installation.
|
||||||
|
chromium --version &&\
|
||||||
|
# Cleanup.
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
# Install LibreOffice & unoconv.
|
||||||
|
apt-get update -qq &&\
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends libreoffice &&\
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends libreoffice &&\
|
||||||
# Next lines are not currently relevant, as latest versions of LibreOffice
|
|
||||||
# (i.e., > 7.0.4) are causing troubles.
|
|
||||||
# See:
|
|
||||||
# https://packages.debian.org/search?keywords=libreoffice.
|
|
||||||
# https://github.com/gotenberg/gotenberg/issues/442.
|
|
||||||
# https://github.com/gotenberg/gotenberg/issues/516.
|
|
||||||
# https://github.com/gotenberg/gotenberg/issues/529.
|
|
||||||
# https://github.com/gotenberg/gotenberg/issues/537.
|
|
||||||
# https://github.com/gotenberg/gotenberg/issues/568.
|
|
||||||
# Note: we use the bullseye-backports distribution to get the latest LibreOffice version.
|
|
||||||
# See:
|
|
||||||
# https://github.com/gotenberg/gotenberg/pull/322.
|
|
||||||
# https://github.com/gotenberg/gotenberg/issues/403.
|
|
||||||
#echo "deb https://httpredir.debian.org/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list &&\
|
|
||||||
#apt-get update -qq &&\
|
|
||||||
#DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends -t bullseye-backports libreoffice &&\
|
|
||||||
# Download unoconv (Python script).
|
|
||||||
curl -Ls https://raw.githubusercontent.com/dagwieers/unoconv/master/unoconv -o /usr/bin/unoconv &&\
|
curl -Ls https://raw.githubusercontent.com/dagwieers/unoconv/master/unoconv -o /usr/bin/unoconv &&\
|
||||||
chmod +x /usr/bin/unoconv &&\
|
chmod +x /usr/bin/unoconv &&\
|
||||||
# unoconv will look for the Python binary, which has to be at version 3.
|
# unoconv will look for the Python binary, which has to be at version 3.
|
||||||
ln -s /usr/bin/python3 /usr/bin/python &&\
|
ln -s /usr/bin/python3 /usr/bin/python &&\
|
||||||
# Download PDFtk.
|
# Verify installations.
|
||||||
# See https://github.com/gotenberg/gotenberg/pull/273. \
|
libreoffice --version &&\
|
||||||
|
unoconv --version &&\
|
||||||
|
# Cleanup.
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
# Install PDFtk & QPDF (PDF engines).
|
||||||
|
# See https://github.com/gotenberg/gotenberg/pull/273.
|
||||||
curl -o /usr/bin/pdftk-all.jar "https://gitlab.com/api/v4/projects/5024297/packages/generic/pdftk-java/$PDFTK_VERSION/pdftk-all.jar" &&\
|
curl -o /usr/bin/pdftk-all.jar "https://gitlab.com/api/v4/projects/5024297/packages/generic/pdftk-java/$PDFTK_VERSION/pdftk-all.jar" &&\
|
||||||
chmod a+x /usr/bin/pdftk-all.jar &&\
|
chmod a+x /usr/bin/pdftk-all.jar &&\
|
||||||
# Download QPDF.
|
echo '#!/bin/bash\n\nexec java -jar /usr/bin/pdftk-all.jar "$@"' > /usr/bin/pdftk && \
|
||||||
|
chmod +x /usr/bin/pdftk &&\
|
||||||
|
apt-get update -qq &&\
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends qpdf &&\
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends qpdf &&\
|
||||||
# See https://github.com/nextcloud/docker/issues/380.
|
# See https://github.com/nextcloud/docker/issues/380.
|
||||||
mkdir -p /usr/share/man/man1 &&\
|
mkdir -p /usr/share/man/man1 &&\
|
||||||
# Cleanup.
|
# Verify installations.
|
||||||
# Note: the Debian image does automatically a clean after each install thanks to a hook.
|
|
||||||
# Therefore, there is no need for apt-get clean.
|
|
||||||
# See https://stackoverflow.com/a/24417119/3248473.
|
|
||||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* &&\
|
|
||||||
# Print versions of main dependencies.
|
|
||||||
chromium --version &&\
|
|
||||||
libreoffice --version &&\
|
|
||||||
unoconv --version &&\
|
|
||||||
pdftk --version &&\
|
pdftk --version &&\
|
||||||
qpdf --version
|
qpdf --version &&\
|
||||||
|
# Cleanup.
|
||||||
|
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
|
# Improve fonts subpixel hinting and smoothing.
|
||||||
|
# Credits:
|
||||||
|
# https://github.com/arachnys/athenapdf/issues/69.
|
||||||
|
# https://github.com/arachnys/athenapdf/commit/ba25a8d80a25d08d58865519c4cd8756dc9a336d.
|
||||||
|
COPY build/fonts.conf /etc/fonts/conf.d/100-gotenberg.conf
|
||||||
|
|
||||||
# Copy the Gotenberg binary from the builder stage.
|
# Copy the Gotenberg binary from the builder stage.
|
||||||
COPY --from=builder /home/gotenberg /usr/bin/
|
COPY --from=binary-stage /home/gotenberg /usr/bin/
|
||||||
|
|
||||||
# Environment variables required by modules or else.
|
# Environment variables required by modules or else.
|
||||||
ENV GC_EXCLUDE_SUBSTR "hsperfdata_root,hsperfdata_gotenberg"
|
ENV GC_EXCLUDE_SUBSTR "hsperfdata_root,hsperfdata_gotenberg"
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
# Note: ARG instructions do not create additional layers.
|
|
||||||
# Instead, next layers will concatenate them.
|
|
||||||
ARG DOCKER_REPOSITORY
|
ARG DOCKER_REPOSITORY
|
||||||
ARG GOTENBERG_VERSION
|
ARG GOTENBERG_VERSION
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
ARCH=$(dpkg --print-architecture)
|
|
||||||
|
|
||||||
if [[ "$ARCH" == "amd64" ]]; then
|
|
||||||
curl https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
|
|
||||||
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list
|
|
||||||
apt-get update -qq
|
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends --allow-unauthenticated google-chrome-stable
|
|
||||||
mv /usr/bin/google-chrome-stable /usr/bin/chromium
|
|
||||||
else
|
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium
|
|
||||||
fi
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
exec java -jar /usr/bin/pdftk-all.jar "$@"
|
|
||||||
@@ -11,12 +11,6 @@ FROM $DOCKER_REPOSITORY/gotenberg:$GOTENBERG_VERSION
|
|||||||
|
|
||||||
USER root
|
USER root
|
||||||
|
|
||||||
COPY --from=golang /usr/local/go /usr/local/go
|
|
||||||
COPY ./test/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
|
|
||||||
COPY ./test/golint.sh /usr/bin/golint
|
|
||||||
COPY ./test/gotest.sh /usr/bin/gotest
|
|
||||||
COPY ./test/gotodos.sh /usr/bin/gotodos
|
|
||||||
|
|
||||||
ENV GOPATH /go
|
ENV GOPATH /go
|
||||||
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
|
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
|
||||||
ENV CGO_ENABLED 1
|
ENV CGO_ENABLED 1
|
||||||
@@ -39,6 +33,12 @@ RUN apt-get update -qq &&\
|
|||||||
sed -i 's#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/go/bin:/usr/local/go/bin#g' /etc/sudoers &&\
|
sed -i 's#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin#/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/go/bin:/usr/local/go/bin#g' /etc/sudoers &&\
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin $GOLANGCI_LINT_VERSION
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin $GOLANGCI_LINT_VERSION
|
||||||
|
|
||||||
|
COPY --from=golang /usr/local/go /usr/local/go
|
||||||
|
COPY ./test/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
|
||||||
|
COPY ./test/golint.sh /usr/bin/golint
|
||||||
|
COPY ./test/gotest.sh /usr/bin/gotest
|
||||||
|
COPY ./test/gotodos.sh /usr/bin/gotodos
|
||||||
|
|
||||||
# Pristine working directory.
|
# Pristine working directory.
|
||||||
WORKDIR /tests
|
WORKDIR /tests
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user