From 85feb30812953c1edfee481f2e2a72e5768962e1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 23:15:37 +1000 Subject: [PATCH] Refactor development docker-compose setup --- docker/{dev-config.env => .env} | 3 +- docker/docker-compose.sqlite.yml | 62 ------------------- ...ker-compose.dev.yml => docker-compose.yml} | 32 +++++----- docker/production/.env | 2 +- docker/production/docker-compose.yml | 2 +- docker/sqlite-config.env | 10 --- 6 files changed, 20 insertions(+), 91 deletions(-) rename docker/{dev-config.env => .env} (89%) delete mode 100644 docker/docker-compose.sqlite.yml rename docker/{docker-compose.dev.yml => docker-compose.yml} (76%) delete mode 100644 docker/sqlite-config.env diff --git a/docker/dev-config.env b/docker/.env similarity index 89% rename from docker/dev-config.env rename to docker/.env index 63a0afe4fb..2c33931c0c 100644 --- a/docker/dev-config.env +++ b/docker/.env @@ -1,6 +1,6 @@ # InvenTree environment variables for a development setup -# Set DEBUG to False for a production environment! +# Set DEBUG to True for a development setup INVENTREE_DEBUG=True INVENTREE_DEBUG_LEVEL=INFO @@ -15,3 +15,4 @@ INVENTREE_DB_PASSWORD=pgpassword # Enable plugins? INVENTREE_PLUGINS_ENABLED=True + diff --git a/docker/docker-compose.sqlite.yml b/docker/docker-compose.sqlite.yml deleted file mode 100644 index e42c43a09c..0000000000 --- a/docker/docker-compose.sqlite.yml +++ /dev/null @@ -1,62 +0,0 @@ -version: "3.8" - -# Docker compose recipe for InvenTree development server -# - Runs sqlite database -# - Uses built-in django webserver -# - Runs the InvenTree background worker process -# - Serves media and static content directly from Django webserver - -# IMPORANT NOTE: -# The InvenTree docker image does not clone source code from git. -# Instead, you must specify *where* the source code is located, -# (on your local machine). -# The django server will auto-detect any code changes and reload the server. - -services: - - # InvenTree web server services - # Uses gunicorn as the web server - inventree-dev-server: - container_name: inventree-dev-server - build: - context: . - target: dev - ports: - # Expose web server on port 8000 - - 8000:8000 - volumes: - # Ensure you specify the location of the 'src' directory at the end of this file - - src:/home/inventree - env_file: - # Environment variables required for the dev server are configured in dev-config.env - - sqlite-config.env - restart: unless-stopped - - # Background worker process handles long-running or periodic tasks - inventree-dev-worker: - container_name: inventree-dev-worker - build: - context: . - target: dev - command: invoke worker - depends_on: - - inventree-dev-server - volumes: - # Ensure you specify the location of the 'src' directory at the end of this file - - src:/home/inventree - env_file: - # Environment variables required for the dev server are configured in dev-config.env - - sqlite-config.env - restart: unless-stopped - -volumes: - # NOTE: Change "../" to a directory on your local machine, where the InvenTree source code is located - # Persistent data, stored external to the container(s) - src: - driver: local - driver_opts: - type: none - o: bind - # This directory specified where InvenTree source code is stored "outside" the docker containers - # By default, this directory is one level above the "docker" directory - device: ../ diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.yml similarity index 76% rename from docker/docker-compose.dev.yml rename to docker/docker-compose.yml index 8cbe2a9e4d..4b504fab2a 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.yml @@ -8,10 +8,12 @@ version: "3.8" # IMPORANT NOTE: # The InvenTree development image does not clone source code from git. -# Instead, you must specify *where* the source code is located, (on your local machine). -# The default setup in this file should work straight out of the box, without modification +# Instead, it runs from source code on your local machine. # The django server will auto-detect any code changes and reload the server. +# If you have cloned the InvenTree git repo, and not made any changes to this file, +# then the default setup in this file should work straight out of the box, without modification + services: # Database service @@ -21,16 +23,15 @@ services: container_name: inventree-dev-db image: postgres:13 ports: - - 5432/tcp + - ${INVENTREE_DB_PORT:-5432}/tcp environment: - - PGDATA=/var/lib/postgresql/data/dev/pgdb - # The pguser and pgpassword values must be the same in the other containers - # Ensure that these are correctly configured in your dev-config.env file - - POSTGRES_USER=pguser - - POSTGRES_PASSWORD=pgpassword + - PGDATA=/var/lib/postgresql/data/dev/pgdb + - POSTGRES_USER=${INVENTREE_DB_USER:?You must provide the 'INVENTREE_DB_USER' variable in the .env file} + - POSTGRES_PASSWORD=${INVENTREE_DB_PASSWORD:?You must provide the 'INVENTREE_DB_PASSWORD' variable in the .env file} + - POSTGRES_DB=${INVENTREE_DB_NAME:?You must provide the 'INVENTREE_DB_NAME' variable in the .env file} volumes: # Map 'data' volume such that postgres database is stored externally - - src:/var/lib/postgresql/data + - inventree_src:/var/lib/postgresql/data restart: unless-stopped # InvenTree web server services @@ -51,7 +52,7 @@ services: # - 8000 volumes: # Ensure you specify the location of the 'src' directory at the end of this file - - src:/home/inventree + - inventree_src:/home/inventree env_file: # Environment variables required for the dev server are configured in dev-config.env - dev-config.env @@ -68,7 +69,7 @@ services: - inventree-dev-server volumes: # Ensure you specify the location of the 'src' directory at the end of this file - - src:/home/inventree + - inventree_src:/home/inventree env_file: # Environment variables required for the dev server are configured in dev-config.env - dev-config.env @@ -86,21 +87,20 @@ services: # # Change "8000" to the port that you want InvenTree web server to be available on # - 8000:80 # volumes: - # # Provide ./nginx.conf file to the container + # # Provide ./nginx.dev.conf file to the container # # Refer to the provided example file as a starting point # - ./nginx.dev.conf:/etc/nginx/conf.d/default.conf:ro # # nginx proxy needs access to static and media files - # - src:/var/www + # - inventree_src:/var/www # restart: unless-stopped volumes: - # NOTE: Change "../" to a directory on your local machine, where the InvenTree source code is located # Persistent data, stored external to the container(s) - src: + inventree_src: driver: local driver_opts: type: none o: bind # This directory specified where InvenTree source code is stored "outside" the docker containers # By default, this directory is one level above the "docker" directory - device: ../ + device: ${INVENTREE_EXT_VOLUME:-../} diff --git a/docker/production/.env b/docker/production/.env index 16ad58427d..7cab3c93ee 100644 --- a/docker/production/.env +++ b/docker/production/.env @@ -12,7 +12,7 @@ # Default web port for the InvenTree server INVENTREE_WEB_PORT=1337 -# Ensure debug is false for a production setup +# Ensure DEBUG is False for a production setup INVENTREE_DEBUG=False INVENTREE_LOG_LEVEL=WARNING diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index 5dbf4fcd73..32fd3e0f48 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -1,6 +1,6 @@ version: "3.8" -# Docker compose recipe for InvenTree (production setup) +# Docker compose recipe for InvenTree production server # - PostgreSQL as the database backend # - gunicorn as the InvenTree web server # - django-q as the InvenTree background worker process diff --git a/docker/sqlite-config.env b/docker/sqlite-config.env deleted file mode 100644 index b41660ad6e..0000000000 --- a/docker/sqlite-config.env +++ /dev/null @@ -1,10 +0,0 @@ -# InvenTree environment variables for a development setup - -# Set DEBUG to False for a production environment! -INVENTREE_DEBUG=True -INVENTREE_DEBUG_LEVEL=INFO - -# Database configuration options -# Note: The example setup is for a PostgreSQL database (change as required) -INVENTREE_DB_ENGINE=sqlite -INVENTREE_DB_NAME=/home/inventree/dev/inventree_db.sqlite3