From 206743b58d5142bbc2d086f8bbbedd0f705cdc3c Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 19:58:55 +1000 Subject: [PATCH 1/7] Add a default value for INVENTREE_WEB_ADDR --- docker/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 8f57d8a18c..c4f0b36492 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -35,7 +35,8 @@ ENV INVENTREE_SECRET_KEY_FILE="${INVENTREE_DATA_DIR}/secret_key.txt" ENV INVENTREE_GUNICORN_WORKERS="4" ENV INVENTREE_BACKGROUND_WORKERS="4" -# Default web server port is 8000 +# Default web server address:port +ENV INVENTREE_WEB_ADDR="0.0.0.0" ENV INVENTREE_WEB_PORT="8000" LABEL org.label-schema.schema-version="1.0" \ From 07857c3088ca119d42edf4ed7d5a98b53874cb51 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 19:59:32 +1000 Subject: [PATCH 2/7] Simplify dev-config.env file - Don't need to re-specify the internal docker variables - Add comments --- docker/dev-config.env | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docker/dev-config.env b/docker/dev-config.env index fe1f073633..ec00c47251 100644 --- a/docker/dev-config.env +++ b/docker/dev-config.env @@ -1,9 +1,10 @@ +# Set DEBUG to False for a production environment! +INVENTREE_DEBUG=true + +# Database linking options INVENTREE_DB_ENGINE=sqlite3 INVENTREE_DB_NAME=/home/inventree/dev/inventree_db.sqlite3 -INVENTREE_MEDIA_ROOT=/home/inventree/dev/media -INVENTREE_STATIC_ROOT=/home/inventree/dev/static -INVENTREE_CONFIG_FILE=/home/inventree/dev/config.yaml -INVENTREE_SECRET_KEY_FILE=/home/inventree/dev/secret_key.txt -INVENTREE_DEBUG=true -INVENTREE_WEB_ADDR=0.0.0.0 -INVENTREE_WEB_PORT=8000 \ No newline at end of file +# INVENTREE_DB_HOST=hostaddress +# INVENTREE_DB_PORT=5432 +# INVENTREE_DB_USERNAME=dbuser +# INVENTREE_DB_PASSWEORD=dbpassword From 7bf32295951da909820c01eb87f50e7cf10898aa Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 20:00:54 +1000 Subject: [PATCH 3/7] Add comment to docker-compose file --- docker/docker-compose.dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 29eccc26c6..ba8ed774ee 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -19,6 +19,7 @@ services: 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 @@ -26,7 +27,6 @@ services: env_file: # Environment variables required for the dev server are configured in dev-config.env - dev-config.env - restart: unless-stopped # Background worker process handles long-running or periodic tasks From a474000361f48cfb24b209b38d3063c10b21002f Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 20:29:48 +1000 Subject: [PATCH 4/7] Fix critical error in dockerfile - Don't' be putting no spaces in! --- docker/Dockerfile | 2 +- docker/dev-config.env | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index c4f0b36492..1266a282e4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -112,7 +112,7 @@ FROM base as dev # The development image requires the source code to be mounted to /home/inventree/ # So from here, we don't actually "do" anything, apart from some file management -ENV INVENTREE_DEV_DIR = "${INVENTREE_HOME}/dev" +ENV INVENTREE_DEV_DIR="${INVENTREE_HOME}/dev" # Override default path settings ENV INVENTREE_STATIC_ROOT="${INVENTREE_DEV_DIR}/static" diff --git a/docker/dev-config.env b/docker/dev-config.env index ec00c47251..67810291aa 100644 --- a/docker/dev-config.env +++ b/docker/dev-config.env @@ -1,5 +1,7 @@ +# InvenTree environment variables for a development setup + # Set DEBUG to False for a production environment! -INVENTREE_DEBUG=true +INVENTREE_DEBUG=True # Database linking options INVENTREE_DB_ENGINE=sqlite3 From d5d89c67b1da9258e17848c3c3e62d0bd4f1bb65 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 20:42:19 +1000 Subject: [PATCH 5/7] Error out if the static or media directories are not properly defined --- InvenTree/InvenTree/settings.py | 40 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 96b7da140d..6297dca41d 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -169,6 +169,30 @@ else: logger.exception(f"Couldn't load keyfile {key_file}") sys.exit(-1) +# The filesystem location for served static files +STATIC_ROOT = os.path.abspath( + get_setting( + 'INVENTREE_STATIC_ROOT', + CONFIG.get('static_root', None) + ) +) + +if STATIC_ROOT is None: + print("ERROR: INVENTREE_STATIC_ROOT directory not defined") + sys.exit(1) + +# The filesystem location for served static files +MEDIA_ROOT = os.path.abspath( + get_setting( + 'INVENTREE_MEDIA_ROOT', + CONFIG.get('media_root', None) + ) +) + +if MEDIA_ROOT is None: + print("ERROR: INVENTREE_MEDIA_ROOT directory is not defined") + sys.exit(1) + # List of allowed hosts (default = allow all) ALLOWED_HOSTS = CONFIG.get('allowed_hosts', ['*']) @@ -189,14 +213,6 @@ if cors_opt: # Web URL endpoint for served static files STATIC_URL = '/static/' -# The filesystem location for served static files -STATIC_ROOT = os.path.abspath( - get_setting( - 'INVENTREE_STATIC_ROOT', - CONFIG.get('static_root', '/home/inventree/data/static') - ) -) - STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'InvenTree', 'static'), ] @@ -218,14 +234,6 @@ STATIC_COLOR_THEMES_DIR = os.path.join(STATIC_ROOT, 'css', 'color-themes') # Web URL endpoint for served media files MEDIA_URL = '/media/' -# The filesystem location for served static files -MEDIA_ROOT = os.path.abspath( - get_setting( - 'INVENTREE_MEDIA_ROOT', - CONFIG.get('media_root', '/home/inventree/data/media') - ) -) - if DEBUG: logger.info("InvenTree running in DEBUG mode") From 895f9f3ce015152c93ad3bb20b8034c765ac82b4 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 20:45:57 +1000 Subject: [PATCH 6/7] Pull debug level out into the .env file --- docker/dev-config.env | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/dev-config.env b/docker/dev-config.env index 67810291aa..927f505649 100644 --- a/docker/dev-config.env +++ b/docker/dev-config.env @@ -3,6 +3,9 @@ # Set DEBUG to False for a production environment! INVENTREE_DEBUG=True +# Change verbosity level for debug output +INVENTREE_DEBUG_LEVEL="INFO" + # Database linking options INVENTREE_DB_ENGINE=sqlite3 INVENTREE_DB_NAME=/home/inventree/dev/inventree_db.sqlite3 From 0294a1c323702471c409876e2744a4b35055b355 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Aug 2021 21:02:45 +1000 Subject: [PATCH 7/7] Fix for staticfile collection - Was generating a *lot* of warning messages - Ref: https://github.com/django-compressor/django-compressor/issues/720 --- InvenTree/InvenTree/settings.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 6297dca41d..a0a9ca510e 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -213,14 +213,12 @@ if cors_opt: # Web URL endpoint for served static files STATIC_URL = '/static/' -STATICFILES_DIRS = [ - os.path.join(BASE_DIR, 'InvenTree', 'static'), -] +STATICFILES_DIRS = [] # Translated Template settings STATICFILES_I18_PREFIX = 'i18n' STATICFILES_I18_SRC = os.path.join(BASE_DIR, 'templates', 'js', 'translated') -STATICFILES_I18_TRG = STATICFILES_DIRS[0] + '_' + STATICFILES_I18_PREFIX +STATICFILES_I18_TRG = os.path.join(BASE_DIR, 'InvenTree', 'static_i18n') STATICFILES_DIRS.append(STATICFILES_I18_TRG) STATICFILES_I18_TRG = os.path.join(STATICFILES_I18_TRG, STATICFILES_I18_PREFIX)