mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-10 01:22:14 +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
|
||||
DOCKER_USER=
|
||||
DOCKER_PASSWORD=
|
||||
DOCKER_REPO=thecodingmachine
|
||||
DOCKER_REPOSITORY=thecodingmachine
|
||||
|
||||
# generate documentation.
|
||||
doc:
|
||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t thecodingmachine/gotenberg:docs -f build/docs/Dockerfile .
|
||||
docker run --rm -it -v "$(PWD):/docs" thecodingmachine/gotenberg:docs
|
||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:docs -f build/docs/Dockerfile .
|
||||
docker run --rm -it -v "$(PWD):/docs" $(DOCKER_REPOSITORY)/gotenberg:docs
|
||||
|
||||
# gofmt and goimports all go files.
|
||||
fmt:
|
||||
@@ -16,23 +16,23 @@ fmt:
|
||||
|
||||
# run all linters.
|
||||
lint:
|
||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t thecodingmachine/gotenberg:lint -f build/lint/Dockerfile .
|
||||
docker run --rm -it -v "$(PWD):/lint" thecodingmachine/gotenberg:lint
|
||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:lint -f build/lint/Dockerfile .
|
||||
docker run --rm -it -v "$(PWD):/lint" $(DOCKER_REPOSITORY)/gotenberg:lint
|
||||
|
||||
# run all tests.
|
||||
tests:
|
||||
docker build -t thecodingmachine/gotenberg:base -f build/base/Dockerfile .
|
||||
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t thecodingmachine/gotenberg:tests -f build/tests/Dockerfile .
|
||||
docker run --rm -it -v "$(PWD):/tests" thecodingmachine/gotenberg:tests
|
||||
docker build -t $(DOCKER_REPOSITORY)/gotenberg:base -f build/base/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" $(DOCKER_REPOSITORY)/gotenberg:tests
|
||||
|
||||
# build Docker 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 .
|
||||
|
||||
# start the API using previously built Docker image.
|
||||
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:
|
||||
|
||||
@@ -96,11 +96,11 @@ COPY build/base/fonts.conf /etc/fonts/conf.d/100-gotenberg.conf
|
||||
# | 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 \
|
||||
&& useradd --uid 1001 --gid gotenberg --shell /bin/bash --no-create-home gotenberg \
|
||||
&& mkdir /gotenberg \
|
||||
&& chown gotenberg: /gotenberg
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ You may start it with:
|
||||
$ 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).
|
||||
|
||||
@@ -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.
|
||||
|
||||
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:
|
||||
privileged: false
|
||||
runAsUser: 1001
|
||||
securityContext:
|
||||
privileged: false
|
||||
runAsUser: 1001
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
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`.
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ COPY cmd ./cmd
|
||||
COPY go.sum go.sum
|
||||
COPY go.mod go.mod
|
||||
|
||||
|
||||
# Build our binary.
|
||||
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
|
||||
}
|
||||
//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 {
|
||||
if v, ok := os.LookupEnv(name); ok {
|
||||
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>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<pre class="chroma"> securityContext:
|
||||
privileged: false
|
||||
runAsUser: 1001
|
||||
<pre class="chroma">securityContext:
|
||||
privileged: false
|
||||
runAsUser: 1001
|
||||
</pre>
|
||||
|
||||
<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>
|
||||
</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>
|
||||
|
||||
|
||||
@@ -7,15 +7,13 @@ import (
|
||||
"github.com/mafredri/cdp/devtool"
|
||||
)
|
||||
|
||||
const (
|
||||
warmupTime = 10 * time.Second
|
||||
)
|
||||
const warmupTime = 10 * time.Second
|
||||
|
||||
type chrome struct {
|
||||
manager *processManager
|
||||
}
|
||||
|
||||
// NewChrome retruns a Google Chrome
|
||||
// NewChrome returns a Google Chrome
|
||||
// headless process.
|
||||
func NewChrome(debug bool) Process {
|
||||
return &chrome{
|
||||
|
||||
@@ -87,11 +87,11 @@ func (m *processManager) pm2(p Process, cmdName string) error {
|
||||
if m.verbose {
|
||||
processStdErr, err := cmd.StderrPipe()
|
||||
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()
|
||||
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) {
|
||||
r := bufio.NewReader(reader)
|
||||
@@ -100,12 +100,12 @@ func (m *processManager) pm2(p Process, cmdName string) error {
|
||||
line, _, err := r.ReadLine()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
// NewUnoconv retruns a unoconv listener
|
||||
// NewUnoconv returns a unoconv listener
|
||||
// process.
|
||||
func NewUnoconv(debug bool) Process {
|
||||
return &unoconv{
|
||||
|
||||
Reference in New Issue
Block a user