Skip to content

Commit d1f59a6

Browse files
authored
Merge pull request jonaswinkler#1212 from theEndBeta/feature_rootless_and_container_repo
Enable rootless container w/ CI tweaks/bugfixes
2 parents ca7a6fe + cdecf89 commit d1f59a6

File tree

7 files changed

+89
-20
lines changed

7 files changed

+89
-20
lines changed

.github/scripts/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def get_image_tag(
1111
"""
1212
Returns a string representing the normal image for a given package
1313
"""
14-
return f"ghcr.io/{repo_name}/builder/{pkg_name}:{pkg_version}"
14+
return f"ghcr.io/{repo_name.lower()}/builder/{pkg_name}:{pkg_version}"
1515

1616

1717
def get_cache_image_tag(
@@ -26,7 +26,7 @@ def get_cache_image_tag(
2626
Registry type caching is utilized for the builder images, to allow fast
2727
rebuilds, generally almost instant for the same version
2828
"""
29-
return f"ghcr.io/{repo_name}/builder/cache/{pkg_name}:{pkg_version}"
29+
return f"ghcr.io/{repo_name.lower()}/builder/cache/{pkg_name}:{pkg_version}"
3030

3131

3232
def get_log_level(args) -> int:

.github/workflows/ci.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ jobs:
6868
- ci-backend
6969
- ci-frontend
7070
steps:
71+
-
72+
name: Set ghcr repository name
73+
id: set-ghcr-repository
74+
run: |
75+
ghcr_name=$(echo "${GITHUB_REPOSITORY}" | awk '{ print tolower($0) }')
76+
echo ::set-output name=repository::${ghcr_name}
7177
-
7278
name: Checkout
7379
uses: actions/checkout@v3
@@ -115,6 +121,8 @@ jobs:
115121
116122
outputs:
117123

124+
ghcr-repository: ${{ steps.set-ghcr-repository.outputs.repository }}
125+
118126
qpdf-json: ${{ steps.qpdf-setup.outputs.qpdf-json }}
119127

120128
pikepdf-json: ${{ steps.pikepdf-setup.outputs.pikepdf-json }}
@@ -142,7 +150,7 @@ jobs:
142150
# a tag
143151
# Otherwise forks would require a Docker Hub account and secrets setup
144152
run: |
145-
if [[ ${{ github.repository }} == "paperless-ngx/paperless-ngx" && ( ${{ github.ref_name }} == "main" || ${{ github.ref_name }} == "dev" || ${{ github.ref_name }} == "beta" || ${{ startsWith(github.ref, 'refs/tags/v') }} == "true" ) ]] ; then
153+
if [[ ${{ needs.prepare-docker-build.outputs.ghcr-repository }} == "paperless-ngx/paperless-ngx" && ( ${{ github.ref_name }} == "main" || ${{ github.ref_name }} == "dev" || ${{ github.ref_name }} == "beta" || ${{ startsWith(github.ref, 'refs/tags/v') }} == "true" ) ]] ; then
146154
echo "Enabling DockerHub image push"
147155
echo ::set-output name=enable::"true"
148156
else
@@ -155,7 +163,7 @@ jobs:
155163
uses: docker/metadata-action@v4
156164
with:
157165
images: |
158-
ghcr.io/${{ github.repository }}
166+
ghcr.io/${{ needs.prepare-docker-build.outputs.ghcr-repository }}
159167
name=paperlessngx/paperless-ngx,enable=${{ steps.docker-hub.outputs.enable }}
160168
tags: |
161169
# Tag branches with branch name
@@ -206,11 +214,11 @@ jobs:
206214
# Get cache layers from this branch, then dev, then main
207215
# This allows new branches to get at least some cache benefits, generally from dev
208216
cache-from: |
209-
type=registry,ref=ghcr.io/${{ github.repository }}/builder/cache/app:${{ github.ref_name }}
210-
type=registry,ref=ghcr.io/${{ github.repository }}/builder/cache/app:dev
211-
type=registry,ref=ghcr.io/${{ github.repository }}/builder/cache/app:main
217+
type=registry,ref=ghcr.io/${{ needs.prepare-docker-build.outputs.ghcr-repository }}/builder/cache/app:${{ github.ref_name }}
218+
type=registry,ref=ghcr.io/${{ needs.prepare-docker-build.outputs.ghcr-repository }}/builder/cache/app:dev
219+
type=registry,ref=ghcr.io/${{ needs.prepare-docker-build.outputs.ghcr-repository }}/builder/cache/app:main
212220
cache-to: |
213-
type=registry,mode=max,ref=ghcr.io/${{ github.repository }}/builder/cache/app:${{ github.ref_name }}
221+
type=registry,mode=max,ref=ghcr.io/${{ needs.prepare-docker-build.outputs.ghcr-repository }}/builder/cache/app:${{ github.ref_name }}
214222
-
215223
name: Inspect image
216224
run: |

.github/workflows/installer-library.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
name: Prepare Docker Image Version Data
3737
runs-on: ubuntu-20.04
3838
steps:
39+
-
40+
name: Set ghcr repository name
41+
id: set-ghcr-repository
42+
run: |
43+
ghcr_name=$(echo "${GITHUB_REPOSITORY}" | awk '{ print tolower($0) }')
44+
echo ::set-output name=repository::${ghcr_name}
3945
-
4046
name: Checkout
4147
uses: actions/checkout@v3
@@ -83,6 +89,8 @@ jobs:
8389
8490
outputs:
8591

92+
ghcr-repository: ${{ steps.set-ghcr-repository.outputs.repository }}
93+
8694
qpdf-json: ${{ steps.qpdf-setup.outputs.qpdf-json }}
8795

8896
pikepdf-json: ${{ steps.pikepdf-setup.outputs.pikepdf-json }}
@@ -134,6 +142,6 @@ jobs:
134142
dockerfile: ./docker-builders/Dockerfile.pikepdf
135143
build-json: ${{ needs.prepare-docker-build.outputs.pikepdf-json }}
136144
build-args: |
137-
REPO=${{ github.repository }}
145+
REPO=${{ needs.prepare-docker-build.outputs.ghcr-repository }}
138146
QPDF_VERSION=${{ fromJSON(needs.prepare-docker-build.outputs.qpdf-json).version }}
139147
PIKEPDF_VERSION=${{ fromJSON(needs.prepare-docker-build.outputs.pikepdf-json).version }}

Dockerfile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,36 @@ COPY gunicorn.conf.py .
117117
# setup docker-specific things
118118
# Use mounts to avoid copying installer files into the image
119119
# These change sometimes, but rarely
120-
WORKDIR /usr/src/paperless/src/docker/
120+
ARG DOCKER_SRC=/usr/src/paperless/src/docker/
121+
WORKDIR ${DOCKER_SRC}
122+
123+
COPY [ \
124+
"docker/imagemagick-policy.xml", \
125+
"docker/supervisord.conf", \
126+
"docker/docker-entrypoint.sh", \
127+
"docker/docker-prepare.sh", \
128+
"docker/paperless_cmd.sh", \
129+
"docker/wait-for-redis.py", \
130+
"docker/management_script.sh", \
131+
"docker/install_management_commands.sh", \
132+
"${DOCKER_SRC}" \
133+
]
121134

122-
RUN --mount=type=bind,readwrite,source=docker,target=./ \
123-
set -eux \
135+
RUN set -eux \
124136
&& echo "Configuring ImageMagick" \
125-
&& cp imagemagick-policy.xml /etc/ImageMagick-6/policy.xml \
137+
&& mv imagemagick-policy.xml /etc/ImageMagick-6/policy.xml \
126138
&& echo "Configuring supervisord" \
127139
&& mkdir /var/log/supervisord /var/run/supervisord \
128-
&& cp supervisord.conf /etc/supervisord.conf \
140+
&& mv supervisord.conf /etc/supervisord.conf \
129141
&& echo "Setting up Docker scripts" \
130-
&& cp docker-entrypoint.sh /sbin/docker-entrypoint.sh \
142+
&& mv docker-entrypoint.sh /sbin/docker-entrypoint.sh \
131143
&& chmod 755 /sbin/docker-entrypoint.sh \
132-
&& cp docker-prepare.sh /sbin/docker-prepare.sh \
144+
&& mv docker-prepare.sh /sbin/docker-prepare.sh \
133145
&& chmod 755 /sbin/docker-prepare.sh \
134-
&& cp wait-for-redis.py /sbin/wait-for-redis.py \
146+
&& mv wait-for-redis.py /sbin/wait-for-redis.py \
135147
&& chmod 755 /sbin/wait-for-redis.py \
148+
&& mv paperless_cmd.sh /usr/local/bin/paperless_cmd.sh \
149+
&& chmod 755 /usr/local/bin/paperless_cmd.sh \
136150
&& echo "Installing managment commands" \
137151
&& chmod +x install_management_commands.sh \
138152
&& ./install_management_commands.sh
@@ -211,4 +225,4 @@ ENTRYPOINT ["/sbin/docker-entrypoint.sh"]
211225

212226
EXPOSE 8000
213227

214-
CMD ["/usr/local/bin/supervisord", "-c", "/etc/supervisord.conf"]
228+
CMD ["/usr/local/bin/paperless_cmd.sh"]

docker/docker-entrypoint.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ initialize() {
9595
done
9696
set -e
9797

98-
gosu paperless /sbin/docker-prepare.sh
98+
${gosu_cmd[@]} /sbin/docker-prepare.sh
9999
}
100100

101101
install_languages() {
@@ -137,6 +137,11 @@ install_languages() {
137137

138138
echo "Paperless-ngx docker container starting..."
139139

140+
gosu_cmd=(gosu paperless)
141+
if [ $(id -u) == $(id -u paperless) ]; then
142+
gosu_cmd=()
143+
fi
144+
140145
# Install additional languages if specified
141146
if [[ -n "$PAPERLESS_OCR_LANGUAGES" ]]; then
142147
install_languages "$PAPERLESS_OCR_LANGUAGES"
@@ -146,7 +151,7 @@ initialize
146151

147152
if [[ "$1" != "/"* ]]; then
148153
echo Executing management command "$@"
149-
exec gosu paperless python3 manage.py "$@"
154+
exec ${gosu_cmd[@]} python3 manage.py "$@"
150155
else
151156
echo Executing "$@"
152157
exec "$@"

docker/paperless_cmd.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
rootless_args=()
4+
if [ $(id -u) == $(id -u paperless) ]; then
5+
rootless_args=(
6+
--user
7+
paperless
8+
--logfile
9+
supervisord.log
10+
--pidfile
11+
supervisord.pid
12+
)
13+
fi
14+
15+
/usr/local/bin/supervisord -c /etc/supervisord.conf ${rootless_args[@]}

docs/setup.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,25 @@ Install Paperless from Docker Hub
184184
port 8000. Modifying the part before the colon will map requests on another
185185
port to the webserver running on the default port.
186186

187+
**Rootless**
188+
189+
If you want to run Paperless as a rootless container, you will need to do the
190+
following in your ``docker-compose.yml``:
191+
192+
- set the ``user`` running the container to map to the ``paperless`` user in the
193+
container.
194+
This value (``user_id`` below), should be the same id that ``USERMAP_UID`` and
195+
``USERMAP_GID`` are set to in the next step.
196+
See ``USERMAP_UID`` and ``USERMAP_GID`` :ref:`here <configuration-docker>`.
197+
198+
Your entry for Paperless should contain something like:
199+
200+
.. code::
201+
202+
webserver:
203+
image: ghcr.io/paperless-ngx/paperless-ngx:latest
204+
user: <user_id>
205+
187206
5. Modify ``docker-compose.env``, following the comments in the file. The
188207
most important change is to set ``USERMAP_UID`` and ``USERMAP_GID``
189208
to the uid and gid of your user on the host system. Use ``id -u`` and

0 commit comments

Comments
 (0)