mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	docker-entrypoint.sh: split non-root tasks into docker-prepare.sh
This commit is contained in:
		| @@ -78,6 +78,7 @@ RUN cd docker \ | |||||||
| 	&& mkdir /var/log/supervisord /var/run/supervisord \ | 	&& mkdir /var/log/supervisord /var/run/supervisord \ | ||||||
| 	&& cp supervisord.conf /etc/supervisord.conf \ | 	&& cp supervisord.conf /etc/supervisord.conf \ | ||||||
| 	&& cp docker-entrypoint.sh /sbin/docker-entrypoint.sh \ | 	&& cp docker-entrypoint.sh /sbin/docker-entrypoint.sh \ | ||||||
|  | 	&& cp docker-prepare.sh /sbin/docker-prepare.sh \ | ||||||
| 	&& chmod 755 /sbin/docker-entrypoint.sh \ | 	&& chmod 755 /sbin/docker-entrypoint.sh \ | ||||||
| 	&& chmod +x install_management_commands.sh \ | 	&& chmod +x install_management_commands.sh \ | ||||||
| 	&& ./install_management_commands.sh \ | 	&& ./install_management_commands.sh \ | ||||||
|   | |||||||
| @@ -15,70 +15,6 @@ map_uidgid() { | |||||||
|     fi |     fi | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| wait_for_postgres() { |  | ||||||
| 	attempt_num=1 |  | ||||||
| 	max_attempts=5 |  | ||||||
|  |  | ||||||
| 	echo "Waiting for PostgreSQL to start..." |  | ||||||
|  |  | ||||||
| 	host="${PAPERLESS_DBHOST}" |  | ||||||
| 	port="${PAPERLESS_DBPORT}" |  | ||||||
|  |  | ||||||
| 	if [[ -z $port ]] ; |  | ||||||
| 	then |  | ||||||
| 		port="5432" |  | ||||||
| 	fi |  | ||||||
|  |  | ||||||
| 	while !</dev/tcp/$host/$port ; |  | ||||||
| 	do |  | ||||||
|  |  | ||||||
| 		if [ $attempt_num -eq $max_attempts ] |  | ||||||
| 		then |  | ||||||
| 			echo "Unable to connect to database." |  | ||||||
| 			exit 1 |  | ||||||
| 		else |  | ||||||
| 			echo "Attempt $attempt_num failed! Trying again in 5 seconds..." |  | ||||||
|  |  | ||||||
| 		fi |  | ||||||
|  |  | ||||||
| 		attempt_num=$(expr "$attempt_num" + 1) |  | ||||||
| 		sleep 5 |  | ||||||
| 	done |  | ||||||
|  |  | ||||||
|  |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| migrations() { |  | ||||||
|  |  | ||||||
| 	if [[ -n "${PAPERLESS_DBHOST}" ]] |  | ||||||
| 	then |  | ||||||
| 		wait_for_postgres |  | ||||||
| 	fi |  | ||||||
|  |  | ||||||
| 	( |  | ||||||
| 		# flock is in place to prevent multiple containers from doing migrations |  | ||||||
| 		# simultaneously. This also ensures that the db is ready when the command |  | ||||||
| 		# of the current container starts. |  | ||||||
| 		flock 200 |  | ||||||
| 		echo "Apply database migrations..." |  | ||||||
| 		sudo -HEu paperless python3 manage.py migrate |  | ||||||
| 	)  200>/usr/src/paperless/data/migration_lock |  | ||||||
|  |  | ||||||
| } |  | ||||||
|  |  | ||||||
| search_index() { |  | ||||||
| 	index_version=1 |  | ||||||
| 	index_version_file=/usr/src/paperless/data/.index_version |  | ||||||
|  |  | ||||||
| 	if [[ (! -f "$index_version_file") || $(< $index_version_file) != "$index_version" ]]; then |  | ||||||
| 		echo "Search index out of date. Updating..." |  | ||||||
| 		sudo -HEu paperless python3 manage.py document_index reindex |  | ||||||
| 		echo $index_version | sudo -HEu paperless tee $index_version_file >/dev/null |  | ||||||
| 	fi |  | ||||||
| } |  | ||||||
|  |  | ||||||
| initialize() { | initialize() { | ||||||
| 	map_uidgid | 	map_uidgid | ||||||
|  |  | ||||||
| @@ -92,13 +28,13 @@ initialize() { | |||||||
|  |  | ||||||
| 	echo "creating directory /tmp/paperless" | 	echo "creating directory /tmp/paperless" | ||||||
| 	mkdir -p /tmp/paperless | 	mkdir -p /tmp/paperless | ||||||
|  |      | ||||||
|  |     set +e | ||||||
| 	chown -R paperless:paperless ../ | 	chown -R paperless:paperless ../ | ||||||
| 	chown -R paperless:paperless /tmp/paperless | 	chown -R paperless:paperless /tmp/paperless | ||||||
|  |     set -e | ||||||
| 	migrations |      | ||||||
|  |     sudo -HEu paperless /sbin/docker-prepare.sh | ||||||
| 	search_index |  | ||||||
| } | } | ||||||
|  |  | ||||||
| install_languages() { | install_languages() { | ||||||
| @@ -154,4 +90,3 @@ else | |||||||
| 	echo Executing "$@" | 	echo Executing "$@" | ||||||
| 	exec "$@" | 	exec "$@" | ||||||
| fi | fi | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										68
									
								
								docker/docker-prepare.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										68
									
								
								docker/docker-prepare.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,68 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  |  | ||||||
|  | wait_for_postgres() { | ||||||
|  | 	attempt_num=1 | ||||||
|  | 	max_attempts=5 | ||||||
|  |  | ||||||
|  | 	echo "Waiting for PostgreSQL to start..." | ||||||
|  |  | ||||||
|  | 	host="${PAPERLESS_DBHOST}" | ||||||
|  | 	port="${PAPERLESS_DBPORT}" | ||||||
|  |  | ||||||
|  | 	if [[ -z $port ]] ; | ||||||
|  | 	then | ||||||
|  | 		port="5432" | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | 	while !</dev/tcp/$host/$port ; | ||||||
|  | 	do | ||||||
|  |  | ||||||
|  | 		if [ $attempt_num -eq $max_attempts ] | ||||||
|  | 		then | ||||||
|  | 			echo "Unable to connect to database." | ||||||
|  | 			exit 1 | ||||||
|  | 		else | ||||||
|  | 			echo "Attempt $attempt_num failed! Trying again in 5 seconds..." | ||||||
|  |  | ||||||
|  | 		fi | ||||||
|  |  | ||||||
|  | 		attempt_num=$(expr "$attempt_num" + 1) | ||||||
|  | 		sleep 5 | ||||||
|  | 	done | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | migrations() { | ||||||
|  | 	if [[ -n "${PAPERLESS_DBHOST}" ]] | ||||||
|  | 	then | ||||||
|  | 		wait_for_postgres | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | 	( | ||||||
|  | 		# flock is in place to prevent multiple containers from doing migrations | ||||||
|  | 		# simultaneously. This also ensures that the db is ready when the command | ||||||
|  | 		# of the current container starts. | ||||||
|  | 		flock 200 | ||||||
|  | 		echo "Apply database migrations..." | ||||||
|  | 		sudo -HEu paperless python3 manage.py migrate | ||||||
|  | 	)  200>/usr/src/paperless/data/migration_lock | ||||||
|  | } | ||||||
|  |  | ||||||
|  | search_index() { | ||||||
|  | 	index_version=1 | ||||||
|  | 	index_version_file=/usr/src/paperless/data/.index_version | ||||||
|  |  | ||||||
|  | 	if [[ (! -f "$index_version_file") || $(< $index_version_file) != "$index_version" ]]; then | ||||||
|  | 		echo "Search index out of date. Updating..." | ||||||
|  | 		python3 manage.py document_index reindex | ||||||
|  | 		echo $index_version | sudo -HEu paperless tee $index_version_file >/dev/null | ||||||
|  | 	fi | ||||||
|  | } | ||||||
|  |  | ||||||
|  | do_work() { | ||||||
|  | 	migrations; | ||||||
|  | 	 | ||||||
|  | 	search_index; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | do_work; | ||||||
		Reference in New Issue
	
	Block a user
	 Starbeamrainbowlabs
					Starbeamrainbowlabs