diff --git a/Makefile b/Makefile index d391354d..2b3c23b3 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ GOTENBERG_USER_GID=1001 GOTENBERG_USER_UID=1001 NOTO_COLOR_EMOJI_VERSION=v2.047 # See https://github.com/googlefonts/noto-emoji/releases. PDFTK_VERSION=v3.3.3 # See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package. +PDFCPU_VERSION=v0.8.1 # See https://github.com/pdfcpu/pdfcpu/releases. GOLANGCI_LINT_VERSION=v1.60.3 # See https://github.com/golangci/golangci-lint/releases. .PHONY: build @@ -24,6 +25,7 @@ build: ## Build the Gotenberg's Docker image --build-arg GOTENBERG_USER_UID=$(GOTENBERG_USER_UID) \ --build-arg NOTO_COLOR_EMOJI_VERSION=$(NOTO_COLOR_EMOJI_VERSION) \ --build-arg PDFTK_VERSION=$(PDFTK_VERSION) \ + --build-arg PDFCPU_VERSION=$(PDFCPU_VERSION) \ -t $(DOCKER_REGISTRY)/$(DOCKER_REPOSITORY):$(GOTENBERG_VERSION) \ -f build/Dockerfile . @@ -197,6 +199,7 @@ release: ## Build the Gotenberg's Docker image and push it to a Docker repositor $(GOTENBERG_USER_UID) \ $(NOTO_COLOR_EMOJI_VERSION) \ $(PDFTK_VERSION) \ + $(PDFCPU_VERSION) \ $(DOCKER_REGISTRY) \ $(DOCKER_REPOSITORY) \ $(LINUX_AMD64_RELEASE) diff --git a/build/Dockerfile b/build/Dockerfile index 133d6f8e..38771906 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -3,10 +3,35 @@ # stage that uses them. ARG GOLANG_VERSION +# ---------------------------------------------- +# pdfcpu binary build stage +# ---------------------------------------------- +# Note: this stage is required as pdfcpu does not release an armhf variant by +# default. + +FROM golang:$GOLANG_VERSION AS pdfcpu-binary-stage + +ARG PDFCPU_VERSION +ENV CGO_ENABLED=0 + +# Define the working directory outside of $GOPATH (we're using go modules). +WORKDIR /home + +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 + +# Install module dependencies. +RUN go mod download &&\ + 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 &&\ + # Verify installation. + ./pdfcpu version + # ---------------------------------------------- # Gotenberg binary build stage # ---------------------------------------------- -FROM golang:$GOLANG_VERSION AS binary-stage +FROM golang:$GOLANG_VERSION AS gotenberg-binary-stage ARG GOTENBERG_VERSION ENV CGO_ENABLED=0 @@ -187,8 +212,11 @@ RUN \ # https://github.com/arachnys/athenapdf/commit/ba25a8d80a25d08d58865519c4cd8756dc9a336d. COPY build/fonts.conf /etc/fonts/conf.d/100-gotenberg.conf -# Copy the Gotenberg binary from the binary stage. -COPY --from=binary-stage /home/gotenberg /usr/bin/ +# Copy the pdfcpu binary from the pdfcpu-binary-stage. +COPY --from=pdfcpu-binary-stage /home/pdfcpu /usr/bin/ + +# Copy the Gotenberg binary from the gotenberg-binary-stage. +COPY --from=gotenberg-binary-stage /home/gotenberg /usr/bin/ # Environment variables required by modules or else. ENV CHROMIUM_BIN_PATH=/usr/bin/chromium @@ -197,6 +225,7 @@ ENV UNOCONVERTER_BIN_PATH=/usr/bin/unoconverter ENV PDFTK_BIN_PATH=/usr/bin/pdftk ENV QPDF_BIN_PATH=/usr/bin/qpdf ENV EXIFTOOL_BIN_PATH=/usr/bin/exiftool +ENV PDFCPU_BIN_PATH=/usr/bin/pdfcpu USER gotenberg WORKDIR /home/gotenberg diff --git a/go.mod b/go.mod index 5a76a53a..cc3688e9 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,6 @@ require ( github.com/mholt/archiver/v3 v3.5.1 github.com/microcosm-cc/bluemonday v1.0.27 github.com/nwaples/rardecode v1.1.3 // indirect - github.com/pdfcpu/pdfcpu v0.8.1 github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/prometheus/client_golang v1.20.4 github.com/russross/blackfriday/v2 v2.1.0 @@ -29,7 +28,6 @@ require ( go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 golang.org/x/crypto v0.28.0 // indirect - golang.org/x/image v0.21.0 // indirect golang.org/x/net v0.30.0 golang.org/x/sync v0.8.0 golang.org/x/sys v0.26.0 // indirect @@ -50,22 +48,16 @@ require ( github.com/gobwas/ws v1.4.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/gorilla/css v1.0.1 // indirect - github.com/hhrutter/lzw v1.0.0 // indirect - github.com/hhrutter/tiff v1.0.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-runewidth v0.0.16 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect - github.com/rivo/uniseg v0.4.7 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect golang.org/x/time v0.7.0 // indirect google.golang.org/protobuf v1.34.2 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 84cf8271..0e058597 100644 --- a/go.sum +++ b/go.sum @@ -52,10 +52,6 @@ github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB1 github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= -github.com/hhrutter/lzw v1.0.0 h1:laL89Llp86W3rRs83LvKbwYRx6INE8gDn0XNb1oXtm0= -github.com/hhrutter/lzw v1.0.0/go.mod h1:2HC6DJSn/n6iAZfgM3Pg+cP1KxeWc3ezG8bBqW5+WEo= -github.com/hhrutter/tiff v1.0.1 h1:MIus8caHU5U6823gx7C6jrfoEvfSTGtEFRiM8/LOzC0= -github.com/hhrutter/tiff v1.0.1/go.mod h1:zU/dNgDm0cMIa8y8YwcYBeuEEveI4B0owqHyiPpJPHc= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= @@ -66,10 +62,6 @@ github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU= github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= @@ -85,8 +77,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= -github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mholt/archiver/v3 v3.5.1 h1:rDjOBX9JSF5BvoJGvjqK479aL70qh9DIpZCl+k7Clwo= github.com/mholt/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= @@ -98,13 +88,9 @@ github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9l github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw= github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0= -github.com/pdfcpu/pdfcpu v0.8.1 h1:AiWUb8uXlrXqJ73OmiYXBjDF0Qxt4OuM281eAfkAOMA= -github.com/pdfcpu/pdfcpu v0.8.1/go.mod h1:M5SFotxdaw0fedxthpjbA/PADytAo6wJnGH0SSBWJ7s= github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= @@ -115,11 +101,6 @@ github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJN github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= -github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -148,8 +129,6 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= -golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s= -golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78= golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= @@ -168,10 +147,5 @@ golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/modules/pdfcpu/doc.go b/pkg/modules/pdfcpu/doc.go index f98fdd1c..e68e2a61 100644 --- a/pkg/modules/pdfcpu/doc.go +++ b/pkg/modules/pdfcpu/doc.go @@ -1,5 +1,5 @@ // Package pdfcpu provides an implementation of the gotenberg.PdfEngine -// interface using the pdfcpu library. This package allows for: +// interface using the pdfcpu command-line tool. This package allows for: // // 1. The merging of PDF files. // diff --git a/pkg/modules/pdfcpu/pdfcpu.go b/pkg/modules/pdfcpu/pdfcpu.go index 18ad79ae..ac2d5358 100644 --- a/pkg/modules/pdfcpu/pdfcpu.go +++ b/pkg/modules/pdfcpu/pdfcpu.go @@ -2,11 +2,10 @@ package pdfcpu import ( "context" + "errors" "fmt" + "os" - pdfcpuAPI "github.com/pdfcpu/pdfcpu/pkg/api" - pdfcpuLog "github.com/pdfcpu/pdfcpu/pkg/log" - pdfcpuConfig "github.com/pdfcpu/pdfcpu/pkg/pdfcpu/model" "go.uber.org/zap" "github.com/gotenberg/gotenberg/v8/pkg/gotenberg" @@ -16,10 +15,10 @@ func init() { gotenberg.MustRegisterModule(new(PdfCpu)) } -// PdfCpu abstracts the pdfcpu library and implements the [gotenberg.PdfEngine] -// interface. +// PdfCpu abstracts the CLI tool pdfcpu and implements the +// [gotenberg.PdfEngine] interface. type PdfCpu struct { - conf *pdfcpuConfig.Configuration + binPath string } // Descriptor returns a [PdfCpu]'s module descriptor. @@ -32,16 +31,38 @@ func (engine *PdfCpu) Descriptor() gotenberg.ModuleDescriptor { // Provision sets the engine properties. func (engine *PdfCpu) Provision(ctx *gotenberg.Context) error { - pdfcpuConfig.ConfigPath = "disable" - pdfcpuLog.DisableLoggers() - engine.conf = pdfcpuConfig.NewDefaultConfiguration() + binPath, ok := os.LookupEnv("PDFCPU_BIN_PATH") + if !ok { + return errors.New("PDFCPU_BIN_PATH environment variable is not set") + } + + engine.binPath = binPath + + return nil +} + +// Validate validates the module properties. +func (engine *PdfCpu) Validate() error { + _, err := os.Stat(engine.binPath) + if os.IsNotExist(err) { + return fmt.Errorf("pdfcpu binary path does not exist: %w", err) + } return nil } // Merge combines multiple PDFs into a single PDF. func (engine *PdfCpu) Merge(ctx context.Context, logger *zap.Logger, inputPaths []string, outputPath string) error { - err := pdfcpuAPI.MergeCreateFile(inputPaths, outputPath, false, engine.conf) + var args []string + args = append(args, "merge", outputPath) + args = append(args, inputPaths...) + + cmd, err := gotenberg.CommandContext(ctx, logger, engine.binPath, args...) + if err != nil { + return fmt.Errorf("create command: %w", err) + } + + _, err = cmd.Exec() if err == nil { return nil } @@ -68,5 +89,6 @@ func (engine *PdfCpu) WriteMetadata(ctx context.Context, logger *zap.Logger, met var ( _ gotenberg.Module = (*PdfCpu)(nil) _ gotenberg.Provisioner = (*PdfCpu)(nil) + _ gotenberg.Validator = (*PdfCpu)(nil) _ gotenberg.PdfEngine = (*PdfCpu)(nil) ) diff --git a/pkg/modules/pdfcpu/pdfcpu_test.go b/pkg/modules/pdfcpu/pdfcpu_test.go index 6172fe2f..f009218a 100644 --- a/pkg/modules/pdfcpu/pdfcpu_test.go +++ b/pkg/modules/pdfcpu/pdfcpu_test.go @@ -33,14 +33,59 @@ func TestPdfCpu_Provision(t *testing.T) { } } +func TestPdfCpu_Validate(t *testing.T) { + for _, tc := range []struct { + scenario string + binPath string + expectError bool + }{ + { + scenario: "empty bin path", + binPath: "", + expectError: true, + }, + { + scenario: "bin path does not exist", + binPath: "/foo", + expectError: true, + }, + { + scenario: "validate success", + binPath: os.Getenv("PDFTK_BIN_PATH"), + expectError: false, + }, + } { + t.Run(tc.scenario, func(t *testing.T) { + engine := new(PdfCpu) + engine.binPath = tc.binPath + err := engine.Validate() + + if !tc.expectError && err != nil { + t.Fatalf("expected no error but got: %v", err) + } + + if tc.expectError && err == nil { + t.Fatal("expected error but got none") + } + }) + } +} + func TestPdfCpu_Merge(t *testing.T) { for _, tc := range []struct { scenario string + ctx context.Context inputPaths []string expectError bool }{ + { + scenario: "invalid context", + ctx: nil, + expectError: true, + }, { scenario: "invalid input path", + ctx: context.TODO(), inputPaths: []string{ "foo", }, @@ -48,6 +93,7 @@ func TestPdfCpu_Merge(t *testing.T) { }, { scenario: "single file success", + ctx: context.TODO(), inputPaths: []string{ "/tests/test/testdata/pdfengines/sample1.pdf", }, @@ -55,10 +101,12 @@ func TestPdfCpu_Merge(t *testing.T) { }, { scenario: "many files success", + ctx: context.TODO(), inputPaths: []string{ "/tests/test/testdata/pdfengines/sample1.pdf", "/tests/test/testdata/pdfengines/sample2.pdf", }, + expectError: false, }, } { t.Run(tc.scenario, func(t *testing.T) { @@ -81,7 +129,7 @@ func TestPdfCpu_Merge(t *testing.T) { } }() - err = engine.Merge(nil, nil, tc.inputPaths, outputDir+"/foo.pdf") + err = engine.Merge(tc.ctx, zap.NewNop(), tc.inputPaths, outputDir+"/foo.pdf") if !tc.expectError && err != nil { t.Fatalf("expected no error but got: %v", err) diff --git a/pkg/modules/pdftk/pdftk.go b/pkg/modules/pdftk/pdftk.go index 571b8016..9846ee9d 100644 --- a/pkg/modules/pdftk/pdftk.go +++ b/pkg/modules/pdftk/pdftk.go @@ -45,7 +45,7 @@ func (engine *PdfTk) Provision(ctx *gotenberg.Context) error { func (engine *PdfTk) Validate() error { _, err := os.Stat(engine.binPath) if os.IsNotExist(err) { - return fmt.Errorf("PdfTk binary path does not exist: %w", err) + return fmt.Errorf("PDFtk binary path does not exist: %w", err) } return nil diff --git a/pkg/modules/pdftk/pdftk_test.go b/pkg/modules/pdftk/pdftk_test.go index bdc0a508..c7b864ec 100644 --- a/pkg/modules/pdftk/pdftk_test.go +++ b/pkg/modules/pdftk/pdftk_test.go @@ -97,6 +97,7 @@ func TestPdfTk_Merge(t *testing.T) { inputPaths: []string{ "/tests/test/testdata/pdfengines/sample1.pdf", }, + expectError: false, }, { scenario: "many files success", @@ -105,6 +106,7 @@ func TestPdfTk_Merge(t *testing.T) { "/tests/test/testdata/pdfengines/sample1.pdf", "/tests/test/testdata/pdfengines/sample2.pdf", }, + expectError: false, }, } { t.Run(tc.scenario, func(t *testing.T) { diff --git a/pkg/modules/qpdf/qpdf_test.go b/pkg/modules/qpdf/qpdf_test.go index a17bafb5..a966928d 100644 --- a/pkg/modules/qpdf/qpdf_test.go +++ b/pkg/modules/qpdf/qpdf_test.go @@ -97,6 +97,7 @@ func TestQPdf_Merge(t *testing.T) { inputPaths: []string{ "/tests/test/testdata/pdfengines/sample1.pdf", }, + expectError: false, }, { scenario: "many files success", @@ -105,6 +106,7 @@ func TestQPdf_Merge(t *testing.T) { "/tests/test/testdata/pdfengines/sample1.pdf", "/tests/test/testdata/pdfengines/sample2.pdf", }, + expectError: false, }, } { t.Run(tc.scenario, func(t *testing.T) { diff --git a/scripts/release.sh b/scripts/release.sh index 1b56ce2f..e6303df7 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -9,9 +9,10 @@ GOTENBERG_USER_GID="$3" GOTENBERG_USER_UID="$4" NOTO_COLOR_EMOJI_VERSION="$5" PDFTK_VERSION="$6" -DOCKER_REGISTRY="$7" -DOCKER_REPOSITORY="$8" -LINUX_AMD64_RELEASE="$9" +PDFCPU_VERSION="$7" +DOCKER_REGISTRY="$8" +DOCKER_REPOSITORY="$9" +LINUX_AMD64_RELEASE="$10" # Find out if given version is "semver". GOTENBERG_VERSION="${GOTENBERG_VERSION//v}" @@ -65,6 +66,7 @@ docker buildx build \ --build-arg GOTENBERG_USER_UID="$GOTENBERG_USER_UID" \ --build-arg NOTO_COLOR_EMOJI_VERSION="$NOTO_COLOR_EMOJI_VERSION" \ --build-arg PDFTK_VERSION="$PDFTK_VERSION" \ + --build-arg PDFCPU_VERSION="$PDFCPU_VERSION" \ $PLATFORM_FLAG \ "${TAGS[@]}" \ --push \