mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 04:32:15 +01:00
minor refactoring of @tbflw work
This commit is contained in:
20
Makefile
20
Makefile
@@ -2,12 +2,12 @@ GOLANG_VERSION=1.12
|
|||||||
VERSION=snapshot
|
VERSION=snapshot
|
||||||
DOCKER_USER=
|
DOCKER_USER=
|
||||||
DOCKER_PASSWORD=
|
DOCKER_PASSWORD=
|
||||||
DOCKER_REPO=thecodingmachine
|
DOCKER_REPOSITORY=thecodingmachine
|
||||||
|
|
||||||
# generate documentation.
|
# generate documentation.
|
||||||
doc:
|
doc:
|
||||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t thecodingmachine/gotenberg:docs -f build/docs/Dockerfile .
|
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:docs -f build/docs/Dockerfile .
|
||||||
docker run --rm -it -v "$(PWD):/docs" thecodingmachine/gotenberg:docs
|
docker run --rm -it -v "$(PWD):/docs" $(DOCKER_REPOSITORY)/gotenberg:docs
|
||||||
|
|
||||||
# gofmt and goimports all go files.
|
# gofmt and goimports all go files.
|
||||||
fmt:
|
fmt:
|
||||||
@@ -16,23 +16,23 @@ fmt:
|
|||||||
|
|
||||||
# run all linters.
|
# run all linters.
|
||||||
lint:
|
lint:
|
||||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t thecodingmachine/gotenberg:lint -f build/lint/Dockerfile .
|
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:lint -f build/lint/Dockerfile .
|
||||||
docker run --rm -it -v "$(PWD):/lint" thecodingmachine/gotenberg:lint
|
docker run --rm -it -v "$(PWD):/lint" $(DOCKER_REPOSITORY)/gotenberg:lint
|
||||||
|
|
||||||
# run all tests.
|
# run all tests.
|
||||||
tests:
|
tests:
|
||||||
docker build -t thecodingmachine/gotenberg:base -f build/base/Dockerfile .
|
docker build -t $(DOCKER_REPOSITORY)/gotenberg:base -f build/base/Dockerfile .
|
||||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t thecodingmachine/gotenberg:tests -f build/tests/Dockerfile .
|
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:tests -f build/tests/Dockerfile .
|
||||||
docker run --rm -it -v "$(PWD):/tests" thecodingmachine/gotenberg:tests
|
docker run --rm -it -v "$(PWD):/tests" $(DOCKER_REPOSITORY)/gotenberg:tests
|
||||||
|
|
||||||
# build Docker image.
|
# build Docker image.
|
||||||
image:
|
image:
|
||||||
docker build -t thecodingmachine/gotenberg:base -f build/base/Dockerfile .
|
docker build -t $(DOCKER_REPOSITORY)/gotenberg:base -f build/base/Dockerfile .
|
||||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) --build-arg VERSION=$(VERSION) -t $(DOCKER_REPO)/gotenberg:$(VERSION) -f build/package/Dockerfile .
|
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) --build-arg VERSION=$(VERSION) -t $(DOCKER_REPO)/gotenberg:$(VERSION) -f build/package/Dockerfile .
|
||||||
|
|
||||||
# start the API using previously built Docker image.
|
# start the API using previously built Docker image.
|
||||||
gotenberg:
|
gotenberg:
|
||||||
docker run -it --rm -p "3000:3000" thecodingmachine/gotenberg:$(VERSION)
|
docker run -it --rm -e DEBUG_PROCESS_STARTUP=1 -p "3000:3000" $(DOCKER_REPOSITORY)/gotenberg:$(VERSION)
|
||||||
|
|
||||||
# publish Gotenberg images according to version.
|
# publish Gotenberg images according to version.
|
||||||
publish:
|
publish:
|
||||||
|
|||||||
@@ -96,11 +96,11 @@ COPY build/base/fonts.conf /etc/fonts/conf.d/100-gotenberg.conf
|
|||||||
# | Default user
|
# | Default user
|
||||||
# |--------------------------------------------------------------------------
|
# |--------------------------------------------------------------------------
|
||||||
# |
|
# |
|
||||||
# | TODO find a correct description for why we're doing this.
|
# | All processes in the Docker container will run as a dedicated
|
||||||
|
# | non-root user.
|
||||||
# |
|
# |
|
||||||
|
|
||||||
RUN groupadd --gid 1001 gotenberg \
|
RUN groupadd --gid 1001 gotenberg \
|
||||||
&& useradd --uid 1001 --gid gotenberg --shell /bin/bash --no-create-home gotenberg \
|
&& useradd --uid 1001 --gid gotenberg --shell /bin/bash --no-create-home gotenberg \
|
||||||
&& mkdir /gotenberg \
|
&& mkdir /gotenberg \
|
||||||
&& chown gotenberg: /gotenberg
|
&& chown gotenberg: /gotenberg
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ You may start it with:
|
|||||||
$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:5
|
$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:5
|
||||||
```
|
```
|
||||||
|
|
||||||
All processes in the docker container runs as a dedicated non-root user called `gotenberg` with user id `1001` from the working dir `/gotenberg`.
|
All processes in the Docker container runs as a dedicated non-root user called `gotenberg` with user id `1001` from the working dir `/gotenberg`.
|
||||||
|
|
||||||
> The API will be available at [http://localhost:3000](http://localhost:3000).
|
> The API will be available at [http://localhost:3000](http://localhost:3000).
|
||||||
|
|
||||||
@@ -40,11 +40,11 @@ Otherwise the API will not be able to launch Google Chrome and LibreOffice (unoc
|
|||||||
|
|
||||||
> The more resources are granted, the quicker will be the conversions.
|
> The more resources are granted, the quicker will be the conversions.
|
||||||
|
|
||||||
Also, in the deployment spec of the pod, specify the uid `1001` of the user `gotenberg`:
|
Also, in the deployment spec of the pod, specify the uid `1001` of the user `gotenberg`:
|
||||||
```
|
```
|
||||||
securityContext:
|
securityContext:
|
||||||
privileged: false
|
privileged: false
|
||||||
runAsUser: 1001
|
runAsUser: 1001
|
||||||
```
|
```
|
||||||
|
|
||||||
In the following examples, we will assume your
|
In the following examples, we will assume your
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ This environment variable accepts any string that can be turned into a port numb
|
|||||||
|
|
||||||
## Debug logging of process startup
|
## Debug logging of process startup
|
||||||
|
|
||||||
By default, stdout and stderr messages from the started processes are disabled.
|
By default, `stdout` and `stderr` messages from the started processes are disabled.
|
||||||
|
|
||||||
You may enable some debug logging from starting the process by setting the environment variable `DEBUG_PROCESS_STARTUP`.
|
You may enable some debug logging from starting the process by setting the environment variable `DEBUG_PROCESS_STARTUP`.
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ COPY cmd ./cmd
|
|||||||
COPY go.sum go.sum
|
COPY go.sum go.sum
|
||||||
COPY go.mod go.mod
|
COPY go.mod go.mod
|
||||||
|
|
||||||
|
|
||||||
# Build our binary.
|
# Build our binary.
|
||||||
RUN go build -o /gotenberg/gotenberg -ldflags "-X main.version=${VERSION}" cmd/gotenberg/main.go
|
RUN go build -o /gotenberg/gotenberg -ldflags "-X main.version=${VERSION}" cmd/gotenberg/main.go
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ func mustParseEnvVar() *api.Options {
|
|||||||
}
|
}
|
||||||
opts.DefaultListenPort = v
|
opts.DefaultListenPort = v
|
||||||
}
|
}
|
||||||
//checkBoolEnv is a convenience function for reading an env var with a bool value where `1` is true and `0` is false
|
// checkBoolEnv is a convenience function for reading
|
||||||
|
// an env var with a bool value where
|
||||||
|
// `1` is true and `0` is false.
|
||||||
checkBoolEnv := func(name string) bool {
|
checkBoolEnv := func(name string) bool {
|
||||||
if v, ok := os.LookupEnv(name); ok {
|
if v, ok := os.LookupEnv(name); ok {
|
||||||
if v != "1" && v != "0" {
|
if v != "1" && v != "0" {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@
|
|||||||
<pre class="chroma">$ docker run --rm -p <span class="m">3000</span>:3000 thecodingmachine/gotenberg:5
|
<pre class="chroma">$ docker run --rm -p <span class="m">3000</span>:3000 thecodingmachine/gotenberg:5
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>All processes in the docker container runs as a dedicated non-root user called <code>gotenberg</code> with user id <code>1001</code> from the working dir <code>/gotenberg</code>.</p>
|
<p>All processes in the Docker container runs as a dedicated non-root user called <code>gotenberg</code> with user id <code>1001</code> from the working dir <code>/gotenberg</code>.</p>
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>The API will be available at <a href="http://localhost:3000">http://localhost:3000</a>.</p>
|
<p>The API will be available at <a href="http://localhost:3000">http://localhost:3000</a>.</p>
|
||||||
@@ -180,9 +180,9 @@ Otherwise the API will not be able to launch Google Chrome and LibreOffice (unoc
|
|||||||
|
|
||||||
<p>Also, in the deployment spec of the pod, specify the uid <code>1001</code> of the user <code>gotenberg</code>:</p>
|
<p>Also, in the deployment spec of the pod, specify the uid <code>1001</code> of the user <code>gotenberg</code>:</p>
|
||||||
|
|
||||||
<pre class="chroma"> securityContext:
|
<pre class="chroma">securityContext:
|
||||||
privileged: false
|
privileged: false
|
||||||
runAsUser: 1001
|
runAsUser: 1001
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>In the following examples, we will assume your
|
<p>In the following examples, we will assume your
|
||||||
@@ -288,7 +288,7 @@ See the <a href="#timeout">timeout section</a>.</p>
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
||||||
</a>Debug logging of process startup</h2>
|
</a>Debug logging of process startup</h2>
|
||||||
|
|
||||||
<p>By default, stdout and stderr messages from the started processes are disabled.</p>
|
<p>By default, <code>stdout</code> and <code>stderr</code> messages from the started processes are disabled.</p>
|
||||||
|
|
||||||
<p>You may enable some debug logging from starting the process by setting the environment variable <code>DEBUG_PROCESS_STARTUP</code>.</p>
|
<p>You may enable some debug logging from starting the process by setting the environment variable <code>DEBUG_PROCESS_STARTUP</code>.</p>
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,13 @@ import (
|
|||||||
"github.com/mafredri/cdp/devtool"
|
"github.com/mafredri/cdp/devtool"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const warmupTime = 10 * time.Second
|
||||||
warmupTime = 10 * time.Second
|
|
||||||
)
|
|
||||||
|
|
||||||
type chrome struct {
|
type chrome struct {
|
||||||
manager *processManager
|
manager *processManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChrome retruns a Google Chrome
|
// NewChrome returns a Google Chrome
|
||||||
// headless process.
|
// headless process.
|
||||||
func NewChrome(debug bool) Process {
|
func NewChrome(debug bool) Process {
|
||||||
return &chrome{
|
return &chrome{
|
||||||
|
|||||||
@@ -87,11 +87,11 @@ func (m *processManager) pm2(p Process, cmdName string) error {
|
|||||||
if m.verbose {
|
if m.verbose {
|
||||||
processStdErr, err := cmd.StderrPipe()
|
processStdErr, err := cmd.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed getting stderr from '%s': %v", p.Fullname(), err)
|
return fmt.Errorf("failed getting stderr from %s: %s", p.Fullname(), err)
|
||||||
}
|
}
|
||||||
processStdOut, err := cmd.StdoutPipe()
|
processStdOut, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed getting stdout from '%s': %v", p.Fullname(), err)
|
return fmt.Errorf("failed getting stdout from %s: %s", p.Fullname(), err)
|
||||||
}
|
}
|
||||||
readFromPipe := func(name string, reader io.ReadCloser) {
|
readFromPipe := func(name string, reader io.ReadCloser) {
|
||||||
r := bufio.NewReader(reader)
|
r := bufio.NewReader(reader)
|
||||||
@@ -100,12 +100,12 @@ func (m *processManager) pm2(p Process, cmdName string) error {
|
|||||||
line, _, err := r.ReadLine()
|
line, _, err := r.ReadLine()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
m.notifyf("error reading from %v for process '%v'", name, p.Fullname())
|
m.notifyf("error reading from %s for process %s", name, p.Fullname())
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if len(line) != 0 {
|
if len(line) != 0 {
|
||||||
m.notifyf("%v %v: %s", p.name(), name, string(line))
|
m.notifyf("%s %s: %s", p.name(), name, string(line))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ type unoconv struct {
|
|||||||
manager *processManager
|
manager *processManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUnoconv retruns a unoconv listener
|
// NewUnoconv returns a unoconv listener
|
||||||
// process.
|
// process.
|
||||||
func NewUnoconv(debug bool) Process {
|
func NewUnoconv(debug bool) Process {
|
||||||
return &unoconv{
|
return &unoconv{
|
||||||
|
|||||||
Reference in New Issue
Block a user