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/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/docker-compose.dev.yml b/docker/docker-compose.dev.yml deleted file mode 100644 index 8cbe2a9e4d..0000000000 --- a/docker/docker-compose.dev.yml +++ /dev/null @@ -1,106 +0,0 @@ -version: "3.8" - -# Docker compose recipe for InvenTree development server -# - Runs PostgreSQL as the database backend -# - Uses built-in django webserver -# - Runs the InvenTree background worker process -# - Serves media and static content directly from Django webserver - -# 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 -# The django server will auto-detect any code changes and reload the server. - -services: - - # Database service - # Use PostgreSQL as the database backend - # Note: This can be changed to a different backend if required - inventree-dev-db: - container_name: inventree-dev-db - image: postgres:13 - ports: - - 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 - volumes: - # Map 'data' volume such that postgres database is stored externally - - src:/var/lib/postgresql/data - restart: unless-stopped - - # InvenTree web server services - # Uses gunicorn as the web server - inventree-dev-server: - container_name: inventree-dev-server - depends_on: - - inventree-dev-db - build: - context: . - target: dev - ports: - # Expose web server on port 8000 - - 8000:8000 - # Note: If using the inventree-dev-proxy container (see below), - # comment out the "ports" directive (above) and uncomment the "expose" directive - #expose: - # - 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 - - dev-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 - - dev-config.env - restart: unless-stopped - - ### Optional: Serve static and media files using nginx - ### Uncomment the following lines to enable nginx proxy for testing - ### Note: If enabling the proxy, change "ports" to "expose" for the inventree-dev-server container (above) - #inventree-dev-proxy: - # container_name: inventree-dev-proxy - # image: nginx:stable - # depends_on: - # - inventree-dev-server - # ports: - # # 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 - # # 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 - # 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.yml b/docker/docker-compose.yml index cef136bddb..e8bb12c44a 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,119 +1,104 @@ version: "3.8" -# Docker compose recipe for InvenTree +# Docker compose recipe for InvenTree development server # - Runs PostgreSQL as the database backend -# - Runs Gunicorn as the InvenTree web server +# - Uses built-in django webserver # - Runs the InvenTree background worker process -# - Runs nginx as a reverse proxy +# - Serves media and static content directly from Django webserver -# --------------------------------- -# 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! -# -# -# InvenTree Image Versions -# ------------------------ -# By default, this docker-compose script targets the STABLE version of InvenTree, -# image: inventree/inventree:stable -# -# To run the LATEST (development) version of InvenTree, change the target image to: -# image: inventree/inventree:latest -# -# Alternatively, you could target a specific tagged release version with (for example): -# image: inventree/inventree:0.5.3 -# -# NOTE: If you change the target image, ensure it is the same for the following containers: -# - inventree-server -# - inventree-worker +# IMPORANT NOTE: +# The InvenTree development image does not clone source code from git. +# 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 # 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 + # Note: This can be changed to a different backend if required + inventree-dev-db: + container_name: inventree-dev-db image: postgres:13 ports: - - 5432/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 prod-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 - - data:/var/lib/postgresql/data/ + # Map 'data' volume such that postgres database is stored externally + - inventree_src:/var/lib/postgresql/data restart: unless-stopped # InvenTree web server services # Uses gunicorn as the web server - inventree-server: - container_name: inventree-server - # If you wish to specify a particular InvenTree version, do so here - image: inventree/inventree:stable - expose: - - 8000 + inventree-dev-server: + container_name: inventree-dev-server depends_on: - - inventree-db + - inventree-dev-db + 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 + # Note: If using the inventree-dev-proxy container (see below), + # comment out the "ports" directive (above) and uncomment the "expose" directive + #expose: + # - 8000 volumes: - # Data volume must map to /home/inventree/data - - data:/home/inventree/data + # 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 production server are configured in prod-config.env - - prod-config.env + - .env restart: unless-stopped # Background worker process handles long-running or periodic tasks - inventree-worker: - container_name: inventree-worker - # If you wish to specify a particular InvenTree version, do so here - image: inventree/inventree:stable + inventree-dev-worker: + container_name: inventree-dev-worker + image: inventree-dev-image command: invoke worker depends_on: - - inventree-db - - inventree-server + - inventree-dev-server volumes: - # Data volume must map to /home/inventree/data - - data:/home/inventree/data + # 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 production server are configured in prod-config.env - - prod-config.env + - .env restart: unless-stopped - # nginx acts as a reverse proxy - # static files are served directly by nginx - # media files are served by nginx, although authentication is redirected to inventree-server - # web requests are redirected to gunicorn - # NOTE: You will need to provide a working nginx.conf file! - inventree-proxy: - container_name: inventree-proxy - image: nginx:stable - depends_on: - - inventree-server - ports: - # 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 - # Refer to the provided example file as a starting point - - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro - # nginx proxy needs access to static and media files - - data:/var/www - restart: unless-stopped + ### Optional: Serve static and media files using nginx + ### Uncomment the following lines to enable nginx proxy for testing + ### Note: If enabling the proxy, change "ports" to "expose" for the inventree-dev-server container (above) + #inventree-dev-proxy: + # container_name: inventree-dev-proxy + # image: nginx:stable + # depends_on: + # - inventree-dev-server + # ports: + # # Change "8000" to the port that you want InvenTree web server to be available on + # - 8000:80 + # volumes: + # # 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 + # - inventree_src:/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_src: 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 + # 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: ${INVENTREE_EXT_VOLUME:-../} 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} diff --git a/docker/prod-config.env b/docker/prod-config.env deleted file mode 100644 index a69fa10d2a..0000000000 --- a/docker/prod-config.env +++ /dev/null @@ -1,19 +0,0 @@ -# InvenTree environment variables for a production setup - -# Note: If your production setup varies from the example, you may want to change these values - -# 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) -INVENTREE_DB_ENGINE=postgresql -INVENTREE_DB_NAME=inventree -INVENTREE_DB_HOST=inventree-db -INVENTREE_DB_PORT=5432 -INVENTREE_DB_USER=pguser -INVENTREE_DB_PASSWORD=pgpassword - -# Enable plugins? -INVENTREE_PLUGINS_ENABLED=False diff --git a/docker/production/.env b/docker/production/.env new file mode 100644 index 0000000000..b1c9430b51 --- /dev/null +++ b/docker/production/.env @@ -0,0 +1,29 @@ +# InvenTree environment variables for a postgresql production setup + +# 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 +INVENTREE_LOG_LEVEL=WARNING + +# Database configuration options +# Note: The example setup is for a PostgreSQL database +INVENTREE_DB_ENGINE=postgresql +INVENTREE_DB_NAME=inventree +INVENTREE_DB_HOST=inventree-db +INVENTREE_DB_PORT=5432 +INVENTREE_DB_USER=pguser +INVENTREE_DB_PASSWORD=pgpassword + +# Enable plugins? +INVENTREE_PLUGINS_ENABLED=False diff --git a/docker/production/docker-compose.yml b/docker/production/docker-compose.yml new file mode 100644 index 0000000000..32fd3e0f48 --- /dev/null +++ b/docker/production/docker-compose.yml @@ -0,0 +1,124 @@ +version: "3.8" + +# 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 +# - 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 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, +# image: inventree/inventree:stable +# +# To run the LATEST (development) version of InvenTree, change the target image to: +# image: inventree/inventree:latest +# +# Alternatively, you could target a specific tagged release version with (for example): +# image: inventree/inventree:0.5.3 +# +# NOTE: If you change the target image, ensure it is the same for the following containers: +# - inventree-server +# - inventree-worker + +services: + # Database service + # Use PostgreSQL as the database backend + inventree-db: + container_name: inventree-db + image: postgres:13 + ports: + - ${INVENTREE_DB_PORT:-5432}/tcp + environment: + - PGDATA=/var/lib/postgresql/data/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 + - inventree_data:/var/lib/postgresql/data/ + restart: unless-stopped + + # InvenTree web server services + # Uses gunicorn as the web server + inventree-server: + container_name: inventree-server + # If you wish to specify a particular InvenTree version, do so here + image: inventree/inventree:stable + expose: + - 8000 + depends_on: + - inventree-db + env_file: + - .env + volumes: + # Data volume must map to /home/inventree/data + - inventree_data:/home/inventree/data + restart: unless-stopped + + # Background worker process handles long-running or periodic tasks + inventree-worker: + container_name: inventree-worker + # If you wish to specify a particular InvenTree version, do so here + image: inventree/inventree:stable + command: invoke worker + depends_on: + - inventree-db + - inventree-server + env_file: + - .env + volumes: + # Data volume must map to /home/inventree/data + - inventree_data:/home/inventree/data + restart: unless-stopped + + # nginx acts as a reverse proxy + # static files are served directly by nginx + # media files are served by nginx, although authentication is redirected to inventree-server + # web requests are redirected to gunicorn + # NOTE: You will need to provide a working nginx.conf file! + inventree-proxy: + container_name: inventree-proxy + image: nginx:stable + depends_on: + - inventree-server + env_file: + - .env + ports: + # 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 + - 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) + inventree_data: + driver: local + driver_opts: + type: none + o: bind + # This directory specified where InvenTree data are stored "outside" the docker containers + device: ${INVENTREE_EXT_VOLUME:?You must specify the 'INVENTREE_EXT_VOLUME' variable in the .env file!} diff --git a/docker/nginx.conf b/docker/production/nginx.prod.conf similarity index 100% rename from docker/nginx.conf rename to docker/production/nginx.prod.conf 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