Simplify external directory structure

- All InvenTree data now in a single subdir
- Copy default config file (if it does not exist)
- Config file is accessible from outside world
- Update start_server and start_worker scripts
This commit is contained in:
Oliver Walters 2021-04-10 17:36:19 +10:00
parent 1372343bd5
commit 9086c8a3bf
4 changed files with 35 additions and 31 deletions

View File

@ -18,12 +18,14 @@ ENV INVENTREE_LOG_LEVEL="INFO"
# InvenTree paths
ENV INVENTREE_SRC_DIR="${INVENTREE_HOME}/src"
ENV INVENTREE_MNG_DIR="${INVENTREE_SRC_DIR}/InvenTree"
ENV INVENTREE_STATIC_ROOT="${INVENTREE_HOME}/static"
ENV INVENTREE_MEDIA_ROOT="${INVENTREE_HOME}/media"
ENV INVENTREE_LOG_DIR="${INVENTREE_HOME}/log"
ENV INVENTREE_BACKUP_DIR="${INVENTREE_HOME}/backup"
ENV INVENTREE_DATA_DIR="${INVENTREE_HOME}/data"
ENV INVENTREE_STATIC_ROOT="${INVENTREE_DATA_DIR}/static"
ENV INVENTREE_MEDIA_ROOT="${INVENTREE_MEDIA_DIR}/media"
ENV INVENTREE_BACKUP_DIR="${INVENTREE_DATA_DIR}/backup"
ENV INVENTREE_VENV="${INVENTREE_HOME}/env"
ENV INVENTREE_CONFIG_FILE="${INVENTREE_DATA_DIR}/config.yaml"
# Pass DB configuration through as environment variables
ENV INVENTREE_DB_ENGINE="${INVENTREE_DB_ENGINE}"
ENV INVENTREE_DB_NAME="${INVENTREE_DB_NAME}"
@ -59,7 +61,7 @@ RUN apk add --no-cache postgresql-contrib postgresql-dev libpq
RUN apk add --no-cache mariadb-connector-c mariadb-dev
# Create required directories
RUN mkdir ${INVENTREE_HOME}/media ${INVENTREE_HOME}/static ${INVENTREE_HOME}/backup
#RUN mkdir ${INVENTREE_DATA_DIR}}/media ${INVENTREE_HOME}/static ${INVENTREE_HOME}/backup
# Setup Python virtual environment
RUN python3 -m venv ${INVENTREE_VENV}

View File

@ -20,7 +20,9 @@ services:
- POSTGRES_USER=pguser
- POSTGRES_PASSWORD=pgpassword
volumes:
- database_data:/var/lib/postgresql/data/
# Map external directory to store database data
# Replace /path/to/dir with the required external path
- /mnt/c/abcdatabase:/var/lib/postgresql/data/
restart: unless-stopped
server:
@ -36,9 +38,9 @@ services:
depends_on:
- db
volumes:
- static_volume:/home/inventree/static
- media_volume:/home/inventree/media
- backup_volume:/home/inventree/backup
# Map external directory to store InvenTree data
# Replace /path/to/dir with the required external path
- /mnt/c/abcde:/home/inventree/data
environment:
- INVENTREE_DB_ENGINE=postgresql
- INVENTREE_DB_NAME=inventree
@ -60,10 +62,6 @@ services:
depends_on:
- db
- server
volumes:
- static_volume:/home/inventree/static
- media_volume:/home/inventree/media
- backup_volume:/home/inventree/backup
environment:
- INVENTREE_DB_ENGINE=postgresql
- INVENTREE_DB_NAME=inventree
@ -72,9 +70,3 @@ services:
- INVENTREE_DB_PORT=5432
- INVENTREE_DB_HOST=db
restart: unless-stopped
volumes:
database_data:
static_volume:
media_volume:
backup_volume:

View File

@ -1,17 +1,33 @@
#!/bin/sh
echo "Starting InvenTree server..."
# Create required directory structure (if it does not already exist)
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
echo "Creating directory $INVENTREE_STATIC_ROOT"
mkdir $INVENTREE_STATIC_ROOT
fi
# Check that the database engine is specified
if [ -z "$INVENTREE_DB_ENGINE" ]; then
echo "INVENTREE_DB_ENGINE not configured"
exit 1
if [[ ! -d "$INVENTREE_MEDIA_ROOT" ]]; then
echo "Creating directory $INVENTREE_MEDIA_ROOT"
mkdir $INVENTREE_MEDIA_ROOT
fi
if [[ ! -d "$INVENTREE_BACKUP_DIR" ]]; then
echo "Creating directory $INVENTREE_BACKUP_DIR"
mkdir $INVENTREE_BACKUP_DIR
fi
# Check if "config.yaml" has been copied into the correct location
if test -f "$INVENTREE_CONFIG_FILE"; then
echo "$INVENTREE_CONFIG_FILE exists - skipping"
else
echo "Copying config file to $INVENTREE_CONFIG_FILE"
cp $INVENTREE_SRC_DIR/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE
fi
# Activate virtual environment
source $INVENTREE_VENV/bin/activate
sleep 5
echo "Starting InvenTree server..."
# Wait for the database to be ready
cd $INVENTREE_MNG_DIR

View File

@ -2,12 +2,6 @@
echo "Starting InvenTree worker..."
# Check that the database engine is specified
if [ -z "$INVENTREE_DB_ENGINE" ]; then
echo "INVENTREE_DB_ENGINE not configured"
exit 1
fi
# Activate virtual environment
source ./env/bin/activate