mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Implements reading from a Docker secrets file in place of an environment variable for certain settings
This commit is contained in:
		 Trenton Holmes
					Trenton Holmes
				
			
				
					committed by
					
						 Johann Bauer
						Johann Bauer
					
				
			
			
				
	
			
			
			 Johann Bauer
						Johann Bauer
					
				
			
						parent
						
							52047b8167
						
					
				
				
					commit
					00059e9482
				
			| @@ -2,6 +2,37 @@ | |||||||
|  |  | ||||||
| set -e | set -e | ||||||
|  |  | ||||||
|  | # Adapted from: | ||||||
|  | # https://github.com/docker-library/postgres/blob/master/docker-entrypoint.sh | ||||||
|  | # usage: file_env VAR | ||||||
|  | #    ie: file_env 'XYZ_DB_PASSWORD' will allow for "$XYZ_DB_PASSWORD_FILE" to | ||||||
|  | # fill in the value of "$XYZ_DB_PASSWORD" from a file, especially for Docker's | ||||||
|  | # secrets feature | ||||||
|  | file_env() { | ||||||
|  | 	local var="$1" | ||||||
|  | 	local fileVar="${var}_FILE" | ||||||
|  |  | ||||||
|  | 	# Basic validation | ||||||
|  | 	if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then | ||||||
|  | 		echo >&2 "error: both $var and $fileVar are set (but are exclusive)" | ||||||
|  | 		exit 1 | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | 	# Only export var if the _FILE exists | ||||||
|  | 	if [ "${!fileVar:-}" ]; then | ||||||
|  | 		# And the file exists | ||||||
|  | 		if [[ -f ${!fileVar} ]]; then | ||||||
|  | 			echo "Setting ${var} from file" | ||||||
|  | 			val="$(< "${!fileVar}")" | ||||||
|  | 			export "$var"="$val" | ||||||
|  | 		else | ||||||
|  | 			echo "File ${!fileVar} doesn't exist" | ||||||
|  | 			exit 1 | ||||||
|  | 		fi | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
| # Source: https://github.com/sameersbn/docker-gitlab/ | # Source: https://github.com/sameersbn/docker-gitlab/ | ||||||
| map_uidgid() { | map_uidgid() { | ||||||
| 	USERMAP_ORIG_UID=$(id -u paperless) | 	USERMAP_ORIG_UID=$(id -u paperless) | ||||||
| @@ -22,6 +53,21 @@ map_folders() { | |||||||
| } | } | ||||||
|  |  | ||||||
| initialize() { | initialize() { | ||||||
|  |  | ||||||
|  | 	# Setup environment from secrets before anything else | ||||||
|  | 	for env_var in \ | ||||||
|  | 		PAPERLESS_DBUSER \ | ||||||
|  | 		PAPERLESS_DBPASS \ | ||||||
|  | 		PAPERLESS_SECRET_KEY \ | ||||||
|  | 		PAPERLESS_AUTO_LOGIN_USERNAME \ | ||||||
|  | 		PAPERLESS_ADMIN_USER \ | ||||||
|  | 		PAPERLESS_ADMIN_MAIL \ | ||||||
|  | 		PAPERLESS_ADMIN_PASSWORD; do | ||||||
|  | 		# Check for a version of this var with _FILE appended | ||||||
|  | 		# and convert the contents to the env var value | ||||||
|  | 		file_env ${env_var} | ||||||
|  | 	done | ||||||
|  |  | ||||||
| 	# Change the user and group IDs if needed | 	# Change the user and group IDs if needed | ||||||
| 	map_uidgid | 	map_uidgid | ||||||
|  |  | ||||||
|   | |||||||
| @@ -200,6 +200,19 @@ Install Paperless from Docker Hub | |||||||
|         You can copy any setting from the file ``paperless.conf.example`` and paste it here. |         You can copy any setting from the file ``paperless.conf.example`` and paste it here. | ||||||
|         Have a look at :ref:`configuration` to see what's available. |         Have a look at :ref:`configuration` to see what's available. | ||||||
|  |  | ||||||
|  |     .. note:: | ||||||
|  |  | ||||||
|  |         You can utilize Docker secrets for some configuration settings by | ||||||
|  |         appending `_FILE` to some configuration values.  This is supported currently | ||||||
|  |         only by: | ||||||
|  |           * PAPERLESS_DBUSER | ||||||
|  |           * PAPERLESS_DBPASS | ||||||
|  |           * PAPERLESS_SECRET_KEY | ||||||
|  |           * PAPERLESS_AUTO_LOGIN_USERNAME | ||||||
|  |           * PAPERLESS_ADMIN_USER | ||||||
|  |           * PAPERLESS_ADMIN_MAIL | ||||||
|  |           * PAPERLESS_ADMIN_PASSWORD | ||||||
|  |  | ||||||
|     .. caution:: |     .. caution:: | ||||||
|  |  | ||||||
|         Some file systems such as NFS network shares don't support file system |         Some file systems such as NFS network shares don't support file system | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user