From f0a01587acd4a8d2a504f036b13a0b231554663d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 21:18:12 +1000 Subject: [PATCH 01/10] Rename default docker-compose file --- docker/{docker-compose.yml => docker-compose.postgresql.yml} | 2 -- 1 file changed, 2 deletions(-) rename docker/{docker-compose.yml => docker-compose.postgresql.yml} (96%) diff --git a/docker/docker-compose.yml b/docker/docker-compose.postgresql.yml similarity index 96% rename from docker/docker-compose.yml rename to docker/docker-compose.postgresql.yml index cef136bddb..2f38182418 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.postgresql.yml @@ -32,8 +32,6 @@ version: "3.8" services: # Database service # Use PostgreSQL as the database backend - # Note: this can be changed to a different backend, - # just make sure that you change the INVENTREE_DB_xxx vars below inventree-db: container_name: inventree-db image: postgres:13 From e4e735a71bd0fcd2b4550be809fd2fc6d56f68be Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 21:44:22 +1000 Subject: [PATCH 02/10] Refactoring docker-compose.postgresql.yml - Do not require duplication of username / password values - Specify different env file - Move to a new child directory which simplifies setup --- docker/{prod-config.env => production/.env} | 2 +- .../docker-compose.yml} | 12 +++--------- docker/{ => production}/nginx.conf | 0 3 files changed, 4 insertions(+), 10 deletions(-) rename docker/{prod-config.env => production/.env} (88%) rename docker/{docker-compose.postgresql.yml => production/docker-compose.yml} (90%) rename docker/{ => production}/nginx.conf (100%) diff --git a/docker/prod-config.env b/docker/production/.env similarity index 88% rename from docker/prod-config.env rename to docker/production/.env index a69fa10d2a..88eae34ebe 100644 --- a/docker/prod-config.env +++ b/docker/production/.env @@ -1,4 +1,4 @@ -# InvenTree environment variables for a production setup +# InvenTree environment variables for a postgresql production setup # Note: If your production setup varies from the example, you may want to change these values diff --git a/docker/docker-compose.postgresql.yml b/docker/production/docker-compose.yml similarity index 90% rename from docker/docker-compose.postgresql.yml rename to docker/production/docker-compose.yml index 2f38182418..abb24f5f9e 100644 --- a/docker/docker-compose.postgresql.yml +++ b/docker/production/docker-compose.yml @@ -40,9 +40,9 @@ services: environment: - PGDATA=/var/lib/postgresql/data/pgdb # The pguser and pgpassword values must be the same in the other containers - # Ensure that these are correctly configured in your prod-config.env file - - POSTGRES_USER=pguser - - POSTGRES_PASSWORD=pgpassword + # Ensure that these are correctly configured in your .env file + - POSTGRES_USER=${INVENTREE_DB_USER} + - POSTGRES_PASSWORD=${INVENTREE_DB_PASSWORD} volumes: # Map 'data' volume such that postgres database is stored externally - data:/var/lib/postgresql/data/ @@ -61,9 +61,6 @@ services: volumes: # Data volume must map to /home/inventree/data - data:/home/inventree/data - env_file: - # Environment variables required for the production server are configured in prod-config.env - - prod-config.env restart: unless-stopped # Background worker process handles long-running or periodic tasks @@ -78,9 +75,6 @@ services: volumes: # Data volume must map to /home/inventree/data - data:/home/inventree/data - env_file: - # Environment variables required for the production server are configured in prod-config.env - - prod-config.env restart: unless-stopped # nginx acts as a reverse proxy diff --git a/docker/nginx.conf b/docker/production/nginx.conf similarity index 100% rename from docker/nginx.conf rename to docker/production/nginx.conf From a50f26e84d46be7652bfda7e77b5b4355f67da43 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 21:52:25 +1000 Subject: [PATCH 03/10] Adjust naming of nginx production file --- docker/production/docker-compose.yml | 14 +++++++------- docker/production/{nginx.conf => nginx.prod.conf} | 0 2 files changed, 7 insertions(+), 7 deletions(-) rename docker/production/{nginx.conf => nginx.prod.conf} (100%) diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index abb24f5f9e..bdccd8c955 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -1,10 +1,10 @@ version: "3.8" -# Docker compose recipe for InvenTree -# - Runs PostgreSQL as the database backend -# - Runs Gunicorn as the InvenTree web server -# - Runs the InvenTree background worker process -# - Runs nginx as a reverse proxy +# Docker compose recipe for InvenTree (production setup) +# - PostgreSQL as the database backend +# - gunicorn as the InvenTree web server +# - django-q as the InvenTree background worker process +# - nginx as a reverse proxy # --------------------------------- # IMPORTANT - READ BEFORE STARTING! @@ -91,9 +91,9 @@ services: # Change "1337" to the port that you want InvenTree web server to be available on - 1337:80 volumes: - # Provide ./nginx.conf file to the container + # Provide nginx configuration file to the container # Refer to the provided example file as a starting point - - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro + - ./nginx.prod.conf:/etc/nginx/conf.d/default.conf:ro # nginx proxy needs access to static and media files - data:/var/www restart: unless-stopped diff --git a/docker/production/nginx.conf b/docker/production/nginx.prod.conf similarity index 100% rename from docker/production/nginx.conf rename to docker/production/nginx.prod.conf From c3fff02bd8bae633290d5a0d11fa86b79ab916c7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 22:11:07 +1000 Subject: [PATCH 04/10] Automatically create a database (with the correct name) when the db container is started! --- docker/production/docker-compose.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index bdccd8c955..b9820cc10d 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -6,6 +6,12 @@ version: "3.8" # - django-q as the InvenTree background worker process # - nginx as a reverse proxy +# --------------------------------- +# Setting environment variables +# --------------------------------- +# Shared environment variables should be stored in the .env file +# Changes made to this file are reflected across all containers! + # --------------------------------- # IMPORTANT - READ BEFORE STARTING! # --------------------------------- @@ -36,13 +42,14 @@ services: container_name: inventree-db image: postgres:13 ports: - - 5432/tcp + - ${INVENTREE_DB_PORT}/tcp environment: - PGDATA=/var/lib/postgresql/data/pgdb # The pguser and pgpassword values must be the same in the other containers # Ensure that these are correctly configured in your .env file - POSTGRES_USER=${INVENTREE_DB_USER} - POSTGRES_PASSWORD=${INVENTREE_DB_PASSWORD} + - POSTGRES_DB=${INVENTREE_DB_NAME} volumes: # Map 'data' volume such that postgres database is stored externally - data:/var/lib/postgresql/data/ @@ -58,6 +65,8 @@ services: - 8000 depends_on: - inventree-db + env_file: + - .env volumes: # Data volume must map to /home/inventree/data - data:/home/inventree/data @@ -72,6 +81,8 @@ services: depends_on: - inventree-db - inventree-server + env_file: + - .env volumes: # Data volume must map to /home/inventree/data - data:/home/inventree/data @@ -87,6 +98,8 @@ services: image: nginx:stable depends_on: - inventree-server + env_file: + - .env ports: # Change "1337" to the port that you want InvenTree web server to be available on - 1337:80 From 0b3aac21ea4880831a94199faa8219ece0f60062 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 22:35:53 +1000 Subject: [PATCH 05/10] The production docker-compose file now no longer needs to be touched at all Everything can be specified in the .env file! --- docker/production/.env | 12 ++++++- docker/production/docker-compose.yml | 50 ++++++++++++++-------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/docker/production/.env b/docker/production/.env index 88eae34ebe..16ad58427d 100644 --- a/docker/production/.env +++ b/docker/production/.env @@ -1,6 +1,16 @@ # InvenTree environment variables for a postgresql production setup -# Note: If your production setup varies from the example, you may want to change these values +# Location of persistent database data (stored external to the docker containers) +# Note: You *must* un-comment this line, and point it to a path on your local machine + +# e.g. Linux +#INVENTREE_EXT_VOLUME=/home/me/inventree-data + +# e.g. Windows (docker desktop) +#INVENTREE_EXT_VOLUME=c:/Users/me/inventree-data + +# Default web port for the InvenTree server +INVENTREE_WEB_PORT=1337 # Ensure debug is false for a production setup INVENTREE_DEBUG=False diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml index b9820cc10d..5dbf4fcd73 100644 --- a/docker/production/docker-compose.yml +++ b/docker/production/docker-compose.yml @@ -6,20 +6,23 @@ version: "3.8" # - django-q as the InvenTree background worker process # - nginx as a reverse proxy -# --------------------------------- +# --------------------- +# READ BEFORE STARTING! +# --------------------- + +# ----------------------------- # Setting environment variables -# --------------------------------- +# ----------------------------- # Shared environment variables should be stored in the .env file # Changes made to this file are reflected across all containers! - -# --------------------------------- -# IMPORTANT - READ BEFORE STARTING! -# --------------------------------- -# Before running, ensure that you change the "/path/to/data" directory, -# specified in the "volumes" section at the end of this file. -# This path determines where the InvenTree data will be stored! -# # +# IMPORTANT NOTE: +# You should not have to change *anything* within the docker-compose.yml file! +# Instead, make any changes in the .env file! +# The only *mandatory* change is to set the INVENTREE_EXT_VOLUME variable, +# which defines the directory (on your local machine) where persistent data are stored. + +# ------------------------ # InvenTree Image Versions # ------------------------ # By default, this docker-compose script targets the STABLE version of InvenTree, @@ -42,17 +45,15 @@ services: container_name: inventree-db image: postgres:13 ports: - - ${INVENTREE_DB_PORT}/tcp + - ${INVENTREE_DB_PORT:-5432}/tcp environment: - PGDATA=/var/lib/postgresql/data/pgdb - # The pguser and pgpassword values must be the same in the other containers - # Ensure that these are correctly configured in your .env file - - POSTGRES_USER=${INVENTREE_DB_USER} - - POSTGRES_PASSWORD=${INVENTREE_DB_PASSWORD} - - POSTGRES_DB=${INVENTREE_DB_NAME} + - 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 - - data:/var/lib/postgresql/data/ + - inventree_data:/var/lib/postgresql/data/ restart: unless-stopped # InvenTree web server services @@ -69,7 +70,7 @@ services: - .env volumes: # Data volume must map to /home/inventree/data - - data:/home/inventree/data + - inventree_data:/home/inventree/data restart: unless-stopped # Background worker process handles long-running or periodic tasks @@ -85,7 +86,7 @@ services: - .env volumes: # Data volume must map to /home/inventree/data - - data:/home/inventree/data + - inventree_data:/home/inventree/data restart: unless-stopped # nginx acts as a reverse proxy @@ -101,24 +102,23 @@ services: env_file: - .env ports: - # Change "1337" to the port that you want InvenTree web server to be available on - - 1337:80 + # Default web port is 1337 (can be changed in the .env file) + - ${INVENTREE_WEB_PORT:-1337}:80 volumes: # Provide nginx configuration file to the container # Refer to the provided example file as a starting point - ./nginx.prod.conf:/etc/nginx/conf.d/default.conf:ro # nginx proxy needs access to static and media files - - data:/var/www + - inventree_data:/var/www restart: unless-stopped volumes: # NOTE: Change /path/to/data to a directory on your local machine # Persistent data, stored external to the container(s) - data: + inventree_data: driver: local driver_opts: type: none o: bind # This directory specified where InvenTree data are stored "outside" the docker containers - # Change this path to a local system path where you want InvenTree data stored - device: /path/to/data \ No newline at end of file + device: ${INVENTREE_EXT_VOLUME:?You must specify the 'INVENTREE_EXT_VOLUME' variable in the .env file!} From 85feb30812953c1edfee481f2e2a72e5768962e1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 23:15:37 +1000 Subject: [PATCH 06/10] 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 From e87e478009a77df5743cb7d0c7454fec4a01e515 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 23:34:50 +1000 Subject: [PATCH 07/10] Fix env file reference for docker-compose.yml (development) --- docker/docker-compose.yml | 6 ++---- docker/production/.env | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4b504fab2a..bfeca88336 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -54,8 +54,7 @@ services: # Ensure you specify the location of the 'src' directory at the end of this file - inventree_src:/home/inventree env_file: - # Environment variables required for the dev server are configured in dev-config.env - - dev-config.env + - .env restart: unless-stopped # Background worker process handles long-running or periodic tasks @@ -71,8 +70,7 @@ services: # Ensure you specify the location of the 'src' directory at the end of this file - inventree_src:/home/inventree env_file: - # Environment variables required for the dev server are configured in dev-config.env - - dev-config.env + - .env restart: unless-stopped ### Optional: Serve static and media files using nginx diff --git a/docker/production/.env b/docker/production/.env index 7cab3c93ee..b1c9430b51 100644 --- a/docker/production/.env +++ b/docker/production/.env @@ -12,12 +12,12 @@ # 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 # Database configuration options -# Note: The example setup is for a PostgreSQL database (change as required) +# Note: The example setup is for a PostgreSQL database INVENTREE_DB_ENGINE=postgresql INVENTREE_DB_NAME=inventree INVENTREE_DB_HOST=inventree-db From 6929d07f4212abf48a2b75dd266eccb305d84a5e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 20 Apr 2022 23:52:56 +1000 Subject: [PATCH 08/10] Cache the pre-built image - The worker container can then use it - Saves a *lot* of time (and otherwise wasted resources) --- docker/docker-compose.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index bfeca88336..e8bb12c44a 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -43,6 +43,8 @@ services: build: context: . target: dev + # Cache the built image to be used by the inventree-dev-worker process + image: inventree-dev-image ports: # Expose web server on port 8000 - 8000:8000 @@ -60,9 +62,7 @@ services: # Background worker process handles long-running or periodic tasks inventree-dev-worker: container_name: inventree-dev-worker - build: - context: . - target: dev + image: inventree-dev-image command: invoke worker depends_on: - inventree-dev-server From 0c93009bf7e1800e97dec0e6ece11ed614eb325e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 21 Apr 2022 00:01:11 +1000 Subject: [PATCH 09/10] Tweaks to dockerfile --- docker/Dockerfile | 4 ++-- docker/init.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 55a89210fe..b272683322 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -110,7 +110,8 @@ RUN pip3 install --user --no-cache-dir --disable-pip-version-check -r ${INVENTRE WORKDIR ${INVENTREE_MNG_DIR} # Server init entrypoint -ENTRYPOINT ["/bin/bash", "../docker/init.sh"] +COPY init.sh ${INVENTREE_HOME}/init.sh +ENTRYPOINT ["/bin/bash", "${INVENTREE_HOME}/init.sh"] # Launch the production server # TODO: Work out why environment variables cannot be interpolated in this command @@ -137,7 +138,6 @@ ENV INVENTREE_CONFIG_FILE="${INVENTREE_DEV_DIR}/config.yaml" ENV INVENTREE_SECRET_KEY_FILE="${INVENTREE_DEV_DIR}/secret_key.txt" ENV INVENTREE_PLUGIN_FILE="${INVENTREE_DEV_DIR}/plugins.txt" - WORKDIR ${INVENTREE_HOME} # Entrypoint ensures that we are running in the python virtual environment diff --git a/docker/init.sh b/docker/init.sh index 793661dc9f..088dd68e89 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -33,7 +33,7 @@ if [[ -n "$INVENTREE_PY_ENV" ]]; then source ${INVENTREE_PY_ENV}/bin/activate # Note: Python packages will have to be installed on first run - # e.g docker-compose -f docker-compose.dev.yml run inventree-dev-server invoke install + # e.g docker-compose run inventree-dev-server invoke update fi cd ${INVENTREE_HOME} From e15a4b73cda45b878ab131c59f0101b9837da7f9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 21 Apr 2022 00:03:48 +1000 Subject: [PATCH 10/10] Restore docker-compose.sqlite.yml This is used for docker build testing in CI! --- docker/docker-compose.sqlite.yml | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 docker/docker-compose.sqlite.yml diff --git a/docker/docker-compose.sqlite.yml b/docker/docker-compose.sqlite.yml new file mode 100644 index 0000000000..e42c43a09c --- /dev/null +++ b/docker/docker-compose.sqlite.yml @@ -0,0 +1,62 @@ +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: ../