2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 03:56:43 +00:00

Add option to specify config file via environment variable

This commit is contained in:
Oliver Walters 2021-04-07 23:46:03 +10:00
parent 9c38d67b52
commit d4d9263131
4 changed files with 23 additions and 17 deletions

View File

@ -55,7 +55,21 @@ TESTING = 'test' in sys.argv
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
cfg_filename = os.path.join(BASE_DIR, 'config.yaml') # Specify where the "config file" is located.
# By default, this is 'config.yaml'
cfg_filename = os.getenv('INVENTREE_CONFIG_FILE')
if cfg_filename:
cfg_filename = cfg_filename.strip()
cfg_filename = os.path.abspath(cfg_filename)
if not os.path.exists(cfg_filename):
print(f"InvenTree configuration file '{cfg_filename}' does not exist!")
sys.exit(1)
else:
# Config file is *not* specified - use the default
cfg_filename = os.path.join(BASE_DIR, 'config.yaml')
if not os.path.exists(cfg_filename): if not os.path.exists(cfg_filename):
print("InvenTree configuration file 'config.yaml' not found - creating default file") print("InvenTree configuration file 'config.yaml' not found - creating default file")

View File

@ -3,7 +3,6 @@ FROM python:alpine as production
# GitHub source # GitHub source
ARG INVENTREE_REPO="https://github.com/inventree/InvenTree.git" ARG INVENTREE_REPO="https://github.com/inventree/InvenTree.git"
ARG INVENTREE_VERSION="master" ARG INVENTREE_VERSION="master"
ARG INVENTREE_CONFIG_FILE="InvenTree/config_template.yaml"
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
@ -79,18 +78,15 @@ RUN apk add --no-cache supervisor
RUN mkdir ${INVENTREE_HOME}/media ${INVENTREE_HOME}/static ${INVENTREE_HOME}/backup RUN mkdir ${INVENTREE_HOME}/media ${INVENTREE_HOME}/static ${INVENTREE_HOME}/backup
# Copy supervisor file # Copy supervisor file
COPY docker/supervisord.conf ${INVENTREE_HOME}/supervisord.conf COPY supervisord.conf ${INVENTREE_HOME}/supervisord.conf
# Copy gunicorn config file # Copy gunicorn config file
COPY docker/gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py COPY gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py
# Copy default InvenTree config file
COPY ${INVENTREE_CONFIG_FILE} ${INVENTREE_SRC_DIR}/InvenTree/config.yaml
# Copy startup script # Copy startup script
COPY docker/start.sh ${INVENTREE_HOME}/start.sh COPY start.sh ${INVENTREE_HOME}/start.sh
RUN chmod 755 ${INVENTREE_HOME}/start.sh RUN chmod 755 ${INVENTREE_HOME}/start.sh
# Let us begin # Let us begin
CMD "./start.sh" CMD ["bash", "./start.sh"]

View File

@ -1,17 +1,13 @@
#!/bin/sh #!/bin/sh
echo "Starting InvenTree server..."
# Check that the database engine is specified # Check that the database engine is specified
if [ -z "$INVENTREE_DB_ENGINE" ]; then if [ -z "$INVENTREE_DB_ENGINE" ]; then
echo "INVENTREE_DB_ENGINE not configured" echo "INVENTREE_DB_ENGINE not configured"
exit 1 exit 1
fi fi
# Check that the base dir is set
if [ -z "$INVENTREE_HOME" ]; then
echo "INVENTREE_HOME not configured"
exit 1
fi
# Activate virtual environment # Activate virtual environment
source $INVENTREE_VENV/bin/activate source $INVENTREE_VENV/bin/activate

View File

@ -19,7 +19,7 @@ nodaemon=true
[program:inventree-server] [program:inventree-server]
user=inventree user=inventree
directory=%(ENV_INVENTREE_SRC_DIR)s/InvenTree directory=%(ENV_INVENTREE_SRC_DIR)s/InvenTree
command=%(ENV_INVENTREE_VENV)s/bin/gunicorn -c %(ENV_INVENTREE_HOME)s/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:80 command=%(ENV_INVENTREE_VENV)s/bin/gunicorn -c %(ENV_INVENTREE_HOME)s/gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8080
startsecs=10 startsecs=10
autostart=true autostart=true
autorestart=true autorestart=true