Zeigren / inventree-docker

Docker Stack For InvenTree A Open Source Inventory Management System
11 stars 5 forks source link
docker docker-compose docker-swarm electronics inventory inventory-management parts parts-management

Docker Stack For InvenTree

Docker Image Size (latest) Docker Pulls

Usage

Use Docker Compose or Docker Swarm to deploy for either development or production. Templates included for using NGINX or Traefik for SSL termination.

Tags

Tags follow this naming scheme:

Using one of the Release Tags is recommended as the other tags are untested and may not work properly.

Release Tags

Links

Docker Hub

GitHub

Stack

For Development

Configuration

Configuration consists of environment variables in the .yml and .conf files.

Using NGINX for SSL Termination

Docker Compose

Using multiple Docker Compose files makes it easier to differentiate between use cases. docker-compose.yml is the base configuration file and production.yml or development.yml are used to either add to or override the base configuration.

Clone the repository, create a config folder inside the inventree-docker directory, and put the relevant configuration files you created/modified into it.

Run with docker-compose -f docker-compose.yml -f production.yml up -d. View using 127.0.0.1:9080.

Docker Swarm

I personally use this with Traefik as a reverse proxy, I've included an example traefik.yml but it's not necessary.

You'll need to create the appropriate Docker Secrets and Docker Configs.

Run with docker stack deploy --compose-file docker-swarm.yml inventree

Deployment

On first run you'll need to create a superuser using the variables in the .yml file.

Theory of operation

InvenTree

The Dockerfile uses multi-stage builds, build hooks, and labels for automated builds on Docker Hub.

The multi-stage build creates a container that can be used for development and another for production. The development container has all the build dependencies for the python packages which are installed into a python virtual environment. The production container copies the python virtual environment from the development container and runs InvenTree from there, this allows it to be much more lightweight.

On startup, the container first runs the docker-entrypoint.sh script before running the gunicorn -c gunicorn.conf.py InvenTree.wsgi command.

docker-entrypoint.sh creates configuration files and runs commands based on environment variables that are declared in the various .yml files.

env_secrets_expand.sh handles using Docker Secrets.

Nginx

Used as a web server. It serves up the static files and passes everything else off to gunicorn/InvenTree.

MariaDB

SQL database.

Development

Run

Clone the InvenTree repository into a folder called InvenTree and build the development Docker image by running docker build . --target development -t inventree:development. Then use docker-compose -f docker-compose.yml -f development.yml up -d to grab all the other Docker images and run InvenTree.

InvenTree Development

The clone you made of InvenTree replaces the one in the Docker container when the container is started (as seen in development.yml). So any changes you make are reflected in the Docker container (you may need to restart the container for those changes to take effect).

If you want to develop/test using the production container you can build it using docker build . --target production -t inventree:production, then change the image tag in development.yml.

Python

If you need to change which python packages are installed you can create/alter the dev_requirements.txt file and uncomment the line in the Dockerfile. Then run docker build . --target development -t inventree:development to rebuild the container, this will install dev_requirements.txt instead of the default InvenTree requirements.txt.

Docs

If you installed the required packages using dev_requirements.txt you can make the docs by running docker exec -it inventree -w /usr/src/app make docs.

phpMyAdmin

Useful for database administration, you can connect to phpMyAdmin at 127.0.0.1:6060.

VSCode

You can use VSCode to work in the container directly on either your computer or a remote one. I've included a sample devcontainer.json for that purpose. You'll need to check the official documentation to set that up.