Merge pull request #156 from thecodingmachine/custom_uid

Custom uid/gid
This commit is contained in:
Julien Neuhart
2019-12-09 15:15:11 +01:00
committed by GitHub
6 changed files with 83 additions and 47 deletions

View File

@@ -2,7 +2,9 @@ GOLANG_VERSION=1.13
VERSION=snapshot
DOCKER_USER=
DOCKER_PASSWORD=
DOCKER_REPOSITORY=thecodingmachine
DOCKER_REGISTRY=thecodingmachine
GOTENBERG_USER_GID=1001
GOTENBERG_USER_UID=1001
GOLANGCI_LINT_VERSION=1.20.1
CODE_COVERAGE=0
TINI_VERSION=0.18.0
@@ -20,12 +22,12 @@ DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE=1048576
# build the base Docker image.
base:
docker build -t $(DOCKER_REPOSITORY)/gotenberg:base -f build/base/Dockerfile .
docker build --build-arg GOTENBERG_USER_GID=$(GOTENBERG_USER_GID) --build-arg GOTENBERG_USER_UID=$(GOTENBERG_USER_UID) -t $(DOCKER_REGISTRY)/gotenberg:base -f build/base/Dockerfile .
# build the workspace Docker image.
workspace:
make base
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:workspace -f build/workspace/Dockerfile .
docker build --build-arg GOLANG_VERSION=$(GOLANG_VERSION) -t $(DOCKER_REGISTRY)/gotenberg:workspace -f build/workspace/Dockerfile .
# gofmt and goimports all go files.
fmt:
@@ -35,24 +37,24 @@ fmt:
# run all linters.
lint:
make workspace
docker build --build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:lint -f build/lint/Dockerfile .
docker run --rm $(DOCKER_REPOSITORY)/gotenberg:lint
docker build --build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) -t $(DOCKER_REGISTRY)/gotenberg:lint -f build/lint/Dockerfile .
docker run --rm $(DOCKER_REGISTRY)/gotenberg:lint
# run all tests.
tests:
make workspace
./scripts/tests.sh $(DOCKER_REPOSITORY) $(CODE_COVERAGE)
./scripts/tests.sh $(DOCKER_REGISTRY) $(CODE_COVERAGE)
# generate documentation.
doc:
make workspace
docker build -t $(DOCKER_REPOSITORY)/gotenberg:docs -f build/docs/Dockerfile .
docker run --rm -it -v "$(PWD):/gotenberg/docs" $(DOCKER_REPOSITORY)/gotenberg:docs
docker build -t $(DOCKER_REGISTRY)/gotenberg:docs -f build/docs/Dockerfile .
docker run --rm -it -v "$(PWD):/gotenberg/docs" $(DOCKER_REGISTRY)/gotenberg:docs
# build Gotenberg Docker image.
image:
make workspace
docker build --build-arg VERSION=$(VERSION) --build-arg TINI_VERSION=$(TINI_VERSION) -t $(DOCKER_REPOSITORY)/gotenberg:$(VERSION) -f build/package/Dockerfile .
docker build --build-arg VERSION=$(VERSION) --build-arg TINI_VERSION=$(TINI_VERSION) -t $(DOCKER_REGISTRY)/gotenberg:$(VERSION) -f build/package/Dockerfile .
# start the API using previously built Docker image.
gotenberg:
@@ -61,4 +63,4 @@ gotenberg:
# publish Gotenberg images according to version.
publish:
make workspace
./scripts/publish.sh $(GOLANG_VERSION) $(TINI_VERSION) $(DOCKER_REPOSITORY) $(VERSION) $(DOCKER_USER) $(DOCKER_PASSWORD)
./scripts/publish.sh $(GOLANG_VERSION) $(TINI_VERSION) $(DOCKER_REGISTRY) $(VERSION) $(DOCKER_USER) $(DOCKER_PASSWORD)

View File

@@ -104,7 +104,10 @@ COPY build/base/fonts.conf /etc/fonts/conf.d/100-gotenberg.conf
# | non-root user.
# |
RUN groupadd --gid 1001 gotenberg \
&& useradd --uid 1001 --gid gotenberg --shell /bin/bash --home /gotenberg --no-create-home gotenberg \
ARG GOTENBERG_USER_GID=1001
ARG GOTENBERG_USER_UID=1001
RUN groupadd --gid ${GOTENBERG_USER_GID} gotenberg \
&& useradd --uid ${GOTENBERG_USER_UID} --gid gotenberg --shell /bin/bash --home /gotenberg --no-create-home gotenberg \
&& mkdir /gotenberg \
&& chown gotenberg: /gotenberg

