diff --git a/docker/Dockerfile b/docker/Dockerfile index 893f028b9b..89af08f835 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index ba9d8e1261..d7d2c09cdb 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -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: diff --git a/docker/start_server.sh b/docker/start_server.sh index fb84783829..e9eaff1dfa 100644 --- a/docker/start_server.sh +++ b/docker/start_server.sh @@ -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 diff --git a/docker/start_worker.sh b/docker/start_worker.sh index 9b7f3f408e..a8a4815583 100644 --- a/docker/start_worker.sh +++ b/docker/start_worker.sh @@ -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