mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 19:15:41 +00:00
[WIP] docker / Caddy (#6551)
* remove docker-sqlite file - Do not want to encourage use of sqlite * Add Caddyfile * Add default site URL to .env - Matches Caddyfile * Cleanup / simplify .env file * Remove dev nginx conf file * Further cleanup of .env file * Update docker-compose.yml - Use caddy image instead of nginx as proxy * Set max body size * gunicorn: enable external logging * Update file structure * Cleanup docker-compose file * Update docker/docker-compose.yml Co-authored-by: Matthias Mair <code@mjmair.com> * Update docker/Caddyfile Co-authored-by: Matthias Mair <code@mjmair.com> * Fix for postgresql packages - Need postgresql13-client to be installed, it contains pg_dump - Without this, backup / restore *does not work* * Create static_i18n dir if it does not exist * Reduce output from collectstatic * Revert gunicorn logging - Want to see the logs in docker * Fix trailing slash Ref: https://github.com/inventree/InvenTree/pull/6551#issuecomment-1962423765 * tasks.py - pass 'nouv' option through * Update package requirements: - Allow installation of rapidfuzz without building * Install uv as part of docker image * Add environment variable to control downstream URL * Do not use uv package manager by default - Currently does not work "correctly" - ignores installed packages - Requires further work to run reliably * Fix docker-compose file - Do not build locally * Cleanup gunicorn file - Remove unused lien * Cleanup docker-compose.yml - Simpler volume management * Update Caddyfile Add newline * Update requirements.txt Add newline * Update tasks.py Add missing blank line * Simplify Caddyfile * Adds option for customizing web port * cleanup docker-compose.yml - Better mapping of caddy data - Cleaner volume setup * Add django version template - Ensure all docs links point to the current django version we are using * docs: cleanup intro.md * Cleanup serving_files.md * Cleanup config.md * docker install docs updates * Enable code block copying * Fix include file * Fix link * Update docker install docs * Update docker.md * Add info about demo dataset * Tweak heading * Update docs link checks * Fix workflow * Another fix * More ignore pattearns --------- Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
@ -1,16 +1,8 @@
|
||||
# InvenTree environment variables for a postgresql production setup
|
||||
# InvenTree environment variables for docker compose deployment
|
||||
|
||||
# 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/inventree/data
|
||||
|
||||
# e.g. Windows (docker desktop)
|
||||
#INVENTREE_EXT_VOLUME=c:/Users/inventree/data
|
||||
|
||||
# Default web port for the InvenTree server
|
||||
INVENTREE_WEB_PORT=1337
|
||||
# Specify the location of the external data volume
|
||||
# By default, placed in local directory 'inventree-data'
|
||||
INVENTREE_EXT_VOLUME=./inventree-data
|
||||
|
||||
# Ensure debug is false for a production setup
|
||||
INVENTREE_DEBUG=False
|
||||
@ -23,16 +15,14 @@ INVENTREE_LOG_LEVEL=WARNING
|
||||
#INVENTREE_ADMIN_EMAIL=
|
||||
|
||||
# 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
|
||||
|
||||
# Database credentials - These must be configured before running
|
||||
# Uncomment the lines below, and change from the default values!
|
||||
#INVENTREE_DB_USER=pguser
|
||||
#INVENTREE_DB_PASSWORD=pgpassword
|
||||
# Database credentials - These should be changed from the default values!
|
||||
INVENTREE_DB_USER=pguser
|
||||
INVENTREE_DB_PASSWORD=pgpassword
|
||||
|
||||
# Redis cache setup (disabled by default)
|
||||
# Un-comment the following lines to enable Redis cache
|
||||
@ -45,12 +35,15 @@ INVENTREE_DB_PORT=5432
|
||||
INVENTREE_GUNICORN_TIMEOUT=90
|
||||
|
||||
# Enable custom plugins?
|
||||
INVENTREE_PLUGINS_ENABLED=False
|
||||
INVENTREE_PLUGINS_ENABLED=True
|
||||
|
||||
# Run migrations automatically?
|
||||
INVENTREE_AUTO_UPDATE=False
|
||||
INVENTREE_AUTO_UPDATE=True
|
||||
|
||||
# Image tag that should be used
|
||||
INVENTREE_TAG=stable
|
||||
|
||||
COMPOSE_PROJECT_NAME=inventree-production
|
||||
# Site URL - update this to match your host (and update the Caddyfile too!)
|
||||
INVENTREE_SITE_URL="http://inventree.localhost"
|
||||
|
||||
COMPOSE_PROJECT_NAME=inventree
|
36
docker/Caddyfile
Normal file
36
docker/Caddyfile
Normal file
@ -0,0 +1,36 @@
|
||||
# Caddyfile for Inventree
|
||||
# The following environment variables may be used:
|
||||
# - INVENTREE_SITE_URL: The upstream URL of the Inventree site (default: inventree.localhost)
|
||||
# - INVENTREE_SERVER: The internal URL of the Inventree container (default: http://inventree-server:8000)
|
||||
|
||||
(log_common) {
|
||||
log {
|
||||
output file /var/log/caddy/{args.0}.access.log
|
||||
}
|
||||
}
|
||||
|
||||
# Change the host to your domain (this will serve at inventree.localhost)
|
||||
{$INVENTREE_SITE_URL:inventree.localhost} {
|
||||
import log_common inventree
|
||||
|
||||
encode gzip
|
||||
|
||||
request_body {
|
||||
max_size 100MB
|
||||
}
|
||||
|
||||
handle_path /static/* {
|
||||
root * /var/www/static
|
||||
file_server
|
||||
}
|
||||
|
||||
handle_path /media/* {
|
||||
forward_auth {$INVENTREE_SERVER:"http://inventree-server:8000"} {
|
||||
uri /auth/
|
||||
}
|
||||
root * /var/www/media
|
||||
file_server
|
||||
}
|
||||
|
||||
reverse_proxy {$INVENTREE_SERVER:"http://inventree-server:8000"}
|
||||
}
|
@ -1,64 +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
|
||||
|
||||
# IMPORTANT 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
|
||||
# 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
|
||||
volumes:
|
||||
# Ensure you specify the location of the 'src' directory at the end of this file
|
||||
- src:/home/inventree
|
||||
environment:
|
||||
- INVENTREE_DEBUG=True
|
||||
- INVENTREE_DB_ENGINE=sqlite
|
||||
- INVENTREE_DB_NAME=/home/inventree/db.sqlite3
|
||||
restart: unless-stopped
|
||||
|
||||
# Background worker process handles long-running or periodic tasks
|
||||
inventree-dev-worker:
|
||||
container_name: inventree-dev-worker
|
||||
image: inventree-dev-image
|
||||
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
|
||||
environment:
|
||||
- INVENTREE_DEBUG=True
|
||||
- INVENTREE_DB_ENGINE=sqlite
|
||||
- INVENTREE_DB_NAME=/home/inventree/db.sqlite3
|
||||
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: ${INVENTREE_EXT_VOLUME:-../}
|
@ -39,6 +39,7 @@ services:
|
||||
# Use PostgreSQL as the database backend
|
||||
inventree-db:
|
||||
image: postgres:13
|
||||
container_name: inventree-db
|
||||
expose:
|
||||
- ${INVENTREE_DB_PORT:-5432}/tcp
|
||||
environment:
|
||||
@ -48,13 +49,14 @@ services:
|
||||
- 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/:z
|
||||
- ${INVENTREE_EXT_VOLUME:?You must specify the 'INVENTREE_EXT_VOLUME' variable in the .env file!}:/var/lib/postgresql/data/:z
|
||||
restart: unless-stopped
|
||||
|
||||
# redis acts as database cache manager
|
||||
# only runs under the "redis" profile : https://docs.docker.com/compose/profiles/
|
||||
inventree-cache:
|
||||
image: redis:7.0
|
||||
container_name: inventree-cache
|
||||
depends_on:
|
||||
- inventree-db
|
||||
profiles:
|
||||
@ -70,10 +72,8 @@ services:
|
||||
inventree-server:
|
||||
# If you wish to specify a particular InvenTree version, do so here
|
||||
image: inventree/inventree:${INVENTREE_TAG:-stable}
|
||||
container_name: inventree-server
|
||||
# Only change this port if you understand the stack.
|
||||
# If you change this you have to change:
|
||||
# - the proxy settings (on two lines)
|
||||
# - only change the exposed port - eg `1338:8000` if you want to expose the server on port 1338
|
||||
expose:
|
||||
- 8000
|
||||
depends_on:
|
||||
@ -82,13 +82,14 @@ services:
|
||||
- .env
|
||||
volumes:
|
||||
# Data volume must map to /home/inventree/data
|
||||
- inventree_data:/home/inventree/data:z
|
||||
- ${INVENTREE_EXT_VOLUME}:/home/inventree/data:z
|
||||
restart: unless-stopped
|
||||
|
||||
# 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}
|
||||
container_name: inventree-worker
|
||||
command: invoke worker
|
||||
depends_on:
|
||||
- inventree-server
|
||||
@ -96,37 +97,26 @@ services:
|
||||
- .env
|
||||
volumes:
|
||||
# Data volume must map to /home/inventree/data
|
||||
- inventree_data:/home/inventree/data:z
|
||||
- ${INVENTREE_EXT_VOLUME}:/home/inventree/data:z
|
||||
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!
|
||||
# caddy acts as reverse proxy and static file server
|
||||
# https://hub.docker.com/_/caddy
|
||||
inventree-proxy:
|
||||
image: nginx:stable
|
||||
container_name: inventree-proxy
|
||||
image: caddy:alpine
|
||||
restart: always
|
||||
depends_on:
|
||||
- inventree-server
|
||||
ports:
|
||||
- ${INVENTREE_WEB_PORT:-80}:80
|
||||
- 443:443
|
||||
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,z
|
||||
# nginx proxy needs access to static and media files
|
||||
- inventree_data:/var/www:z
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
# 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!}
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
||||
- ${INVENTREE_EXT_VOLUME}/static:/var/www/static:z
|
||||
- ${INVENTREE_EXT_VOLUME}/media:/var/www/media:z
|
||||
- ${INVENTREE_EXT_VOLUME}:/var/log:z
|
||||
- ${INVENTREE_EXT_VOLUME}:/data:z
|
||||
- ${INVENTREE_EXT_VOLUME}:/config:z
|
@ -7,5 +7,5 @@ apk add gcc g++ musl-dev openssl-dev libffi-dev cargo python3-dev openldap-dev \
|
||||
jpeg-dev openjpeg-dev libwebp-dev zlib-dev \
|
||||
sqlite sqlite-dev \
|
||||
mariadb-connector-c-dev mariadb-client mariadb-dev \
|
||||
postgresql13-dev postgresql-libs postgresql13-client \
|
||||
postgresql13-dev postgresql-libs \
|
||||
$@
|
||||
|
@ -1,66 +0,0 @@
|
||||
|
||||
server {
|
||||
|
||||
# Listen for connection on (internal) port 80
|
||||
listen 80;
|
||||
|
||||
real_ip_header proxy_protocol;
|
||||
|
||||
location / {
|
||||
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-By $server_addr:$server_port;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header CLIENT_IP $remote_addr;
|
||||
|
||||
proxy_pass_request_headers on;
|
||||
|
||||
proxy_redirect off;
|
||||
|
||||
client_max_body_size 100M;
|
||||
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
|
||||
# Change 'inventree-dev-server' to the name of the inventree server container,
|
||||
# and '8000' to the INVENTREE_WEB_PORT (if not default)
|
||||
proxy_pass http://inventree-dev-server:8000;
|
||||
|
||||
}
|
||||
|
||||
# Redirect any requests for static files
|
||||
location /static/ {
|
||||
alias /var/www/dev/static/;
|
||||
autoindex on;
|
||||
|
||||
# Caching settings
|
||||
expires 30d;
|
||||
add_header Pragma public;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
# Redirect any requests for media files
|
||||
location /media/ {
|
||||
alias /var/www/dev/media/;
|
||||
|
||||
# Media files require user authentication
|
||||
auth_request /auth;
|
||||
|
||||
# Content header to force download
|
||||
add_header Content-disposition "attachment";
|
||||
}
|
||||
|
||||
# Use the 'user' API endpoint for auth
|
||||
location /auth {
|
||||
internal;
|
||||
|
||||
proxy_pass http://inventree-dev-server:8000/auth/;
|
||||
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header X-Original-URI $request_uri;
|
||||
}
|
||||
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
|
||||
server {
|
||||
|
||||
# Listen for connection on (internal) port 80
|
||||
# If you are exposing this server to the internet, you should use HTTPS!
|
||||
# In which case, you should also set up a redirect from HTTP to HTTPS, and listen on port 443
|
||||
# See the Nginx documentation for more details
|
||||
listen 80;
|
||||
|
||||
real_ip_header proxy_protocol;
|
||||
|
||||
location / {
|
||||
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-By $server_addr:$server_port;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header CLIENT_IP $remote_addr;
|
||||
|
||||
proxy_pass_request_headers on;
|
||||
|
||||
proxy_redirect off;
|
||||
|
||||
client_max_body_size 100M;
|
||||
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
|
||||
# Do not touch this unless you have a specific reason - this and the docker-compose need to match
|
||||
proxy_pass http://inventree-server:8000;
|
||||
}
|
||||
|
||||
# Redirect any requests for static files
|
||||
location /static/ {
|
||||
alias /var/www/static/;
|
||||
autoindex on;
|
||||
|
||||
# Caching settings
|
||||
expires 30d;
|
||||
add_header Pragma public;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
|
||||
# Redirect any requests for media files
|
||||
location /media/ {
|
||||
alias /var/www/media/;
|
||||
|
||||
# Media files require user authentication
|
||||
auth_request /auth;
|
||||
|
||||
# Content header to force download
|
||||
add_header Content-disposition "attachment";
|
||||
}
|
||||
|
||||
# Use the 'user' API endpoint for auth
|
||||
location /auth {
|
||||
internal;
|
||||
|
||||
proxy_pass http://inventree-server:8000/auth/;
|
||||
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header X-Original-URI $request_uri;
|
||||
}
|
||||
|
||||
}
|
@ -17,3 +17,6 @@ gunicorn>=21.2.0
|
||||
# LDAP required packages
|
||||
django-auth-ldap # Django integration for ldap auth
|
||||
python-ldap # LDAP auth support
|
||||
|
||||
# Upgraded python package installer
|
||||
uv
|
||||
|
Reference in New Issue
Block a user