diff --git a/README.md b/README.md
index 344cd160..efd6c62c 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ At TheCodingMachine, we build a lot of web applications (intranets, extranets an
* HTML and Markdown conversions using Google Chrome headless
* Office conversions (.txt, .rtf, .docx, .doc, .odt, .pptx, .ppt, .odp and so on) using [unoconv](https://github.com/dagwieers/unoconv)
-* Performance :zap:: Google Chrome and Libreoffice (unoconv) started once in the background thanks to PM2
+* Performance :zap:: Google Chrome and LibreOffice (unoconv) started once in the background thanks to PM2
* Failure prevention :broken_heart:: PM2 automatically restarts previous processes if they fail
* Assets :package:: send your header, footer, images, fonts, stylesheets and so on for converting your HTML and Markdown to beaufitul PDFs!
* Easily interact with the API using our [Go](https://github.com/thecodingmachine/gotenberg-go-client) and [PHP](https://github.com/thecodingmachine/gotenberg-php-client) libraries
@@ -23,7 +23,7 @@ At TheCodingMachine, we build a lot of web applications (intranets, extranets an
Open a terminal and run the following command:
```bash
-$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:4
+$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:5
```
The API is now available on your host at `http://localhost:3000`.
@@ -33,7 +33,7 @@ to learn how to interact with it!
## Badges
-[](https://microbadger.com/images/thecodingmachine/gotenberg:4)
+[](https://microbadger.com/images/thecodingmachine/gotenberg:5)
[](https://travis-ci.org/thecodingmachine/gotenberg)
[](https://godoc.org/github.com/thecodingmachine/gotenberg)
[](https://goreportcard.com/report/thecodingmachine/gotenberg)
diff --git a/build/base/Dockerfile b/build/base/Dockerfile
index 202b1b3b..c8cb8e94 100644
--- a/build/base/Dockerfile
+++ b/build/base/Dockerfile
@@ -20,7 +20,7 @@ RUN echo "deb http://httpredir.debian.org/debian/ stretch main contrib non-free"
# | recovering. In our case: Chrome (headless) and Office (headless).
# |
-# Yep, this is dirty. The following script does not work anymore (see https://github.com/Unitech/pm2/issues/4127).
+# Yep, this is dirty. The following script does not work anymore (see https://github.com/Unitech/pm2/issues/4127):
#RUN curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | bash -
# Installing PM2 with Node.js and npm breaks something which prevents Google Chrome to work as expected.
@@ -38,19 +38,19 @@ COPY --from=hack /etc/systemd/system/pm2.service /etc/systemd/system/pm2.service
# | Chrome
# |--------------------------------------------------------------------------
# |
-# | Installs Chrome for HTML and Markdown conversions.
+# | Installs Chrome.
# |
RUN wget -q -O - 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 &&\
- apt-get -y install google-chrome-stable
+ apt-get -y --allow-unauthenticated install google-chrome-stable
# |--------------------------------------------------------------------------
# | Unoconv
# |--------------------------------------------------------------------------
# |
-# | Installs unoconv and LibreOffice for Office documents conversions.
+# | Installs unoconv and LibreOffice.
# |
RUN pip3 install unoconv &&\
diff --git a/build/docs/content/00-introduction.md b/build/docs/content/00-introduction.md
index 64fa9931..ac1bf49a 100644
--- a/build/docs/content/00-introduction.md
+++ b/build/docs/content/00-introduction.md
@@ -6,7 +6,7 @@ title: Introduction
* HTML and Markdown conversions using Google Chrome headless
* Office conversions (.txt, .rtf, .docx, .doc, .odt, .pptx, .ppt, .odp and so on) using [unoconv](https://github.com/dagwieers/unoconv)
-* Performance: Google Chrome and Libreoffice (unoconv) started once in the background thanks to PM2
+* Performance: Google Chrome and LibreOffice (unoconv) started once in the background thanks to PM2
* Failure prevention: PM2 automatically restarts previous processes if they fail
* Assets: send your header, footer, images, fonts, stylesheets and so on for converting your HTML and Markdown to beaufitul PDFs!
* Easily interact with the API using our [Go](https://github.com/thecodingmachine/gotenberg-go-client) and [PHP](https://github.com/thecodingmachine/gotenberg-php-client) libraries
\ No newline at end of file
diff --git a/build/docs/content/01-install.md b/build/docs/content/01-install.md
index 89c05589..03585a66 100644
--- a/build/docs/content/01-install.md
+++ b/build/docs/content/01-install.md
@@ -7,12 +7,14 @@ Gotenberg is shipped within a Docker image.
You may start it with:
```bash
-$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:4
+$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:5
```
> The API will be available at [http://localhost:3000](http://localhost:3000).
-Or add it in your Docker Compose stack:
+## Docker Compose
+
+You may also add it in your Docker Compose stack:
```yaml
version: '3'
@@ -22,37 +24,19 @@ services:
# your others services
gotenberg:
- image: thecodingmachine/gotenberg:4
+ image: thecodingmachine/gotenberg:5
```
> The API will be available under `gotenberg:3000` in your Docker Compose network.
+## Kubernetes
+
It may also be deployed with Kubernetes.
-> In Kubernetes, make sure to provide enough memory and CPU requests (for instance `512Mi` and `0.2` CPU).
-> Otherwise the API will not be able to launch Google Chrome and Libreoffice (unoconv).
->
-> Also note the more resources are granted, the quicker will be the conversions.
+Make sure to provide enough memory and CPU requests (for instance `512Mi` and `0.2` CPU).
+Otherwise the API will not be able to launch Google Chrome and LibreOffice (unoconv).
+
+> The more resources are granted, the quicker will be the conversions.
In the following examples, we will assume your
-Gotenberg API is available at [http://localhost:3000](http://localhost:3000).
-
-## Go client
-
-```bash
-$ go get -u github.com/thecodingmachine/gotenberg-go-client/v4
-```
-
-## PHP client
-
-Unless your project already has a PSR7 `HttpClient`, install `php-http/guzzle6-adapter`:
-
-```bash
-$ composer require php-http/guzzle6-adapter
-```
-
-Then the PHP client:
-
-```bash
-$ composer require thecodingmachine/gotenberg-php-client
-```
\ No newline at end of file
+Gotenberg API is available at [http://localhost:3000](http://localhost:3000).
\ No newline at end of file
diff --git a/build/docs/content/02-clients.md b/build/docs/content/02-clients.md
new file mode 100644
index 00000000..195fb85d
--- /dev/null
+++ b/build/docs/content/02-clients.md
@@ -0,0 +1,25 @@
+---
+title: Clients
+---
+
+We provide clients in various languages for easing the interactions with the API.
+
+## Go client
+
+```bash
+$ go get -u github.com/thecodingmachine/gotenberg-go-client/v5
+```
+
+## PHP client
+
+Unless your project already has a PSR7 `HttpClient`, install `php-http/guzzle6-adapter`:
+
+```bash
+$ composer require php-http/guzzle6-adapter
+```
+
+Then the PHP client:
+
+```bash
+$ composer require thecodingmachine/gotenberg-php-client
+```
\ No newline at end of file
diff --git a/build/docs/content/03-environment-variables.md b/build/docs/content/03-environment-variables.md
new file mode 100644
index 00000000..1a915e04
--- /dev/null
+++ b/build/docs/content/03-environment-variables.md
@@ -0,0 +1,33 @@
+---
+title: Environment variables
+---
+
+You may customize the API behaviour thanks to environment variables.
+
+## Disable Google Chrome
+
+In order to save some resources, the Gotenberg image accepts the environment variable `DISABLE_GOOGLE_CHROME`.
+
+It takes the strings `"0"` or `"1"` as value.
+
+> If Google Chrome is disabled, the following conversions will **not** be available anymore:
+> [HTML](#html), [URL](#url) and [Markdown](#markdown)
+
+
+## Disable LibreOffice (unoconv)
+
+You may also disable LibreOffice (unoconv) with `DISABLE_UNOCONV`.
+
+> If LibreOffice (unoconv) is disabled, the following conversion will **not** be available anymore:
+> [Office](#office)
+
+## Default wait timeout
+
+By default, the API will wait 10 seconds before it considers the conversion to be unsuccessful.
+
+You may customize this timeout thanks to the environment variable `DEFAULT_WAIT_TIMEOUT`.
+
+It takes a string representation of a float as value (e.g `"2.5"` for 2.5 seconds).
+
+> The default timeout may also be overridden per request thanks to the form field `waitTimeout`.
+> See the [timeout section](#timeout).
\ No newline at end of file
diff --git a/build/docs/content/02-html.md b/build/docs/content/04-html.md
similarity index 79%
rename from build/docs/content/02-html.md
rename to build/docs/content/04-html.md
index ad32f051..b2661e3c 100644
--- a/build/docs/content/02-html.md
+++ b/build/docs/content/04-html.md
@@ -39,7 +39,7 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
@@ -113,13 +113,13 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
req, _ := gotenberg.NewHTMLRequest("index.html")
- req.SetHeader("header.html")
- req.SetFooter("footer.html")
+ req.Header("header.html")
+ req.Footer("footer.html")
dest := "result.pdf"
c.Store(req, dest)
}
@@ -186,9 +186,6 @@ You may also use *remote* paths for Google fonts, images and so on.
> If you want to install fonts directly in the Gotenberg Docker image,
> see to the [fonts section](#fonts).
->
-> For web fonts (Google fonts), there is a timeout of 500ms by default. You may update
-> this value thanks to the form field `webFontsTimeout`.
### cURL
@@ -206,12 +203,12 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
req, _ := gotenberg.NewHTMLRequest("index.html")
- req.SetAssets("font.woff", "img.gif", "style.css")
+ req.Assets("font.woff", "img.gif", "style.css")
dest := "result.pdf"
c.Store(req, dest)
}
@@ -243,8 +240,7 @@ You may also customize the resulting PDF format.
By default, it will be rendered with `A4` size, `1 inch` margins and `portrait` orientation.
-> Paper size and margins have to be provided in `inches`.
-> Also, you have to set both `paperWidth` and `paperHeight`. Same for margins.
+> Paper size and margins have to be provided in `inches`. Same for margins.
### cURL
@@ -266,14 +262,14 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
req, _ := gotenberg.NewHTMLRequest("index.html")
- req.SetPaperSize(gotenberg.A4)
- req.SetMargins(gotenberg.NoMargins)
- req.SetLandscape(true)
+ req.PaperSize(gotenberg.A4)
+ req.Margins(gotenberg.NoMargins)
+ req.Landscape(true)
dest := "result.pdf"
c.Store(req, dest)
}
@@ -295,4 +291,52 @@ $request->setMargins(Request::NO_MARGINS);
$request->setLandscape(true);
$dest = "result.pdf";
$client->store($request, $dest);
+```
+
+## Wait delay
+
+In some cases, you may want to wait a certain amount of time to make sure the
+page you're trying to generate is fully rendered.
+
+> The wait delay is a duration in **seconds** (e.g `2.5` for 2.5 seconds).
+
+### cURL
+
+```bash
+$ curl --request POST \
+ --url http://localhost:3000/convert/html \
+ --header 'Content-Type: multipart/form-data' \
+ --form files=@index.html \
+ --form waitDelay=5.5 \
+ -o result.pdf
+```
+
+### Go
+
+```golang
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
+
+func main() {
+ c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+ req, _ := gotenberg.NewHTMLRequest("index.html")
+ req.WaitDelay(5.5)
+ dest := "result.pdf"
+ c.Store(req, dest)
+}
+```
+
+### PHP
+
+```php
+use TheCodingMachine\Gotenberg\Client;
+use TheCodingMachine\Gotenberg\DocumentFactory;
+use TheCodingMachine\Gotenberg\HTMLRequest;
+use TheCodingMachine\Gotenberg\Request;
+
+$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client());
+$index = DocumentFactory::makeFromPath('index.html', 'index.html');
+$request = new HTMLRequest($index);
+$request->setWaitDelay(5.5);
+$dest = "result.pdf";
+$client->store($request, $dest);
```
\ No newline at end of file
diff --git a/build/docs/content/03-url.md b/build/docs/content/05-url.md
similarity index 93%
rename from build/docs/content/03-url.md
rename to build/docs/content/05-url.md
index 5f11c399..a26db834 100644
--- a/build/docs/content/03-url.md
+++ b/build/docs/content/05-url.md
@@ -31,12 +31,12 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
req := gotenberg.NewURLRequest("https://google.com")
- req.SetMargins(gotenberg.NoMargins)
+ req.Margins(gotenberg.NoMargins)
dest := "result.pdf"
c.Store(req, dest)
}
diff --git a/build/docs/content/04-markdown.md b/build/docs/content/06-markdown.md
similarity index 96%
rename from build/docs/content/04-markdown.md
rename to build/docs/content/06-markdown.md
index cef48003..1dadb7c5 100644
--- a/build/docs/content/04-markdown.md
+++ b/build/docs/content/06-markdown.md
@@ -42,7 +42,7 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
diff --git a/build/docs/content/05-office.md b/build/docs/content/07-office.md
similarity index 94%
rename from build/docs/content/05-office.md
rename to build/docs/content/07-office.md
index 9d2258b2..b17b8146 100644
--- a/build/docs/content/05-office.md
+++ b/build/docs/content/07-office.md
@@ -43,7 +43,7 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
@@ -90,12 +90,12 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
req, _ := gotenberg.NewOfficeRequest("document.docx")
- req.SetLandscape(true)
+ req.Landscape(true)
dest := "result.pdf"
c.Store(req, dest)
}
diff --git a/build/docs/content/08-filename.md b/build/docs/content/08-filename.md
deleted file mode 100644
index 22ee347c..00000000
--- a/build/docs/content/08-filename.md
+++ /dev/null
@@ -1,14 +0,0 @@
----
-title: Filename
----
-
-All endpoints accept a form field named `filename`.
-
-If provided, the API will return the resulting PDF file with the given filename.
-Otherwise a random filename is used.
-
-> The Go and PHP libraries do not provide a way to set this form field.
-> However, you may hijack the response from the API or store the resulting PDF
-> using a custom filename.
->
-> **Attention:** this feature does not work if the form field `webhookURL` is given.
\ No newline at end of file
diff --git a/build/docs/content/06-merge.md b/build/docs/content/08-merge.md
similarity index 86%
rename from build/docs/content/06-merge.md
rename to build/docs/content/08-merge.md
index 6099a85b..3b8b7dfc 100644
--- a/build/docs/content/06-merge.md
+++ b/build/docs/content/08-merge.md
@@ -2,7 +2,7 @@
title: Merge
---
-Gotenberg provides the endpoint `/merge` for merging PDFs.
+Gotenberg provides the endpoint `/convert/merge` for merging PDFs.
It accepts `POST` requests with a `multipart/form-data` Content-Type.
@@ -17,7 +17,7 @@ will merge them and return the resulting PDF file.
```bash
$ curl --request POST \
- --url http://localhost:3000/merge \
+ --url http://localhost:3000/convert/merge \
--header 'Content-Type: multipart/form-data' \
--form files=@file.pdf \
--form files=@file2.pdf \
@@ -27,7 +27,7 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
diff --git a/build/docs/content/09-timeout.md b/build/docs/content/09-timeout.md
new file mode 100644
index 00000000..92c78b83
--- /dev/null
+++ b/build/docs/content/09-timeout.md
@@ -0,0 +1,52 @@
+---
+title: Timeout
+---
+
+All endpoints accept a form field named `waitTimeout`.
+
+The API will wait the given **seconds** before it considers the conversion to be unsucessful.
+
+It takes a float as value (e.g `2.5` for 2.5 seconds).
+
+> You may also define this value globally: see the [environment variables](#environment_variables.default_wait_timeout) section.
+
+## Examples
+
+### cURL
+
+```bash
+$ curl --request POST \
+ --url http://localhost:3000/convert/html \
+ --header 'Content-Type: multipart/form-data' \
+ --form files=@index.html \
+ --form waitTimeout=2.5
+```
+
+### Go
+
+```golang
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
+
+func main() {
+ c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+ req, _ := gotenberg.NewHTMLRequest("index.html")
+ req.WaitTimeout(2.5)
+ resp, _ := c.Post(req)
+}
+```
+
+### PHP
+
+```php
+use TheCodingMachine\Gotenberg\Client;
+use TheCodingMachine\Gotenberg\DocumentFactory;
+use TheCodingMachine\Gotenberg\HTMLRequest;
+use TheCodingMachine\Gotenberg\Request;
+
+$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client());
+$index = DocumentFactory::makeFromPath('index.html', 'index.html');
+$request = new HTMLRequest($index);
+$request->setWaitTimeout(2.5);
+$dest = "result.pdf";
+$client->store($request, $dest);
+```
\ No newline at end of file
diff --git a/build/docs/content/07-webhook.md b/build/docs/content/10-webhook.md
similarity index 89%
rename from build/docs/content/07-webhook.md
rename to build/docs/content/10-webhook.md
index ca00be45..497baaca 100644
--- a/build/docs/content/07-webhook.md
+++ b/build/docs/content/10-webhook.md
@@ -24,13 +24,12 @@ $ curl --request POST \
### Go
```golang
-import "github.com/thecodingmachine/gotenberg-go-client/v4"
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
func main() {
c := &gotenberg.Client{Hostname: "http://localhost:3000"}
req, _ := gotenberg.NewHTMLRequest("index.html")
- req.SetWebhookURL("http://myapp.com/webhook/")
- dest := "result.pdf"
+ req.WebhookURL("http://myapp.com/webhook/")
resp, _ := c.Post(req)
}
```
diff --git a/build/docs/content/11-result-filename.md b/build/docs/content/11-result-filename.md
new file mode 100644
index 00000000..22f2c184
--- /dev/null
+++ b/build/docs/content/11-result-filename.md
@@ -0,0 +1,50 @@
+---
+title: Result filename
+---
+
+All endpoints accept a form field named `resultFilename`.
+
+If provided, the API will return the resulting PDF file with the given filename.
+Otherwise a random filename is used.
+
+> **Attention:** this feature does not work if the form field `webhookURL` is given.
+
+## Examples
+
+### cURL
+
+```bash
+$ curl --request POST \
+ --url http://localhost:3000/convert/html \
+ --header 'Content-Type: multipart/form-data' \
+ --form files=@index.html \
+ --form resultFilename='foo.pdf'
+```
+
+### Go
+
+```golang
+import "github.com/thecodingmachine/gotenberg-go-client/v5"
+
+func main() {
+ c := &gotenberg.Client{Hostname: "http://localhost:3000"}
+ req, _ := gotenberg.NewHTMLRequest("index.html")
+ req.ResultFilename("foo.pdf")
+ resp, _ := c.Post(req)
+}
+```
+
+### PHP
+
+```php
+use TheCodingMachine\Gotenberg\Client;
+use TheCodingMachine\Gotenberg\DocumentFactory;
+use TheCodingMachine\Gotenberg\HTMLRequest;
+use TheCodingMachine\Gotenberg\Request;
+
+$client = new Client('http://localhost:3000', new \Http\Adapter\Guzzle6\Client());
+$index = DocumentFactory::makeFromPath('index.html', 'index.html');
+$request = new HTMLRequest($index);
+$request->setResultFilename('foo.pdf');
+$resp = $client->post($request);
+```
\ No newline at end of file
diff --git a/build/docs/content/09-scalability.md b/build/docs/content/12-scalability.md
similarity index 92%
rename from build/docs/content/09-scalability.md
rename to build/docs/content/12-scalability.md
index 906cc6dd..e5d1225f 100644
--- a/build/docs/content/09-scalability.md
+++ b/build/docs/content/12-scalability.md
@@ -14,7 +14,7 @@ services:
# your others services
gotenberg:
- image: thecodingmachine/gotenberg:4
+ image: thecodingmachine/gotenberg:5
```
You may now launch your services using:
diff --git a/build/docs/content/10-liveness.md b/build/docs/content/13-ping.md
similarity index 96%
rename from build/docs/content/10-liveness.md
rename to build/docs/content/13-ping.md
index 5da45771..3222cf55 100644
--- a/build/docs/content/10-liveness.md
+++ b/build/docs/content/13-ping.md
@@ -1,5 +1,5 @@
---
-title: Liveness
+title: Ping
---
Gotenberg provides the endpoint `/ping` for checking the API availability with
diff --git a/build/docs/content/11-fonts.md b/build/docs/content/14-fonts.md
similarity index 87%
rename from build/docs/content/11-fonts.md
rename to build/docs/content/14-fonts.md
index daa7e040..fa120864 100644
--- a/build/docs/content/11-fonts.md
+++ b/build/docs/content/14-fonts.md
@@ -7,7 +7,7 @@ By default, a handful of fonts are installed. Asian characters are also supporte
If you wish to use more fonts, you will have to create your own image:
```Dockerfile
-FROM thecodingmachine/gotenberg:4
+FROM thecodingmachine/gotenberg:5
RUN apt-get -y install yourfonts
```
\ No newline at end of file
diff --git a/build/docs/content/12-links.md b/build/docs/content/15-links.md
similarity index 100%
rename from build/docs/content/12-links.md
rename to build/docs/content/15-links.md
diff --git a/build/lint/Dockerfile b/build/lint/Dockerfile
index ce0fb562..869447e6 100644
--- a/build/lint/Dockerfile
+++ b/build/lint/Dockerfile
@@ -10,7 +10,7 @@ FROM golang:${GOLANG_VERSION}-stretch
# | than gometalinter.
# |
-ENV GOLANGCI_LINT_VERSION 1.15.0
+ENV GOLANGCI_LINT_VERSION 1.16.0
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b /usr/local/bin v${GOLANGCI_LINT_VERSION} &&\
golangci-lint --version
@@ -32,4 +32,4 @@ COPY go.sum .
# Install module dependencies.
RUN go mod download
-CMD ["golangci-lint", "run" ,"--tests=false", "--enable-all", "--disable=dupl", "--disable=lll", "--disable=errcheck", "--disable=gosec", "--disable=gochecknoglobals", "--disable=gochecknoinits" ]
\ No newline at end of file
+CMD ["golangci-lint", "run" ,"--tests=false", "--enable-all", "--disable=dupl" ]
\ No newline at end of file
diff --git a/build/tests/docker-entrypoint.sh b/build/tests/docker-entrypoint.sh
index f76c5367..fa2f311a 100755
--- a/build/tests/docker-entrypoint.sh
+++ b/build/tests/docker-entrypoint.sh
@@ -5,12 +5,11 @@ set -xe
# Testing PM2 processes launch separatly for avoiding
# spending to much time on each tests depending on
# them.
-go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestChromeLaunch
-go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestUnoconvLaunch
+go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestChromeStart
+go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestUnoconvStart
# Running others tests.
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/app/api
-go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/pkg/printer
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/pkg/rand
# Finally testing processes shutdown.
diff --git a/cmd/gotenberg/main.go b/cmd/gotenberg/main.go
index c978aa3c..f3a9cf9f 100644
--- a/cmd/gotenberg/main.go
+++ b/cmd/gotenberg/main.go
@@ -1,21 +1,125 @@
package main
import (
+ "context"
"fmt"
+ "net/http"
"os"
+ "os/signal"
+ "strconv"
+ "time"
+ "github.com/labstack/echo/v4"
"github.com/thecodingmachine/gotenberg/internal/app/api"
"github.com/thecodingmachine/gotenberg/internal/pkg/notify"
+ "github.com/thecodingmachine/gotenberg/internal/pkg/pm2"
)
// version will be set on build time.
+// nolint: gochecknoglobals
var version = "snapshot"
-func main() {
- notify.Println(fmt.Sprintf("Gotenberg %s", version))
- if err := api.Start(); err != nil {
- notify.ErrPrintln(err)
+const (
+ defaultWaitTimeoutEnvVar = "DEFAULT_WAIT_TIMEOUT"
+ disableGoogleChromeEnvVar = "DISABLE_GOOGLE_CHROME"
+ disableUnoconvEnvVar = "DISABLE_UNOCONV"
+)
+
+func mustParseEnvVar() *api.Options {
+ opts := api.DefaultOptions()
+ if os.Getenv(defaultWaitTimeoutEnvVar) != "" {
+ defaultWaitTimeout, err := strconv.ParseFloat(os.Getenv(defaultWaitTimeoutEnvVar), 64)
+ if err != nil {
+ notify.ErrPrint(fmt.Errorf("%s: wrong value: want float got %v", defaultWaitTimeoutEnvVar, err))
+ os.Exit(1)
+ }
+ opts.DefaultWaitTimeout = defaultWaitTimeout
+ }
+ if v, ok := os.LookupEnv(disableGoogleChromeEnvVar); ok {
+ if v != "1" && v != "0" {
+ notify.ErrPrint(fmt.Errorf("%s: wrong value: want \"0\" or \"1\" got %v", defaultWaitTimeoutEnvVar, v))
+ os.Exit(1)
+ }
+ opts.EnableChromeEndpoints = v != "1"
+ }
+ if v, ok := os.LookupEnv(disableUnoconvEnvVar); ok {
+ if v != "1" && v != "0" {
+ notify.ErrPrint(fmt.Errorf("%s: wrong value: want \"0\" or \"1\" got %v", disableUnoconvEnvVar, v))
+ os.Exit(1)
+ }
+ opts.EnableUnoconvEndpoints = v != "1"
+ }
+ return opts
+}
+
+func mustStartProcesses(opts *api.Options) []pm2.Process {
+ var processes []pm2.Process
+ if opts.EnableChromeEndpoints {
+ processes = append(processes, pm2.NewChrome())
+ }
+ if opts.EnableUnoconvEndpoints {
+ processes = append(processes, pm2.NewUnoconv())
+ }
+ for _, p := range processes {
+ notify.Printf("starting %s with PM2...", p.Fullname())
+ if err := p.Start(); err != nil {
+ notify.ErrPrint(err)
+ os.Exit(1)
+ }
+ }
+ return processes
+}
+
+func mustStartAPI(srv *echo.Echo) {
+ notify.Print("http server started on port 3000")
+ if err := srv.Start(":3000"); err != nil {
+ if err != http.ErrServerClosed {
+ notify.ErrPrint(err)
+ os.Exit(1)
+ }
+ }
+}
+
+func mustShutdownProcesses(processes []pm2.Process) {
+ for _, p := range processes {
+ notify.Printf("shutting down %s with PM2... (Ctrl+C to force)", p.Fullname())
+ if err := p.Shutdown(); err != nil {
+ notify.ErrPrint(err)
+ os.Exit(1)
+ }
+ }
+}
+
+func mustShutdownAPI(srv *echo.Echo) {
+ // create a deadline to wait for.
+ ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
+ defer cancel()
+ // doesn't block if no connections, but will otherwise wait
+ // until the timeout deadline.
+ notify.Print("shutting down http server... (Ctrl+C to force)")
+ if err := srv.Shutdown(ctx); err != nil {
+ notify.ErrPrint(err)
os.Exit(1)
}
+}
+
+func main() {
+ notify.Printf("Gotenberg %s", version)
+ opts := mustParseEnvVar()
+ srv := api.New(opts)
+ processes := mustStartProcesses(opts)
+ // run our API in a goroutine so that it doesn't block.s
+ go func() {
+ mustStartAPI(srv)
+ }()
+ quit := make(chan os.Signal, 1)
+ // we'll accept graceful shutdowns when quit via SIGINT (Ctrl+C)
+ // SIGKILL, SIGQUIT or SIGTERM (Ctrl+/) will not be caught.
+ signal.Notify(quit, os.Interrupt)
+ // block until we receive our signal.
+ <-quit
+ mustShutdownAPI(srv)
+ mustShutdownProcesses(processes)
+ notify.Print("bye!")
os.Exit(0)
}
diff --git a/docs/index.html b/docs/index.html
index 1593a94a..114bbd93 100755
--- a/docs/index.html
+++ b/docs/index.html
@@ -50,6 +50,14 @@
Install
+
In Kubernetes, make sure to provide enough memory and CPU requests (for instance 512Mi and 0.2 CPU).
-Otherwise the API will not be able to launch Google Chrome and Libreoffice (unoconv).
+
Make sure to provide enough memory and CPU requests (for instance 512Mi and 0.2 CPU).
+Otherwise the API will not be able to launch Google Chrome and LibreOffice (unoconv).
-
Also note the more resources are granted, the quicker will be the conversions.
+
+
The more resources are granted, the quicker will be the conversions.
In the following examples, we will assume your
Gotenberg API is available at http://localhost:3000.
import"github.com/thecodingmachine/gotenberg-go-client/v5"funcmain(){c:=&gotenberg.Client{Hostname:"http://localhost:3000"}req,_:=gotenberg.NewHTMLRequest("index.html")
- req.SetHeader("header.html")
- req.SetFooter("footer.html")
+ req.Header("header.html")
+ req.Footer("footer.html")dest:="result.pdf"c.Store(req,dest)}
@@ -383,9 +458,6 @@ are on the same level as the index.html file.
If you want to install fonts directly in the Gotenberg Docker image,
see to the fonts section.
-
-
For web fonts (Google fonts), there is a timeout of 500ms by default. You may update
-this value thanks to the form field webFontsTimeout.
import"github.com/thecodingmachine/gotenberg-go-client/v5"funcmain(){c:=&gotenberg.Client{Hostname:"http://localhost:3000"}req:=gotenberg.NewURLRequest("https://google.com")
- req.SetMargins(gotenberg.NoMargins)
+ req.Margins(gotenberg.NoMargins)dest:="result.pdf"c.Store(req,dest)}
@@ -620,7 +746,7 @@ in the file index.html. This function will convert a given markdown
Go
-
import"github.com/thecodingmachine/gotenberg-go-client/v5"funcmain(){c:=&gotenberg.Client{Hostname:"http://localhost:3000"}
@@ -703,7 +829,7 @@ See the scalability section to find how to mitigate t
Go
-
All endpoints accept a form field named resultFilename.
If provided, the API will return the resulting PDF file with the given filename.
Otherwise a random filename is used.
-
The Go and PHP libraries do not provide a way to set this form field.
-However, you may hijack the response from the API or store the resulting PDF
-using a custom filename.
-
Attention: this feature does not work if the form field webhookURL is given.