mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix: Make management commands aware of the container environment (#9499)
This commit is contained in:
		| @@ -239,6 +239,7 @@ COPY --from=compile-frontend --chown=1000:1000 /src/src/documents/static/fronten | |||||||
| # add users, setup scripts | # add users, setup scripts | ||||||
| # Mount the compiled frontend to expected location | # Mount the compiled frontend to expected location | ||||||
| RUN set -eux \ | RUN set -eux \ | ||||||
|  |   && sed -i '1s|^#!/usr/bin/env python3|#!/command/with-contenv python3|' manage.py \ | ||||||
|   && echo "Setting up user/group" \ |   && echo "Setting up user/group" \ | ||||||
|     && addgroup --gid 1000 paperless \ |     && addgroup --gid 1000 paperless \ | ||||||
|     && useradd --uid 1000 --gid paperless --home-dir /usr/src/paperless paperless \ |     && useradd --uid 1000 --gid paperless --home-dir /usr/src/paperless paperless \ | ||||||
|   | |||||||
| @@ -24,8 +24,10 @@ | |||||||
| # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | ||||||
| #   and '.env' into a folder. | #   and '.env' into a folder. | ||||||
| # - Run 'docker compose pull'. | # - Run 'docker compose pull'. | ||||||
| # - Run 'docker compose run --rm webserver createsuperuser' to create a user. |  | ||||||
| # - Run 'docker compose up -d'. | # - Run 'docker compose up -d'. | ||||||
|  | # - Wait until the webserver has completed startup | ||||||
|  | # - Run 'docker compose exec webserver createsuperuser' to create a user. | ||||||
|  |  | ||||||
| # | # | ||||||
| # For more extensive installation and update instructions, refer to the | # For more extensive installation and update instructions, refer to the | ||||||
| # documentation. | # documentation. | ||||||
|   | |||||||
| @@ -20,8 +20,9 @@ | |||||||
| # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | ||||||
| #   and '.env' into a folder. | #   and '.env' into a folder. | ||||||
| # - Run 'docker compose pull'. | # - Run 'docker compose pull'. | ||||||
| # - Run 'docker compose run --rm webserver createsuperuser' to create a user. |  | ||||||
| # - Run 'docker compose up -d'. | # - Run 'docker compose up -d'. | ||||||
|  | # - Wait until the webserver has completed startup | ||||||
|  | # - Run 'docker compose exec webserver createsuperuser' to create a user. | ||||||
| # | # | ||||||
| # For more extensive installation and update instructions, refer to the | # For more extensive installation and update instructions, refer to the | ||||||
| # documentation. | # documentation. | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ | |||||||
| # - Click 'Deploy the stack' and wait for it to be deployed | # - Click 'Deploy the stack' and wait for it to be deployed | ||||||
| # - Open the list of containers, select paperless_webserver_1 | # - Open the list of containers, select paperless_webserver_1 | ||||||
| # - Click 'Console' and then 'Connect' to open the command line inside the container | # - Click 'Console' and then 'Connect' to open the command line inside the container | ||||||
| # - Run 'python3 manage.py createsuperuser' to create a user | # - Run 'createsuperuser' to create a user | ||||||
| # - Exit the console | # - Exit the console | ||||||
| # | # | ||||||
| # For more extensive installation and update instructions, refer to the | # For more extensive installation and update instructions, refer to the | ||||||
|   | |||||||
| @@ -24,8 +24,9 @@ | |||||||
| # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | ||||||
| #   and '.env' into a folder. | #   and '.env' into a folder. | ||||||
| # - Run 'docker compose pull'. | # - Run 'docker compose pull'. | ||||||
| # - Run 'docker compose run --rm webserver createsuperuser' to create a user. |  | ||||||
| # - Run 'docker compose up -d'. | # - Run 'docker compose up -d'. | ||||||
|  | # - Wait until the webserver has completed startup | ||||||
|  | # - Run 'docker compose exec webserver createsuperuser' to create a user. | ||||||
| # | # | ||||||
| # For more extensive installation and update instructions, refer to the | # For more extensive installation and update instructions, refer to the | ||||||
| # documentation. | # documentation. | ||||||
|   | |||||||
| @@ -20,8 +20,9 @@ | |||||||
| # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | ||||||
| #   and '.env' into a folder. | #   and '.env' into a folder. | ||||||
| # - Run 'docker compose pull'. | # - Run 'docker compose pull'. | ||||||
| # - Run 'docker compose run --rm webserver createsuperuser' to create a user. |  | ||||||
| # - Run 'docker compose up -d'. | # - Run 'docker compose up -d'. | ||||||
|  | # - Wait until the webserver has completed startup | ||||||
|  | # - Run 'docker compose exec webserver createsuperuser' to create a user. | ||||||
| # | # | ||||||
| # For more extensive installation and update instructions, refer to the | # For more extensive installation and update instructions, refer to the | ||||||
| # documentation. | # documentation. | ||||||
|   | |||||||
| @@ -24,8 +24,9 @@ | |||||||
| # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | ||||||
| #   and '.env' into a folder. | #   and '.env' into a folder. | ||||||
| # - Run 'docker compose pull'. | # - Run 'docker compose pull'. | ||||||
| # - Run 'docker compose run --rm webserver createsuperuser' to create a user. |  | ||||||
| # - Run 'docker compose up -d'. | # - Run 'docker compose up -d'. | ||||||
|  | # - Wait until the webserver has completed startup | ||||||
|  | # - Run 'docker compose exec webserver createsuperuser' to create a user. | ||||||
| # | # | ||||||
| # For more extensive installation and update instructions, refer to the | # For more extensive installation and update instructions, refer to the | ||||||
| # documentation. | # documentation. | ||||||
|   | |||||||
| @@ -17,8 +17,9 @@ | |||||||
| # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | # - Copy this file as 'docker-compose.yml' and the files 'docker-compose.env' | ||||||
| #   and '.env' into a folder. | #   and '.env' into a folder. | ||||||
| # - Run 'docker compose pull'. | # - Run 'docker compose pull'. | ||||||
| # - Run 'docker compose run --rm webserver createsuperuser' to create a user. |  | ||||||
| # - Run 'docker compose up -d'. | # - Run 'docker compose up -d'. | ||||||
|  | # - Wait until the webserver has completed startup | ||||||
|  | # - Run 'docker compose exec webserver createsuperuser' to create a user. | ||||||
| # | # | ||||||
| # For more extensive installation and update instructions, refer to the | # For more extensive installation and update instructions, refer to the | ||||||
| # documentation. | # documentation. | ||||||
|   | |||||||
| @@ -18,9 +18,10 @@ for command in decrypt_documents \ | |||||||
| 	document_fuzzy_match \ | 	document_fuzzy_match \ | ||||||
| 	manage_superuser \ | 	manage_superuser \ | ||||||
| 	convert_mariadb_uuid \ | 	convert_mariadb_uuid \ | ||||||
| 	prune_audit_logs; | 	prune_audit_logs \ | ||||||
|  | 	createsuperuser; | ||||||
| do | do | ||||||
| 	echo "installing $command..." | 	echo "installing $command..." | ||||||
| 	sed "s/management_command/$command/g" management_script.sh >"$PWD/rootfs/usr/local/bin/$command" | 	sed "s/management_command/$command/g" management_script.sh >"$PWD/rootfs/usr/local/bin/$command" | ||||||
| 	chmod +x "$PWD/rootfs/usr/local/bin/$command" | 	chmod u=rwx,g=rwx,o=rx "$PWD/rootfs/usr/local/bin/$command" | ||||||
| done | done | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								docker/rootfs/usr/local/bin/createsuperuser
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										14
									
								
								docker/rootfs/usr/local/bin/createsuperuser
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | #!/command/with-contenv /usr/bin/bash | ||||||
|  | # shellcheck shell=bash | ||||||
|  |  | ||||||
|  | set -e | ||||||
|  |  | ||||||
|  | cd "${PAPERLESS_SRC_DIR}" | ||||||
|  |  | ||||||
|  | if [[ $(id -u) == 0 ]]; then | ||||||
|  | 	s6-setuidgid paperless python3 manage.py createsuperuser "$@" | ||||||
|  | elif [[ $(id -un) == "paperless" ]]; then | ||||||
|  | 	python3 manage.py createsuperuser "$@" | ||||||
|  | else | ||||||
|  | 	echo "Unknown user." | ||||||
|  | fi | ||||||
| @@ -131,24 +131,30 @@ account. The script essentially automatically performs the steps described in [D | |||||||
|     by default but you can change the image to pull from Docker Hub by changing the `image` |     by default but you can change the image to pull from Docker Hub by changing the `image` | ||||||
|     line to `image: paperlessngx/paperless-ngx:latest`. |     line to `image: paperlessngx/paperless-ngx:latest`. | ||||||
|  |  | ||||||
| 6.  To be able to login, you will need a "superuser". To create it, | 6.  Run `docker compose up -d`. This will create and start the necessary containers. | ||||||
|  |  | ||||||
|  | 7.  Wait for the containers to complete their startup. You can monitor the logs using Docker, such as: | ||||||
|  |  | ||||||
|  |     ```shell-session | ||||||
|  |     docker logs --follow webserver | ||||||
|  |     ``` | ||||||
|  |  | ||||||
|  | 8.  To be able to login, you will need a "superuser". To create it, | ||||||
|     execute the following command: |     execute the following command: | ||||||
|  |  | ||||||
|     ```shell-session |     ```shell-session | ||||||
|     docker compose run --rm webserver createsuperuser |     docker compose exec webserver createsuperuser | ||||||
|     ``` |     ``` | ||||||
|  |  | ||||||
|     or using docker exec from within the container: |     or using docker exec from within the container: | ||||||
|  |  | ||||||
|     ```shell-session |     ```shell-session | ||||||
|     python3 manage.py createsuperuser |     createsuperuser | ||||||
|     ``` |     ``` | ||||||
|  |  | ||||||
|     This will guide you through the superuser setup. |     This will guide you through the superuser setup. | ||||||
|  |  | ||||||
| 7.  Run `docker compose up -d`. This will create and start the necessary containers. | 9.  Congratulations! Your Paperless-ngx instance should now be accessible at `http://127.0.0.1:8000` | ||||||
|  |  | ||||||
| 8.  Congratulations! Your Paperless-ngx instance should now be accessible at `http://127.0.0.1:8000` |  | ||||||
|     (or similar, depending on your configuration). Use the superuser credentials you have |     (or similar, depending on your configuration). Use the superuser credentials you have | ||||||
|     created in the previous step to login. |     created in the previous step to login. | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Trenton H
					Trenton H