View File

@@ -4,8 +4,6 @@ title: Install
Gotenberg is shipped within a Docker image.
> It uses a dedicated non-root user called `gotenberg` with uid and gid `1001`.
You may start it with:
```bash
@@ -14,6 +12,23 @@ $ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:6
> The API will be available at [http://localhost:3000](http://localhost:3000).
The image uses a dedicated non-root user called `gotenberg` with uid and gid `1001`.
If you wish to change those uid and gid, you will have to:
* clone the project
* re-build the image
* publish the image in your own Docker registry
For instance:
```bash
$ git clone https://github.com/thecodingmachine/gotenberg.git
$ make publish GOTENBERG_USER_GID=your_custom_gid GOTENBERG_USER_UID=your_custom_uid DOCKER_REGISTRY=your_registry DOCKER_USER=registry_user DOCKER_PASSWORD=registry_password VERSION=6.1.0
```
> `master` branch is always up-to-date with the latest version of the API.
## Docker Compose
You may also add it in your Docker Compose stack:
@@ -39,7 +54,7 @@ Make sure to provide enough memory and CPU requests (for instance `512Mi` and `0
> The more resources are granted, the quicker will be the conversions.
In the deployment specification of the pod, also specify the uid `1001` of the user `gotenberg`:
In the deployment specification of the pod, also specify the uid of the user `gotenberg`:
```
securityContext:

View File

@@ -132,33 +132,49 @@
</a>Install</h1>
<p>Gotenberg is shipped within a Docker image.</p>
<blockquote>
<p>It uses a dedicated non-root user called <code>gotenberg</code> with uid and gid <code>1001</code>.</p>
</blockquote>
<p>You may start it with:</p>
<pre class="chroma">$ docker run --rm -p <span class="m">3000</span>:3000 thecodingmachine/gotenberg:6
<pre class="chroma">$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:6
</pre>
<blockquote>
<p>The API will be available at <a href="http://localhost:3000">http://localhost:3000</a>.</p>
</blockquote>
<p>The image uses a dedicated non-root user called <code>gotenberg</code> with uid and gid <code>1001</code>.</p>
<p>If you wish to change those uid and gid, you will have to:</p>
<ul>
<li>clone the project</li>
<li>re-build the image</li>
<li>publish the image in your own Docker registry</li>
</ul>
<p>For instance:</p>
<pre class="chroma">$ git clone https://github.com/thecodingmachine/gotenberg.git
$ make publish <span class="nv">GOTENBERG_USER_GID</span><span class="o">=</span>your_custom_gid <span class="nv">GOTENBERG_USER_UID</span><span class="o">=</span>your_custom_uid <span class="nv">DOCKER_REGISTRY</span><span class="o">=</span>your_registry <span class="nv">DOCKER_USER</span><span class="o">=</span>registry_user <span class="nv">DOCKER_PASSWORD</span><span class="o">=</span>registry_password <span class="nv">VERSION</span><span class="o">=</span>6.1.0
</pre>
<blockquote>
<p><code>master</code> branch is always up-to-date with the latest version of the API.</p>
</blockquote>
<h2 class="Heading"><a class="Anchor" aria-hidden="true" id="install.docker_compose" href="#install.docker_compose">
<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>Docker Compose</h2>
<p>You may also add it in your Docker Compose stack:</p>
<pre class="chroma">version<span class="p">:</span><span class="w"> </span><span class="s1">&#39;3&#39;</span><span class="w">
<pre class="chroma"><span class="k">version</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;3&#39;</span><span class="w">
</span><span class="w">
</span><span class="w"></span>services<span class="p">:</span><span class="w">
</span><span class="w"></span><span class="k">services</span><span class="p">:</span><span class="w">
</span><span class="w">
</span><span class="w"> </span><span class="c"># your others services</span><span class="w">
</span><span class="w">
</span><span class="w"> </span>gotenberg<span class="p">:</span><span class="w">
</span><span class="w"> </span>image<span class="p">:</span><span class="w"> </span>thecodingmachine/gotenberg<span class="p">:</span><span class="m">6</span><span class="w">
</span><span class="w"> </span><span class="k">gotenberg</span><span class="p">:</span><span class="w">
</span><span class="w"> </span><span class="k">image</span><span class="p">:</span><span class="w"> </span>thecodingmachine/gotenberg<span class="p">:</span><span class="m">6</span><span class="w">
</span></pre>
<blockquote>
@@ -177,7 +193,7 @@
<p>The more resources are granted, the quicker will be the conversions.</p>
</blockquote>
<p>In the deployment specification of the pod, also specify the uid <code>1001</code> of the user <code>gotenberg</code>:</p>
<p>In the deployment specification of the pod, also specify the uid of the user <code>gotenberg</code>:</p>
<pre class="chroma">securityContext:
privileged: false
@@ -673,8 +689,8 @@ $client-&gt;store($request, $dest);
</span><span class="se"></span> --url http://localhost:3000/convert/html <span class="se">\
</span><span class="se"></span> --header <span class="s1">&#39;Content-Type: multipart/form-data&#39;</span> <span class="se">\
</span><span class="se"></span> --form <span class="nv">files</span><span class="o">=</span>@index.html <span class="se">\
</span><span class="se"></span> --form <span class="nv">paperWidth</span><span class="o">=</span><span class="m">8</span>.27 <span class="se">\
</span><span class="se"></span> --form <span class="nv">paperHeight</span><span class="o">=</span><span class="m">11</span>.69 <span class="se">\
</span><span class="se"></span> --form <span class="nv">paperWidth</span><span class="o">=</span>8.27 <span class="se">\
</span><span class="se"></span> --form <span class="nv">paperHeight</span><span class="o">=</span>11.69 <span class="se">\
</span><span class="se"></span> --form <span class="nv">marginTop</span><span class="o">=</span><span class="m">0</span> <span class="se">\
</span><span class="se"></span> --form <span class="nv">marginBottom</span><span class="o">=</span><span class="m">0</span> <span class="se">\
</span><span class="se"></span> --form <span class="nv">marginLeft</span><span class="o">=</span><span class="m">0</span> <span class="se">\
@@ -739,7 +755,7 @@ a lot on JavaScript for rendering.</p>
</span><span class="se"></span> --url http://localhost:3000/convert/html <span class="se">\
</span><span class="se"></span> --header <span class="s1">&#39;Content-Type: multipart/form-data&#39;</span> <span class="se">\
</span><span class="se"></span> --form <span class="nv">files</span><span class="o">=</span>@index.html <span class="se">\
</span><span class="se"></span> --form <span class="nv">waitDelay</span><span class="o">=</span><span class="m">5</span>.5 <span class="se">\
</span><span class="se"></span> --form <span class="nv">waitDelay</span><span class="o">=</span>5.5 <span class="se">\
</span><span class="se"></span> -o result.pdf
</pre>
@@ -1205,7 +1221,7 @@ If unsucessful, it returns a <code>504</code> HTTP code.</p>
</span><span class="se"></span> --url http://localhost:3000/convert/html <span class="se">\
</span><span class="se"></span> --header <span class="s1">&#39;Content-Type: multipart/form-data&#39;</span> <span class="se">\
</span><span class="se"></span> --form <span class="nv">files</span><span class="o">=</span>@index.html <span class="se">\
</span><span class="se"></span> --form <span class="nv">waitTimeout</span><span class="o">=</span><span class="m">2</span>.5
</span><span class="se"></span> --form <span class="nv">waitTimeout</span><span class="o">=</span>2.5
</pre>
<h3 class="Heading"><a class="Anchor" aria-hidden="true" id="timeout.examples.go" href="#timeout.examples.go">
@@ -1323,7 +1339,7 @@ $resp = $client-&gt;post($request);
</span><span class="se"></span> --header <span class="s1">&#39;Content-Type: multipart/form-data&#39;</span> <span class="se">\
</span><span class="se"></span> --form <span class="nv">files</span><span class="o">=</span>@index.html <span class="se">\
</span><span class="se"></span> --form <span class="nv">webhookURL</span><span class="o">=</span><span class="s1">&#39;http://myapp.com/webhook/&#39;</span> <span class="se">\
</span><span class="se"></span> --form <span class="nv">webhookURLTimeout</span><span class="o">=</span><span class="m">2</span>.5
</span><span class="se"></span> --form <span class="nv">webhookURLTimeout</span><span class="o">=</span>2.5
</pre>
<h4 class="Heading"><a class="Anchor" aria-hidden="true" id="webhook.timeout.examples.go" href="#webhook.timeout.examples.go">
@@ -1463,14 +1479,14 @@ if the API is under heavy load.</p>
<p>For instance, using the following Docker Compose file:</p>
<pre class="chroma">version<span class="p">:</span><span class="w"> </span><span class="s1">&#39;3&#39;</span><span class="w">
<pre class="chroma"><span class="k">version</span><span class="p">:</span><span class="w"> </span><span class="s1">&#39;3&#39;</span><span class="w">
</span><span class="w">
</span><span class="w"></span>services<span class="p">:</span><span class="w">
</span><span class="w"></span><span class="k">services</span><span class="p">:</span><span class="w">
</span><span class="w">
</span><span class="w"> </span><span class="c"># your others services</span><span class="w">
</span><span class="w">
</span><span class="w"> </span>gotenberg<span class="p">:</span><span class="w">
</span><span class="w"> </span>image<span class="p">:</span><span class="w"> </span>thecodingmachine/gotenberg<span class="p">:</span><span class="m">6</span><span class="w">
</span><span class="w"> </span><span class="k">gotenberg</span><span class="p">:</span><span class="w">
</span><span class="w"> </span><span class="k">image</span><span class="p">:</span><span class="w"> </span>thecodingmachine/gotenberg<span class="p">:</span><span class="m">6</span><span class="w">
</span></pre>
<p>You may now launch your services using:</p>

View File

@@ -4,7 +4,7 @@ set -e
GOLANG_VERSION="$1"
TINI_VERSION="$2"
DOCKER_REPOSITORY="$3"
DOCKER_REGISTRY="$3"
VERSION="$4"
DOCKER_USER="$5"
DOCKER_PASSWORD="$6"
@@ -23,13 +23,13 @@ fi
docker build \
--build-arg VERSION=${VERSION} \
--build-arg TINI_VERSION=${TINI_VERSION} \
-t ${DOCKER_REPOSITORY}/gotenberg:latest \
-t ${DOCKER_REPOSITORY}/gotenberg:${SEMVER[0]} \
-t ${DOCKER_REPOSITORY}/gotenberg:${SEMVER[0]}.${SEMVER[1]} \
-t ${DOCKER_REPOSITORY}/gotenberg:${SEMVER[0]}.${SEMVER[1]}.${SEMVER[2]} \
-t ${DOCKER_REGISTRY}/gotenberg:latest \
-t ${DOCKER_REGISTRY}/gotenberg:${SEMVER[0]} \
-t ${DOCKER_REGISTRY}/gotenberg:${SEMVER[0]}.${SEMVER[1]} \
-t ${DOCKER_REGISTRY}/gotenberg:${SEMVER[0]}.${SEMVER[1]}.${SEMVER[2]} \
-f build/package/Dockerfile .
docker push "${DOCKER_REPOSITORY}/gotenberg:latest"
docker push "${DOCKER_REPOSITORY}/gotenberg:${SEMVER[0]}"
docker push "${DOCKER_REPOSITORY}/gotenberg:${SEMVER[0]}.${SEMVER[1]}"
docker push "${DOCKER_REPOSITORY}/gotenberg:${SEMVER[0]}.${SEMVER[1]}.${SEMVER[2]}"
docker push "${DOCKER_REGISTRY}/gotenberg:latest"
docker push "${DOCKER_REGISTRY}/gotenberg:${SEMVER[0]}"
docker push "${DOCKER_REGISTRY}/gotenberg:${SEMVER[0]}.${SEMVER[1]}"
docker push "${DOCKER_REGISTRY}/gotenberg:${SEMVER[0]}.${SEMVER[1]}.${SEMVER[2]}"

View File

@@ -2,15 +2,15 @@
set -e
DOCKER_REPOSITORY="$1"
DOCKER_REGISTRY="$1"
CODE_COVERAGE="$2"
touch "$PWD/coverage.txt"
chmod 777 "$PWD/coverage.txt"
docker build -t "$DOCKER_REPOSITORY/gotenberg:tests" -f build/tests/Dockerfile .
docker build -t "$DOCKER_REGISTRY/gotenberg:tests" -f build/tests/Dockerfile .
if [ "$CODE_COVERAGE" = "1" ]; then
docker run --rm -e "CODE_COVERAGE=$CODE_COVERAGE" -v "$PWD/coverage.txt:/gotenberg/tests/coverage.txt" "$DOCKER_REPOSITORY/gotenberg:tests"
docker run --rm -e "CODE_COVERAGE=$CODE_COVERAGE" -v "$PWD/coverage.txt:/gotenberg/tests/coverage.txt" "$DOCKER_REGISTRY/gotenberg:tests"
else
docker run --rm -e "CODE_COVERAGE=$CODE_COVERAGE" "$DOCKER_REPOSITORY/gotenberg:tests"
docker run --rm -e "CODE_COVERAGE=$CODE_COVERAGE" "$DOCKER_REGISTRY/gotenberg:tests"
fi