chore(Dockerfile): better distinction between intructions in a single RUN

This commit is contained in:
Julien Neuhart
2026-03-30 22:24:32 +02:00
parent 813926cd47
commit 61cadd0e6a

View File

@@ -17,16 +17,16 @@ 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).
WORKDIR /home WORKDIR /home
RUN curl -Ls "https://github.com/pdfcpu/pdfcpu/archive/refs/tags/$PDFCPU_VERSION.tar.gz" -o pdfcpu.tar.gz &&\ RUN curl -Ls "https://github.com/pdfcpu/pdfcpu/archive/refs/tags/$PDFCPU_VERSION.tar.gz" -o pdfcpu.tar.gz \
tar --strip-components=1 -xvzf pdfcpu.tar.gz && tar --strip-components=1 -xvzf pdfcpu.tar.gz
# Install module dependencies. # Install module dependencies.
RUN go mod download &&\ RUN go mod download \
go mod verify && go mod verify
RUN go build -o pdfcpu -ldflags "-s -w -X 'main.version=$PDFCPU_VERSION' -X 'github.com/pdfcpu/pdfcpu/pkg/pdfcpu.VersionStr=$PDFCPU_VERSION' -X main.builtBy=gotenberg" ./cmd/pdfcpu &&\ RUN go build -o pdfcpu -ldflags "-s -w -X 'main.version=$PDFCPU_VERSION' -X 'github.com/pdfcpu/pdfcpu/pkg/pdfcpu.VersionStr=$PDFCPU_VERSION' -X main.builtBy=gotenberg" ./cmd/pdfcpu \
# Verify installation. # Verify installation.
./pdfcpu version && ./pdfcpu version
# ---------------------------------------------- # ----------------------------------------------
# Gotenberg binary build stage # Gotenberg binary build stage
@@ -42,16 +42,16 @@ WORKDIR /home
# Install module dependencies. # Install module dependencies.
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download &&\ RUN go mod download \
go mod verify && go mod verify
# Copy the source code. # Copy the source code.
COPY cmd ./cmd COPY cmd ./cmd
COPY pkg ./pkg COPY pkg ./pkg
RUN go build -o gotenberg -ldflags "-s -w -X 'github.com/gotenberg/gotenberg/v8/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg/main.go &&\ RUN go build -o gotenberg -ldflags "-s -w -X 'github.com/gotenberg/gotenberg/v8/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg/main.go \
go build -o gotenberg-chromium -ldflags "-s -w -X 'github.com/gotenberg/gotenberg/v8/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg-chromium/main.go &&\ && go build -o gotenberg-chromium -ldflags "-s -w -X 'github.com/gotenberg/gotenberg/v8/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg-chromium/main.go \
go build -o gotenberg-libreoffice -ldflags "-s -w -X 'github.com/gotenberg/gotenberg/v8/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg-libreoffice/main.go && go build -o gotenberg-libreoffice -ldflags "-s -w -X 'github.com/gotenberg/gotenberg/v8/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg-libreoffice/main.go
# ---------------------------------------------- # ----------------------------------------------
# Custom JRE stage # Custom JRE stage
@@ -59,10 +59,9 @@ RUN go build -o gotenberg -ldflags "-s -w -X 'github.com/gotenberg/gotenberg/v8/
# ---------------------------------------------- # ----------------------------------------------
FROM debian:13-slim AS custom-jre-stage FROM debian:13-slim AS custom-jre-stage
RUN \ RUN apt-get update -qq \
apt-get update -qq &&\ && apt-get upgrade -yqq \
apt-get upgrade -yqq &&\ && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends default-jdk-headless binutils
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends default-jdk-headless binutils
# Note: jdeps helps finding which modules a JAR requires. # Note: jdeps helps finding which modules a JAR requires.
# Currently only for PDFtk, as we don't rely on LibreOffice UNO Java SDK. # Currently only for PDFtk, as we don't rely on LibreOffice UNO Java SDK.
@@ -84,16 +83,16 @@ FROM debian:13-slim AS downloader-stage
# See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package. # See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package.
ARG PDFTK_VERSION=v3.3.3 ARG PDFTK_VERSION=v3.3.3
RUN apt-get update -qq &&\ RUN apt-get update -qq \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends curl ca-certificates && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends curl ca-certificates
WORKDIR /downloads WORKDIR /downloads
RUN curl -Ls https://raw.githubusercontent.com/gotenberg/unoconverter/v0.2.0/unoconv -o unoconverter &&\ RUN curl -Ls https://raw.githubusercontent.com/gotenberg/unoconverter/v0.2.0/unoconv -o unoconverter \
chmod +x unoconverter && chmod +x unoconverter
RUN curl -o pdftk-all.jar "https://gitlab.com/api/v4/projects/5024297/packages/generic/pdftk-java/$PDFTK_VERSION/pdftk-all.jar" &&\ RUN curl -o pdftk-all.jar "https://gitlab.com/api/v4/projects/5024297/packages/generic/pdftk-java/$PDFTK_VERSION/pdftk-all.jar" \
chmod a+x pdftk-all.jar && chmod a+x pdftk-all.jar
# ---------------------------------------------- # ----------------------------------------------
# Base image stage # Base image stage
@@ -115,19 +114,17 @@ FROM base-image-stage AS common-stage
ARG GOTENBERG_USER_GID=1001 ARG GOTENBERG_USER_GID=1001
ARG GOTENBERG_USER_UID=1001 ARG GOTENBERG_USER_UID=1001
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. RUN 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
RUN \ # Note: tini is a helper for reaping zombie processes.
apt-get update -qq &&\ RUN apt-get update -qq \
apt-get upgrade -yqq &&\ && apt-get upgrade -yqq \
# Note: tini is a helper for reaping zombie processes. && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
tini \ tini \
# Install fonts. # Install fonts.
# Essential metric-compatible fonts for LibreOffice layout fidelity (replaces MS Fonts). # Essential metric-compatible fonts for LibreOffice layout fidelity (replaces MS Fonts).
@@ -144,27 +141,26 @@ RUN \
# Tofu prevention. # Tofu prevention.
fonts-noto-core \ fonts-noto-core \
# Install QPDF & ExifTool (PDF engines). # Install QPDF & ExifTool (PDF engines).
qpdf exiftool &&\ qpdf exiftool \
# 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. # Cleanup.
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy PDFtk jar and create bash wrapper. # Copy PDFtk jar and create bash wrapper.
# See https://github.com/gotenberg/gotenberg/pull/273. # See https://github.com/gotenberg/gotenberg/pull/273.
COPY --link --from=downloader-stage /downloads/pdftk-all.jar /usr/bin/pdftk-all.jar COPY --link --from=downloader-stage /downloads/pdftk-all.jar /usr/bin/pdftk-all.jar
RUN printf '#!/bin/bash\n\nexec java -jar /usr/bin/pdftk-all.jar "$@"' > /usr/bin/pdftk &&\ RUN printf '#!/bin/bash\n\nexec java -jar /usr/bin/pdftk-all.jar "$@"' > /usr/bin/pdftk \
chmod +x /usr/bin/pdftk && chmod +x /usr/bin/pdftk
# Support for arbitrary user IDs (OpenShift). # Support for arbitrary user IDs (OpenShift).
# See: # See:
# https://github.com/gotenberg/gotenberg/issues/1049. # https://github.com/gotenberg/gotenberg/issues/1049.
# https://docs.redhat.com/en/documentation/openshift_container_platform/4.15/html/images/creating-images#use-uid_create-images. # https://docs.redhat.com/en/documentation/openshift_container_platform/4.15/html/images/creating-images#use-uid_create-images.
RUN \ RUN usermod -aG root gotenberg \
usermod -aG root gotenberg &&\ && chgrp -R 0 /home/gotenberg \
chgrp -R 0 /home/gotenberg &&\ && chmod -R g=u /home/gotenberg
chmod -R g=u /home/gotenberg
# Improve fonts subpixel hinting and smoothing. # Improve fonts subpixel hinting and smoothing.
# Credits: # Credits:
@@ -212,20 +208,18 @@ LABEL org.opencontainers.image.title="Gotenberg" \
org.opencontainers.image.documentation="https://gotenberg.dev" \ org.opencontainers.image.documentation="https://gotenberg.dev" \
org.opencontainers.image.source="https://github.com/gotenberg/gotenberg" org.opencontainers.image.source="https://github.com/gotenberg/gotenberg"
RUN \ # Install Chromium.
# Install Chromium. RUN apt-get update -qq \
apt-get update -qq &&\ && apt-get upgrade -yqq \
apt-get upgrade -yqq &&\ && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium &&\
# Cleanup. # Cleanup.
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN \ # Install LibreOffice & unoconverter.
# Install LibreOffice & unoconverter. RUN echo "deb http://deb.debian.org/debian trixie-backports main" >> /etc/apt/sources.list \
echo "deb http://deb.debian.org/debian trixie-backports main" >> /etc/apt/sources.list &&\ && apt-get update -qq \
apt-get update -qq &&\ && apt-get upgrade -yqq \
apt-get upgrade -yqq &&\ && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
python3 python3-distutils-extra \ python3 python3-distutils-extra \
# Install Hyphenation for LibreOffice. # Install Hyphenation for LibreOffice.
# Credits: https://wiki.archlinux.org/title/LibreOffice. # Credits: https://wiki.archlinux.org/title/LibreOffice.
@@ -233,13 +227,13 @@ RUN \
hyphen-en-gb hyphen-en-us hyphen-eo hyphen-es hyphen-fr hyphen-gl hyphen-gu hyphen-hi hyphen-hr hyphen-hu \ hyphen-en-gb hyphen-en-us hyphen-eo hyphen-es hyphen-fr hyphen-gl hyphen-gu hyphen-hi hyphen-hr hyphen-hu \
hyphen-id hyphen-is hyphen-it hyphen-kn hyphen-lt hyphen-lv hyphen-ml hyphen-mn hyphen-mr hyphen-nl \ hyphen-id hyphen-is hyphen-it hyphen-kn hyphen-lt hyphen-lv hyphen-ml hyphen-mn hyphen-mr hyphen-nl \
hyphen-no hyphen-or hyphen-pa hyphen-pl hyphen-pt-br hyphen-pt-pt hyphen-ro hyphen-ru hyphen-sk hyphen-sl \ hyphen-no hyphen-or hyphen-pa hyphen-pl hyphen-pt-br hyphen-pt-pt hyphen-ro hyphen-ru hyphen-sk hyphen-sl \
hyphen-sr hyphen-sv hyphen-ta hyphen-te hyphen-th hyphen-uk hyphen-zu &&\ hyphen-sr hyphen-sv hyphen-ta hyphen-te hyphen-th hyphen-uk hyphen-zu \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends -t trixie-backports \ && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends -t trixie-backports \
libreoffice-writer libreoffice-calc libreoffice-impress libreoffice-draw python3-uno &&\ libreoffice-writer libreoffice-calc libreoffice-impress libreoffice-draw python3-uno \
# unoconverter will look for the Python binary, which has to be at version 3. # unoconverter 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 \
# Cleanup. # Cleanup.
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy unoconverter. # Copy unoconverter.
COPY --link --from=downloader-stage /downloads/unoconverter /usr/bin/unoconverter COPY --link --from=downloader-stage /downloads/unoconverter /usr/bin/unoconverter
@@ -281,13 +275,12 @@ LABEL org.opencontainers.image.title="Gotenberg (Chromium)" \
org.opencontainers.image.documentation="https://gotenberg.dev" \ org.opencontainers.image.documentation="https://gotenberg.dev" \
org.opencontainers.image.source="https://github.com/gotenberg/gotenberg" org.opencontainers.image.source="https://github.com/gotenberg/gotenberg"
RUN \ # Install Chromium.
# Install Chromium. RUN apt-get update -qq \
apt-get update -qq &&\ && apt-get upgrade -yqq \
apt-get upgrade -yqq &&\ && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium &&\
# Cleanup. # Cleanup.
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy dictionnaries so that hyphens work on Chromium. # Copy dictionnaries so that hyphens work on Chromium.
# See https://github.com/gotenberg/gotenberg/issues/1293. # See https://github.com/gotenberg/gotenberg/issues/1293.
@@ -322,12 +315,11 @@ LABEL org.opencontainers.image.title="Gotenberg (LibreOffice)" \
org.opencontainers.image.documentation="https://gotenberg.dev" \ org.opencontainers.image.documentation="https://gotenberg.dev" \
org.opencontainers.image.source="https://github.com/gotenberg/gotenberg" org.opencontainers.image.source="https://github.com/gotenberg/gotenberg"
RUN \ # Install LibreOffice & unoconverter.
# Install LibreOffice & unoconverter. RUN echo "deb http://deb.debian.org/debian trixie-backports main" >> /etc/apt/sources.list \
echo "deb http://deb.debian.org/debian trixie-backports main" >> /etc/apt/sources.list &&\ && apt-get update -qq \
apt-get update -qq &&\ && apt-get upgrade -yqq \
apt-get upgrade -yqq &&\ && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
python3 python3-distutils-extra \ python3 python3-distutils-extra \
# Install Hyphenation for LibreOffice. # Install Hyphenation for LibreOffice.
# Credits: https://wiki.archlinux.org/title/LibreOffice. # Credits: https://wiki.archlinux.org/title/LibreOffice.
@@ -335,13 +327,13 @@ RUN \
hyphen-en-gb hyphen-en-us hyphen-eo hyphen-es hyphen-fr hyphen-gl hyphen-gu hyphen-hi hyphen-hr hyphen-hu \ hyphen-en-gb hyphen-en-us hyphen-eo hyphen-es hyphen-fr hyphen-gl hyphen-gu hyphen-hi hyphen-hr hyphen-hu \
hyphen-id hyphen-is hyphen-it hyphen-kn hyphen-lt hyphen-lv hyphen-ml hyphen-mn hyphen-mr hyphen-nl \ hyphen-id hyphen-is hyphen-it hyphen-kn hyphen-lt hyphen-lv hyphen-ml hyphen-mn hyphen-mr hyphen-nl \
hyphen-no hyphen-or hyphen-pa hyphen-pl hyphen-pt-br hyphen-pt-pt hyphen-ro hyphen-ru hyphen-sk hyphen-sl \ hyphen-no hyphen-or hyphen-pa hyphen-pl hyphen-pt-br hyphen-pt-pt hyphen-ro hyphen-ru hyphen-sk hyphen-sl \
hyphen-sr hyphen-sv hyphen-ta hyphen-te hyphen-th hyphen-uk hyphen-zu &&\ hyphen-sr hyphen-sv hyphen-ta hyphen-te hyphen-th hyphen-uk hyphen-zu \
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends -t trixie-backports \ && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends -t trixie-backports \
libreoffice-writer libreoffice-calc libreoffice-impress libreoffice-draw python3-uno &&\ libreoffice-writer libreoffice-calc libreoffice-impress libreoffice-draw python3-uno \
# unoconverter will look for the Python binary, which has to be at version 3. # unoconverter 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 \
# Cleanup. # Cleanup.
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Copy unoconverter. # Copy unoconverter.
COPY --link --from=downloader-stage /downloads/unoconverter /usr/bin/unoconverter COPY --link --from=downloader-stage /downloads/unoconverter /usr/bin/unoconverter