From a5828fa01ab7581b564e04f36721bc771b043fef Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Fri, 27 Aug 2021 09:41:59 +0200 Subject: [PATCH] fix: add `--disable-gpu` flag to Chromium / chore: upgrade base image to bullseye (#331) --- .github/workflows/continuous_integration.yml | 2 +- Makefile | 2 +- build/Dockerfile | 8 ++--- pkg/modules/chromium/chromium.go | 10 ++++++- pkg/modules/chromium/debug.go | 31 ++++++++++++++++++++ pkg/modules/chromium/debug_test.go | 24 +++++++++++++++ 6 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 pkg/modules/chromium/debug.go create mode 100644 pkg/modules/chromium/debug_test.go diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index e130c413..cb5366c0 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -19,7 +19,7 @@ jobs: - name: Run linters uses: golangci/golangci-lint-action@v2 with: - version: v1.39 + version: v1.42 tests: needs: diff --git a/Makefile b/Makefile index 3d2203fb..6e6ff013 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ GOTENBERG_VERSION=snapshot GOTENBERG_USER_GID=1001 GOTENBERG_USER_UID=1001 PDFTK_VERSION=1353200058 # See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package. -GOLANGCI_LINT_VERSION=v1.39.0 # See https://github.com/golangci/golangci-lint/releases. +GOLANGCI_LINT_VERSION=v1.42.0 # See https://github.com/golangci/golangci-lint/releases. .PHONY: build build: ## Build the Gotenberg's Docker image diff --git a/build/Dockerfile b/build/Dockerfile index 47c74cd1..27237191 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -26,7 +26,7 @@ ARG GOTENBERG_VERSION RUN go build -o gotenberg -ldflags "-X 'github.com/gotenberg/gotenberg/v7/cmd.Version=$GOTENBERG_VERSION'" cmd/gotenberg/main.go -FROM debian:buster-slim +FROM debian:bullseye-slim ARG GOTENBERG_VERSION @@ -84,6 +84,7 @@ RUN \ fonts-telu \ fonts-thai-tlwg \ ttf-wqy-zenhei \ + fonts-arphic-ukai \ fonts-arphic-uming \ fonts-ipafont-mincho \ fonts-ipafont-gothic \ @@ -102,11 +103,8 @@ RUN \ fonts-sil-gentium \ fonts-sil-gentium-basic &&\ rm -f ./ttf-mscorefonts-installer_3.8_all.deb &&\ - echo "deb https://httpredir.debian.org/debian/ buster-backports main contrib non-free" >> /etc/apt/sources.list &&\ - apt-get update -qq &&\ # Install Chromium and LibreOffice. - DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium &&\ - DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends -t buster-backports libreoffice &&\ + DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends chromium libreoffice &&\ # Download unoconv (Python script). curl -Ls https://raw.githubusercontent.com/dagwieers/unoconv/master/unoconv -o /usr/bin/unoconv &&\ chmod +x /usr/bin/unoconv &&\ diff --git a/pkg/modules/chromium/chromium.go b/pkg/modules/chromium/chromium.go index 6b54d789..8ba3df69 100644 --- a/pkg/modules/chromium/chromium.go +++ b/pkg/modules/chromium/chromium.go @@ -257,12 +257,18 @@ func (mod Chromium) Routes() ([]api.MultipartFormDataRoute, error) { // drastically. In such a scenario, the given context may also be done before // the end of the conversion. func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath string, options Options) error { + debug := debugLogger{logger: logger.Named("chromium.debug")} userProfileDirPath := gotenberg.NewDirPath() args := append(chromedp.DefaultExecAllocatorOptions[:], + chromedp.CombinedOutput(debug), chromedp.ExecPath(mod.binPath), chromedp.NoSandbox, // See: + // https://github.com/gotenberg/gotenberg/issues/327 + // https://github.com/chromedp/chromedp/issues/904 + chromedp.DisableGPU, + // See: // https://github.com/puppeteer/puppeteer/issues/661 // https://github.com/puppeteer/puppeteer/issues/2410 chromedp.Flag("font-render-hinting", "none"), @@ -284,7 +290,9 @@ func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath allocatorCtx, cancel := chromedp.NewExecAllocator(ctx, args...) defer cancel() - taskCtx, cancel := chromedp.NewContext(allocatorCtx) + taskCtx, cancel := chromedp.NewContext(allocatorCtx, + chromedp.WithDebugf(debug.Printf), + ) defer cancel() // We validate the "main" URL against our allow / deny lists. diff --git a/pkg/modules/chromium/debug.go b/pkg/modules/chromium/debug.go new file mode 100644 index 00000000..8434238e --- /dev/null +++ b/pkg/modules/chromium/debug.go @@ -0,0 +1,31 @@ +package chromium + +import ( + "fmt" + "io" + + "go.uber.org/zap" +) + +// debugLogger is wrapper around a zap.Logger which is used for debugging +// Chromium. +type debugLogger struct { + logger *zap.Logger +} + +// Write logs the bytes in a debug message. +func (debug debugLogger) Write(p []byte) (n int, err error) { + debug.logger.Debug(string(p)) + + return len(p), nil +} + +// Printf logs a debug message. +func (debug debugLogger) Printf(format string, v ...interface{}) { + debug.logger.Debug(fmt.Sprintf(format, v...)) +} + +// Interface guards. +var ( + _ io.Writer = (*debugLogger)(nil) +) diff --git a/pkg/modules/chromium/debug_test.go b/pkg/modules/chromium/debug_test.go new file mode 100644 index 00000000..e373cc35 --- /dev/null +++ b/pkg/modules/chromium/debug_test.go @@ -0,0 +1,24 @@ +package chromium + +import ( + "testing" + + "go.uber.org/zap" +) + +func TestDebugLogger_Write(t *testing.T) { + actual, err := debugLogger{logger: zap.NewNop()}.Write([]byte("foo")) + expected := len([]byte("foo")) + + if actual != expected { + t.Errorf("expected %d but got %d", expected, actual) + } + + if err != nil { + t.Errorf("expected not error but got: %v", err) + } +} + +func TestDebugLogger_Printf(t *testing.T) { + debugLogger{logger: zap.NewNop()}.Printf("%s", "foo") +}