* Add ParameterTemplate model - Data structure duplicated from PartParameterTemplate * Apply data migration for templates * Admin integration * API endpoints for ParameterTemplate * Scaffolding * Add validator for ParameterTemplate model type - Update migrations - Make Parameter class abstract (for now) - Validators * API updates - Fix options for model_type - Add API filters * Add definition for Parameter model * Add django admin site integration * Update InvenTreeParameterMixin class - Fetch queryset of all linked Parameter instances - Ensure deletion of linked instances * API endpoints for Parameter instances * Refactor UI table for parameter templates * Add comment for later * Add "enabled" field to ParameterTemplate model * Add new field to serializer * Rough-in new table * Implement generic "parameter" table * Enable parameters for Company model * Change migration for part parameter - Make it "universal" * Remove code for ManufacturerPartParameter * Fix for filters * Add data import for parameter table * Add verbose name to ParameterTemplate model * Removed dead API code * Update global setting * Fix typos * Check global setting for unit validation * Use GenericForeignKey * Add generic relationship to allow reverse lookups * Fixes for table structure * Add custom serializer field for ContentType with choices * Adds ContentTypeField - Handles representation of content type - Provides human-readable options * Refactor API filtering for endpoints - Specify ContentType by ID, model or app label * Revert change to parameters property * Define GenericRelationship for linking model * Refactoring some code * Add a generic way to back-annotate and prefetch parameters for any model type * Change panel position * Directly annotate parameters against different model serializers * remove defunct admin classes * Run plugin validation against parameter * Fix prefetching for PartSerializer * Implement generic "filtering" against queryset * Implement generic "ordering" by parameter * Make parametric table generic * Refactor segmented panels * Consolidate part table views * Fix for parametric part table - Only display parameters for which we know there is a value * Add parametric tables for company views * Fix typo in file name * Prefetch to reduce hits * Add generic API mixin for filtering and ordering by parameter * Fix hook for rebuilding template parameters * Remove serializer * Remove old models * Fix code for copying parameters from category * Implement more parametric tables: - ManufacturerPart - SupplierPart - Fixes and enhancements * Add parameter support for orders * Add UI support for parameters against orders * Update API version * Update CHANGELOG.md * Add parameter support for build orders * Tweak frontend * Add renderer * Remove defunct endpoints * Add migration requirement * Require contenttypes to be updated * Update migration * Try using ID val * Adjust migration dependencies * fix params fixture * fix schema export * fix modelset * Fixes for data migration * tweak table * Fix for Category Parameters * Use branch of demo dataset for testing * Add parameteric build order table * disable broken imports * remove old model from ruleset * correct test * Table tweaks * fix test * Remove old model type * fix test * fix test * Refactor mixin to avoid specifying model type manually * fix test * fix resolve name * remove unneeded import * Tweak unit testing * Fix unit test * Enable bulk-create * More fixes * More unit test tweaks * Enhancements * Unit test fixes * Add some migration tests * Fix admin tests * Fix part tests * adapt expectation * fix remaining typecheck * Docs updates * Rearrange models * fix paramater caching * fix doc links * adjust assumption * Adjust data migration unit tests * docs fixes * Fix docs link * Fixes * Tweak formatting * Add doc for setting * Add metadata view for parameters * Add metadata view for ParamterTemplate * Update CHANGELOG file * Deconflict model_type fields * Invert key:value * Revert "Invert key:value" This reverts commitd555658db2. * fix assert * Update API rev notes * Initial unit tests for API * Test parameter create / edit / delete via the API * Add some more unit tests for the API * Validate queryset annotation - Add unit test with large dataset - Ensure number of queries is fixed - Fix for prefetching check * Add breaking change info to CHANGELOG.md * Ensure that parameters are removed when deleting the linked object * Enhance type hinting * Refactor part parameter exporter plugin - Any model which supports parameters can use this now - Update documentation * Improve serializer field * Adjust unit test * Reimplement checks for locked parts * Fix unit test for data migration * Fix for unit test * Allow disable edit for ParameterTable * Fix supplier part import wizard * Add unit tests for template API filtering * Add playwright tests for purchasing index * Add tests for manufacturing index page * ui tests for sales index * Add data migration tests for ManufacturerPartParameter * Pull specific branch for python binding tests * Specify target migration * Remove debug statement * Tweak migration unit tests * Add options for spectacular * Add explicit choice options * Ensure empty string values are converted to None * Don't use custom branch for python checks * Fix for migration test * Fix migration test * Fix reference target * Remove duplicate enum in spectactular.py * Add null choice to custom serializer class * [UI] Edit shipment details - Pass "pending" status through to the form * New migration strategy: part.0144: - Add new "enabled" field to PartParameterTemplate model - Add new ContentType fields to the "PartParameterTemplate" and "PartParameter" models - Data migration for existing "PartParameter" records part.0145: - Set NOT NULL constraints on new fields - Remove the obsolete "part" field from the "PartParameter" model * More migration updates: - Create new "models" (without moving the existing tables) - Data migration for PartCataegoryParameterTemplate model - Remove PartParameterTemplate and PartParameter models * Overhaul of migration strategy - New models simply point to the old database tables - Perform schema and data migrations on the old models first (in the part app) - Swap model references in correct order * Improve checks for data migrations * Bug fix for data migration * Add migration unit test to ensure that primary keys are maintained * Add playwright test for company parameters * Rename underlying database tables * Fixes for migration unit tests * Revert "Rename underlying database tables" This reverts commit477c692076. * Fix for migration sequencing * Simplify new playwright test * Remove spectacular collision * Monkey patch the drf-spectacular warn function * Do not use custom branch for playwright testing --------- Co-authored-by: Matthias Mair <code@mjmair.com>
13 KiB
title
| title |
|---|
| Docker Production Server |
Docker Production Server
The following guide provides a streamlined production InvenTree installation, with minimal configuration required.
!!! tip "Docker Installation" This guide assumes that you have already installed Docker and Docker Compose. If you have not yet installed Docker, please refer to the official installation guide.
!!! info "Starting Point" This setup guide should be considered a starting point - your particular production requirements vary from the example shown here.
!!! tip "Docker Theory" Refer to the docker theory section for more information about how our docker installation works under the hood.
Before You Start
!!! warning "Check the version" Please make sure you are reading the STABLE documentation when using the stable docker image tags.
!!! warning "Docker Knowledge Required" This guide assumes that you are reasonably comfortable with the basic concepts of docker and docker compose.
Frequently Asked Questions
If you encounter any issues during the installation process, please refer first to the FAQ for common problems and solutions.
Docker Installation
Required Files
The following files required for this setup are provided with the InvenTree source, located in the contrib/container/ directory of the [InvenTree source code]({{ sourcedir("/contrib/container/") }}):
| Filename | Description |
|---|---|
| [docker-compose.yml]({{ sourcefile("contrib/container/docker-compose.yml", raw=True) }}) | The docker compose script |
| [.env]({{ sourcefile("contrib/container/.env", raw=True) }}) | Environment variables |
| [Caddyfile]({{ sourcefile("contrib/container/Caddyfile", raw=True) }}) | Caddy configuration file |
Download these files to a directory on your local machine.
!!! warning "File Extensions" If your computer adds .txt extensions to any of the downloaded files, rename the file and remove the added extension before continuing!
!!! success "Working Directory" This tutorial assumes you are working from a directory where all of these files are located.
!!! tip "No Source Required" For a production setup you do not need the InvenTree source code. Simply download the three required files from the links above!
Edit Environment Variables
The first step is to edit the environment variables, located in the .env file.
!!! warning "External Volume"
You must define the INVENTREE_EXT_VOLUME variable - this must point to a directory on your local machine where persistent data is to be stored.
!!! warning "Database Credentials"
You must also define the database username (INVENTREE_DB_USER) and password (INVENTREE_DB_PASSWORD). You should ensure they are changed from the default values for added security
!!! info "Other Variables" There are a number of other environment variables which can be set to customize the InvenTree installation. Refer to the environment variables documentation for more information.
Initial Database Setup
Perform the initial database setup by running the following command:
docker compose run --rm inventree-server invoke update
This command performs the following steps:
- Ensure required python packages are installed
- Create a new (empty) database
- Perform the required schema updates to create the required database tables
- Update translation files
- Update required static files
Create Administrator Account
If you are creating the initial database, you need to create an admin (superuser) account for the database. Run the command below, and follow the prompts:
docker compose run inventree-server invoke superuser
Alternatively, admin account details can be specified in the .env file, removing the need for this manual step:
| Variable | Description |
|---|---|
| INVENTREE_ADMIN_USER | Admin account username |
| INVENTREE_ADMIN_PASSWORD | Admin account password |
| INVENTREE_ADMIN_EMAIL | Admin account email address |
!!! warning "Scrub Account Data"
Ensure that the admin account credentials are removed from the .env file after the first run, for security.
Start Docker Containers
Now that the database has been created, migrations applied, and you have created an admin account, we are ready to launch the InvenTree containers:
docker compose up -d
This command launches the following containers:
inventree-db- PostgreSQL databaseinventree-server- InvenTree web serverinventree-worker- Background workerinventree-proxy- Caddy reverse proxyinventree-cache- Redis cache
!!! success "Up and Running!"
You should now be able to view the InvenTree login screen at http://inventree.localhost (or whatever custom domain you have configured in the .env file).
!!! tip "External Access"
Note that http://inventree.localhost will only be available from the machine you are running the code on. To make it accessible externally, change INVENTREE_SITE_URL to a host address which can be accessed by other computers on your network.
Updating InvenTree
To update your InvenTree installation to the latest version, follow these steps:
Stop Containers
Stop all running containers as below:
docker compose down
Update Images
Pull down the latest version of the InvenTree docker image
docker compose pull
This ensures that the InvenTree containers will be running the latest version of the InvenTree source code.
!!! tip "Docker Directory"
All docker compose commands must be performed in the same directory as the docker-compose.yml file
!!! info "Tagged Version"
If you are targeting a particular "tagged" version of InvenTree, you may wish to edit the INVENTREE_TAG variable in the .env file before issuing the docker compose pull command
Update Database
Run the following command to ensure that the InvenTree database is updated:
docker compose run --rm inventree-server invoke update
!!! info "Skip Backup"
By default, the invoke update command performs a database backup. To skip this step, add the --skip-backup flag
Start Containers
Now restart the docker containers:
docker compose up -d
Data Backup
Database and media files are stored external to the container, in the volume location specified in the docker-compose.yml file. It is strongly recommended that a backup of the files in this volume is performed on a regular basis.
Read more about data backup.
Exporting Database as JSON
To export the database to an agnostic JSON file, perform the following command:
docker compose run --rm inventree-server invoke export-records -f /home/inventree/data/data.json
This will export database records to the file data.json in your mounted volume directory.
Viewing Logs
To view the logs for the InvenTree container(s), use the following command:
docker compose logs
To view the logs for a specific container, use the following command:
docker compose logs <container-name>
e.g.
docker compose logs inventree-server
You can also "follow" the logs in real time, using the -f flag:
docker compose logs -f
Further Configuration
Check your security posture
It is recommended to check the threat modelling inputs to ensure that your InvenTree installation is set up in the way that it is assumed in the software design.
Custom Domain
By default, the InvenTree server is accessible at http://inventree.localhost. If you wish to use a custom domain, you can edit the .env environment file to specify the domain name.
Look for the INVENTREE_SITE_URL variable, and set it to the desired domain name.
!!! tip "Configuration Options" There are a number of other environment variables which can be set to customize the InvenTree installation. Refer to the configuration documentation for more information.
SSL Configuration
The provided Caddyfile configuration file is setup to enable Automatic HTTPS "out of the box". All you have to do is specify a https:// URL in the INVENTREE_SITE_URL variable.
The Caddy container will automatically generate SSL certificates for your domain.
Persistent Files
Any persistent files generated by the Caddy container (such as certificates, etc) will be stored in the caddy directory within the external volume.
Web Server Bind Address
By default, the Dockerized InvenTree web server binds to all available network interfaces and listens for IPv4 traffic on port 8000. This can be adjusted using the following environment variables:
| Environment Variable | Default | ||
|---|---|---|---|
| INVENTREE_WEB_ADDR | 0.0.0.0 | ||
| INVENTREE_WEB_PORT | 8000 |
These variables are combined in the [Dockerfile]({{ sourcefile("contrib/container/Dockerfile") }}) to build the bind string passed to the InvenTree server on startup.
!!! tip "IPv6 Support"
To enable IPv6/Dual Stack support, set INVENTREE_WEB_ADDR to [::] when you create/start the container.
Demo Dataset
To quickly get started with a demo dataset, you can run the following command:
docker compose run --rm inventree-server invoke dev.setup-test -i
This will install the InvenTree demo dataset into your instance.
To start afresh (and completely remove the existing database), run the following command:
docker compose run --rm inventree-server invoke dev.delete-data
Install custom packages
To install custom packages to your docker image, a custom docker image can be built and used automatically each time when updating. The following changes need to be applied to the docker compose file:
docker-compose.yml changes
diff --git a/docker-compose.yml b/docker-compose.yml
index 8adee63..dc3993c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -69,7 +69,14 @@ services:
# Uses gunicorn as the web server
inventree-server:
# If you wish to specify a particular InvenTree version, do so here
- image: inventree/inventree:${INVENTREE_TAG:-stable}
+ image: inventree/inventree:${INVENTREE_TAG:-stable}-custom
+ pull_policy: never
+ build:
+ context: .
+ dockerfile: Dockerfile
+ target: production
+ args:
+ INVENTREE_TAG: ${INVENTREE_TAG:-stable}
# Only change this port if you understand the stack.
# If you change this you have to change:
# - the proxy settings (on two lines)
@@ -88,7 +95,8 @@ services:
# Background worker process handles long-running or periodic tasks
inventree-worker:
# If you wish to specify a particular InvenTree version, do so here
- image: inventree/inventree:${INVENTREE_TAG:-stable}
+ image: inventree/inventree:${INVENTREE_TAG:-stable}-custom
+ pull_policy: never
command: invoke worker
depends_on:
- inventree-server
And the following Dockerfile needs to be created:
Dockerfile
ARG INVENTREE_TAG
FROM inventree/inventree:${INVENTREE_TAG} as production
# Install whatever dependency is needed here (e.g. git)
RUN apk add --no-cache git
And if additional, development packages are needed e.g. just for building a wheel for a pip package, a multi stage build can be used with the following Dockerfile:
Dockerfile
ARG INVENTREE_TAG
# prebuild stage - needs a lot of build dependencies
# make sure, the alpine and python version matches the version used in the inventree base image
FROM python:3.11-alpine3.18 as prebuild
# Install whatever development dependency is needed (e.g. cups-dev, gcc, the musl-dev build tools and the pip pycups package)
RUN apk add --no-cache cups-dev gcc musl-dev && \
pip install --user --no-cache-dir pycups
# production image - only install the cups shared library
FROM inventree/inventree:${INVENTREE_TAG} as production
# Install e.g. shared library later available in the final image
RUN apk add --no-cache cups-libs
# Copy the pip wheels from the build stage in the production stage
COPY --from=prebuild /root/.local /root/.local