mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 08:32:16 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5828fa01a | ||
|
|
662d3ff795 | ||
|
|
a97f05db3b |
2
.github/workflows/continuous_integration.yml
vendored
2
.github/workflows/continuous_integration.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: Run linters
|
- name: Run linters
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v2
|
||||||
with:
|
with:
|
||||||
version: v1.39
|
version: v1.42
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
needs:
|
needs:
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -11,7 +11,7 @@ GOTENBERG_VERSION=snapshot
|
|||||||
GOTENBERG_USER_GID=1001
|
GOTENBERG_USER_GID=1001
|
||||||
GOTENBERG_USER_UID=1001
|
GOTENBERG_USER_UID=1001
|
||||||
PDFTK_VERSION=1353200058 # See https://gitlab.com/pdftk-java/pdftk/-/releases - Binary package.
|
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
|
.PHONY: build
|
||||||
build: ## Build the Gotenberg's Docker image
|
build: ## Build the Gotenberg's Docker image
|
||||||
|
|||||||
@@ -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
|
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
|
ARG GOTENBERG_VERSION
|
||||||
|
|
||||||
@@ -84,6 +84,7 @@ RUN \
|
|||||||
fonts-telu \
|
fonts-telu \
|
||||||
fonts-thai-tlwg \
|
fonts-thai-tlwg \
|
||||||
ttf-wqy-zenhei \
|
ttf-wqy-zenhei \
|
||||||
|
fonts-arphic-ukai \
|
||||||
fonts-arphic-uming \
|
fonts-arphic-uming \
|
||||||
fonts-ipafont-mincho \
|
fonts-ipafont-mincho \
|
||||||
fonts-ipafont-gothic \
|
fonts-ipafont-gothic \
|
||||||
@@ -102,11 +103,8 @@ RUN \
|
|||||||
fonts-sil-gentium \
|
fonts-sil-gentium \
|
||||||
fonts-sil-gentium-basic &&\
|
fonts-sil-gentium-basic &&\
|
||||||
rm -f ./ttf-mscorefonts-installer_3.8_all.deb &&\
|
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.
|
# 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 chromium libreoffice &&\
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends -t buster-backports libreoffice &&\
|
|
||||||
# Download unoconv (Python script).
|
# 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 &&\
|
||||||
|
|||||||
@@ -382,11 +382,7 @@ func (a *API) Start() error {
|
|||||||
checks := append(a.healthChecks, health.WithTimeout(a.processTimeout))
|
checks := append(a.healthChecks, health.WithTimeout(a.processTimeout))
|
||||||
checker := health.NewChecker(checks...)
|
checker := health.NewChecker(checks...)
|
||||||
|
|
||||||
return func(echoCtx echo.Context) error {
|
return echo.WrapHandler(health.NewHandler(checker))
|
||||||
health.NewHandler(checker).ServeHTTP(echoCtx.Response().Writer, echoCtx.Request())
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}(),
|
}(),
|
||||||
timeoutMiddleware(hardTimeout),
|
timeoutMiddleware(hardTimeout),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -257,12 +257,18 @@ func (mod Chromium) Routes() ([]api.MultipartFormDataRoute, error) {
|
|||||||
// drastically. In such a scenario, the given context may also be done before
|
// drastically. In such a scenario, the given context may also be done before
|
||||||
// the end of the conversion.
|
// the end of the conversion.
|
||||||
func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath string, options Options) error {
|
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()
|
userProfileDirPath := gotenberg.NewDirPath()
|
||||||
|
|
||||||
args := append(chromedp.DefaultExecAllocatorOptions[:],
|
args := append(chromedp.DefaultExecAllocatorOptions[:],
|
||||||
|
chromedp.CombinedOutput(debug),
|
||||||
chromedp.ExecPath(mod.binPath),
|
chromedp.ExecPath(mod.binPath),
|
||||||
chromedp.NoSandbox,
|
chromedp.NoSandbox,
|
||||||
// See:
|
// 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/661
|
||||||
// https://github.com/puppeteer/puppeteer/issues/2410
|
// https://github.com/puppeteer/puppeteer/issues/2410
|
||||||
chromedp.Flag("font-render-hinting", "none"),
|
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...)
|
allocatorCtx, cancel := chromedp.NewExecAllocator(ctx, args...)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
taskCtx, cancel := chromedp.NewContext(allocatorCtx)
|
taskCtx, cancel := chromedp.NewContext(allocatorCtx,
|
||||||
|
chromedp.WithDebugf(debug.Printf),
|
||||||
|
)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// We validate the "main" URL against our allow / deny lists.
|
// We validate the "main" URL against our allow / deny lists.
|
||||||
|
|||||||
31
pkg/modules/chromium/debug.go
Normal file
31
pkg/modules/chromium/debug.go
Normal file
@@ -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)
|
||||||
|
)
|
||||||
24
pkg/modules/chromium/debug_test.go
Normal file
24
pkg/modules/chromium/debug_test.go
Normal file
@@ -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")
|
||||||
|
}
|
||||||
@@ -432,6 +432,29 @@ func TestConvertMarkdownHandler(t *testing.T) {
|
|||||||
outputDir: "/tmp/foo",
|
outputDir: "/tmp/foo",
|
||||||
expectOutputPathsCount: 1,
|
expectOutputPathsCount: 1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ctx: func() *api.MockContext {
|
||||||
|
ctx := &api.MockContext{Context: &api.Context{}}
|
||||||
|
|
||||||
|
ctx.SetDirPath("/tmp/foo")
|
||||||
|
ctx.SetFiles(map[string]string{
|
||||||
|
"index.html": "/tests/test/testdata/chromium/markdown/sample3/index.html",
|
||||||
|
"markdown1.md": "/tests/test/testdata/chromium/markdown/sample3/markdown.md",
|
||||||
|
})
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
}(),
|
||||||
|
api: func() API {
|
||||||
|
chromiumAPI := struct{ ProtoAPI }{}
|
||||||
|
chromiumAPI.pdf = func(_ context.Context, _ *zap.Logger, _, _ string, _ Options) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return chromiumAPI
|
||||||
|
}(),
|
||||||
|
outputDir: "/tmp/foo",
|
||||||
|
expectOutputPathsCount: 1,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
func() {
|
func() {
|
||||||
if tc.outputDir != "" {
|
if tc.outputDir != "" {
|
||||||
|
|||||||
18
test/testdata/chromium/markdown/sample3/index.html
vendored
Normal file
18
test/testdata/chromium/markdown/sample3/index.html
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Gutenberg</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Table in markdown</h1>
|
||||||
|
|
||||||
|
<h2>toHTML</h2>
|
||||||
|
{{ toHTML "markdown.md" }}
|
||||||
|
|
||||||
|
<h2>Actual HTML</h2>
|
||||||
|
<textarea readonly="readonly" cols="100" rows="50">
|
||||||
|
{{ toHTML "markdown.md" }}
|
||||||
|
</textarea>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
5
test/testdata/chromium/markdown/sample3/markdown.md
vendored
Normal file
5
test/testdata/chromium/markdown/sample3/markdown.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
| Tables | Are | Cool |
|
||||||
|
|----------|:-------------:|------:|
|
||||||
|
| col 1 is | left-aligned | $1600 |
|
||||||
|
| col 2 is | centered | $12 |
|
||||||
|
| col 3 is | right-aligned | $1 |
|
||||||
Reference in New Issue
Block a user