mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Merge pull request #300 from TeraHz/master
Handle Django migrations at startup
This commit is contained in:
		| @@ -30,8 +30,6 @@ RUN apk --no-cache --update add \ | |||||||
|     apk del .build-dependencies && \ |     apk del .build-dependencies && \ | ||||||
| # Create the consumption directory | # Create the consumption directory | ||||||
|     mkdir -p $PAPERLESS_CONSUMPTION_DIR && \ |     mkdir -p $PAPERLESS_CONSUMPTION_DIR && \ | ||||||
| # Migrate database |  | ||||||
|     ./src/manage.py migrate && \ |  | ||||||
| # Create user | # Create user | ||||||
|     addgroup -g 1000 paperless && \ |     addgroup -g 1000 paperless && \ | ||||||
|     adduser -D -u 1000 -G paperless -h /usr/src/paperless paperless && \ |     adduser -D -u 1000 -G paperless -h /usr/src/paperless paperless && \ | ||||||
|   | |||||||
| @@ -1,12 +1,19 @@ | |||||||
| version: '2' | version: '2.1' | ||||||
|  |  | ||||||
| services: | services: | ||||||
|     webserver: |     webserver: | ||||||
|         build: ./ |         build: ./ | ||||||
|  |         # uncomment the following line to start automatically on system boot | ||||||
|  |         # restart: always | ||||||
|         ports: |         ports: | ||||||
|             # You can adapt the port you want Paperless to listen on by |             # You can adapt the port you want Paperless to listen on by | ||||||
|             # modifying the part before the `:`. |             # modifying the part before the `:`. | ||||||
|             - "8000:8000" |             - "8000:8000" | ||||||
|  |         healthcheck: | ||||||
|  |             test: ["CMD", "curl" , "-f", "http://localhost:8000"] | ||||||
|  |             interval: 30s | ||||||
|  |             timeout: 10s | ||||||
|  |             retries: 5 | ||||||
|         volumes: |         volumes: | ||||||
|             - data:/usr/src/paperless/data |             - data:/usr/src/paperless/data | ||||||
|             - media:/usr/src/paperless/media |             - media:/usr/src/paperless/media | ||||||
| @@ -21,6 +28,11 @@ services: | |||||||
|  |  | ||||||
|     consumer: |     consumer: | ||||||
|         build: ./ |         build: ./ | ||||||
|  |         # uncomment the following line to start automatically on system boot | ||||||
|  |         # restart: always | ||||||
|  |         depends_on: | ||||||
|  |             webserver: | ||||||
|  |                 condition: service_healthy | ||||||
|         volumes: |         volumes: | ||||||
|             - data:/usr/src/paperless/data |             - data:/usr/src/paperless/data | ||||||
|             - media:/usr/src/paperless/media |             - media:/usr/src/paperless/media | ||||||
|   | |||||||
| @@ -94,7 +94,7 @@ You may want to take a look at the ``paperless.conf.example`` file to see if | |||||||
| there's anything new in there compared to what you've got int ``/etc``. | there's anything new in there compared to what you've got int ``/etc``. | ||||||
|  |  | ||||||
| If you are :ref:`using Docker <setup-installation-docker>` the update process | If you are :ref:`using Docker <setup-installation-docker>` the update process | ||||||
| requires only one additional step: | is similar: | ||||||
|  |  | ||||||
| .. code-block:: shell-session | .. code-block:: shell-session | ||||||
|  |  | ||||||
| @@ -102,7 +102,6 @@ requires only one additional step: | |||||||
|     $ git pull |     $ git pull | ||||||
|     $ docker build -t paperless . |     $ docker build -t paperless . | ||||||
|     $ docker-compose up -d |     $ docker-compose up -d | ||||||
|     $ docker-compose run --rm webserver migrate |  | ||||||
|  |  | ||||||
| If ``git pull`` doesn't report any changes, there is no need to continue with | If ``git pull`` doesn't report any changes, there is no need to continue with | ||||||
| the remaining steps. | the remaining steps. | ||||||
|   | |||||||
| @@ -42,9 +42,24 @@ set_permissions() { | |||||||
|     chown -Rh paperless:paperless /usr/src/paperless |     chown -Rh paperless:paperless /usr/src/paperless | ||||||
| } | } | ||||||
|  |  | ||||||
|  | migrations() { | ||||||
|  |     # A simple lock file in case other containers use this startup | ||||||
|  |     LOCKFILE="/usr/src/paperless/data/db.sqlite3.migration" | ||||||
|  |  | ||||||
|  |     set -o noclobber | ||||||
|  |     # check for and create lock file in one command  | ||||||
|  |     (> ${LOCKFILE}) &> /dev/null | ||||||
|  |     if [ $? -eq 0 ] | ||||||
|  |     then | ||||||
|  |         sudo -HEu paperless "/usr/src/paperless/src/manage.py" "migrate" | ||||||
|  |         rm ${LOCKFILE} | ||||||
|  |     fi | ||||||
|  | } | ||||||
|  |  | ||||||
| initialize() { | initialize() { | ||||||
|     map_uidgid |     map_uidgid | ||||||
|     set_permissions |     set_permissions | ||||||
|  |     migrations | ||||||
| } | } | ||||||
|  |  | ||||||
| install_languages() { | install_languages() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn