mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Merge pull request #1569 from SchrodingersGat/docker-dev
Development docker image
This commit is contained in:
commit
07c7af1f2e
1
.github/workflows/docker_build.yaml
vendored
1
.github/workflows/docker_build.yaml
vendored
@ -30,6 +30,7 @@ jobs:
|
|||||||
context: ./docker
|
context: ./docker
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
push: true
|
push: true
|
||||||
|
target: production
|
||||||
repository: inventree/inventree
|
repository: inventree/inventree
|
||||||
tags: inventree/inventree:latest
|
tags: inventree/inventree:latest
|
||||||
- name: Image Digest
|
- name: Image Digest
|
||||||
|
1
.github/workflows/docker_publish.yaml
vendored
1
.github/workflows/docker_publish.yaml
vendored
@ -28,4 +28,5 @@ jobs:
|
|||||||
repository: inventree/inventree
|
repository: inventree/inventree
|
||||||
tag_with_ref: true
|
tag_with_ref: true
|
||||||
dockerfile: ./Dockerfile
|
dockerfile: ./Dockerfile
|
||||||
|
target: production
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,6 +31,7 @@ var/
|
|||||||
*.log
|
*.log
|
||||||
local_settings.py
|
local_settings.py
|
||||||
*.sqlite3
|
*.sqlite3
|
||||||
|
*.sqlite3-journal
|
||||||
*.backup
|
*.backup
|
||||||
*.old
|
*.old
|
||||||
|
|
||||||
|
@ -431,11 +431,15 @@ It can be specified in config.yaml (or envvar) as either (for example):
|
|||||||
- django.db.backends.postgresql
|
- django.db.backends.postgresql
|
||||||
"""
|
"""
|
||||||
|
|
||||||
db_engine = db_config['ENGINE']
|
db_engine = db_config['ENGINE'].lower()
|
||||||
|
|
||||||
if db_engine.lower() in ['sqlite3', 'postgresql', 'mysql']:
|
# Correct common misspelling
|
||||||
|
if db_engine == 'sqlite':
|
||||||
|
db_engine = 'sqlite3'
|
||||||
|
|
||||||
|
if db_engine in ['sqlite3', 'postgresql', 'mysql']:
|
||||||
# Prepend the required python module string
|
# Prepend the required python module string
|
||||||
db_engine = f'django.db.backends.{db_engine.lower()}'
|
db_engine = f'django.db.backends.{db_engine}'
|
||||||
db_config['ENGINE'] = db_engine
|
db_config['ENGINE'] = db_engine
|
||||||
|
|
||||||
db_name = db_config['NAME']
|
db_name = db_config['NAME']
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM python:alpine as production
|
FROM python:alpine as base
|
||||||
|
|
||||||
# GitHub source
|
# GitHub source
|
||||||
ARG repository="https://github.com/inventree/InvenTree.git"
|
ARG repository="https://github.com/inventree/InvenTree.git"
|
||||||
@ -73,6 +73,7 @@ RUN pip install --no-cache-dir -U invoke
|
|||||||
RUN pip install --no-cache-dir -U psycopg2 mysqlclient pgcli mariadb
|
RUN pip install --no-cache-dir -U psycopg2 mysqlclient pgcli mariadb
|
||||||
RUN pip install --no-cache-dir -U gunicorn
|
RUN pip install --no-cache-dir -U gunicorn
|
||||||
|
|
||||||
|
FROM base as production
|
||||||
# Clone source code
|
# Clone source code
|
||||||
RUN echo "Downloading InvenTree from ${INVENTREE_REPO}"
|
RUN echo "Downloading InvenTree from ${INVENTREE_REPO}"
|
||||||
RUN git clone --branch ${INVENTREE_BRANCH} --depth 1 ${INVENTREE_REPO} ${INVENTREE_SRC_DIR}
|
RUN git clone --branch ${INVENTREE_BRANCH} --depth 1 ${INVENTREE_REPO} ${INVENTREE_SRC_DIR}
|
||||||
@ -85,11 +86,9 @@ COPY gunicorn.conf.py ${INVENTREE_HOME}/gunicorn.conf.py
|
|||||||
|
|
||||||
# Copy startup scripts
|
# Copy startup scripts
|
||||||
COPY start_prod_server.sh ${INVENTREE_SRC_DIR}/start_prod_server.sh
|
COPY start_prod_server.sh ${INVENTREE_SRC_DIR}/start_prod_server.sh
|
||||||
COPY start_dev_server.sh ${INVENTREE_SRC_DIR}/start_dev_server.sh
|
|
||||||
COPY start_worker.sh ${INVENTREE_SRC_DIR}/start_worker.sh
|
COPY start_worker.sh ${INVENTREE_SRC_DIR}/start_worker.sh
|
||||||
|
|
||||||
RUN chmod 755 ${INVENTREE_SRC_DIR}/start_prod_server.sh
|
RUN chmod 755 ${INVENTREE_SRC_DIR}/start_prod_server.sh
|
||||||
RUN chmod 755 ${INVENTREE_SRC_DIR}/start_dev_server.sh
|
|
||||||
RUN chmod 755 ${INVENTREE_SRC_DIR}/start_worker.sh
|
RUN chmod 755 ${INVENTREE_SRC_DIR}/start_worker.sh
|
||||||
|
|
||||||
# exec commands should be executed from the "src" directory
|
# exec commands should be executed from the "src" directory
|
||||||
@ -97,3 +96,17 @@ WORKDIR ${INVENTREE_SRC_DIR}
|
|||||||
|
|
||||||
# Let us begin
|
# Let us begin
|
||||||
CMD ["bash", "./start_prod_server.sh"]
|
CMD ["bash", "./start_prod_server.sh"]
|
||||||
|
|
||||||
|
FROM base as dev
|
||||||
|
|
||||||
|
# The development image requires the source code to be mounted to /home/inventree/src/
|
||||||
|
# So from here, we don't actually "do" anything
|
||||||
|
|
||||||
|
WORKDIR ${INVENTREE_SRC_DIR}
|
||||||
|
|
||||||
|
COPY start_dev_server.sh ${INVENTREE_HOME}/start_dev_server.sh
|
||||||
|
COPY start_dev_worker.sh ${INVENTREE_HOME}/start_dev_worker.sh
|
||||||
|
RUN chmod 755 ${INVENTREE_HOME}/start_dev_server.sh
|
||||||
|
RUN chmod 755 ${INVENTREE_HOME}/start_dev_worker.sh
|
||||||
|
|
||||||
|
CMD ["bash", "/home/inventree/start_dev_server.sh"]
|
||||||
|
7
docker/dev-config.env
Normal file
7
docker/dev-config.env
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
INVENTREE_DB_ENGINE=sqlite3
|
||||||
|
INVENTREE_DB_NAME=/home/inventree/src/inventree_docker_dev.sqlite3
|
||||||
|
INVENTREE_MEDIA_ROOT=/home/inventree/src/inventree_media
|
||||||
|
INVENTREE_STATIC_ROOT=/home/inventree/src/inventree_static
|
||||||
|
INVENTREE_CONFIG_FILE=/home/inventree/src/config.yaml
|
||||||
|
INVENTREE_SECRET_KEY_FILE=/home/inventree/src/secret_key.txt
|
||||||
|
INVENTREE_DEBUG=true
|
59
docker/docker-compose.dev.yml
Normal file
59
docker/docker-compose.dev.yml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
# Docker compose recipe for InvenTree development server
|
||||||
|
# - Runs sqlite3 as the database backend
|
||||||
|
# - Uses built-in 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-server:
|
||||||
|
container_name: inventree-server
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: dev
|
||||||
|
ports:
|
||||||
|
- 8000:8000
|
||||||
|
volumes:
|
||||||
|
# Ensure you specify the location of the 'src' directory at the end of this file
|
||||||
|
- src:/home/inventree/src
|
||||||
|
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-worker:
|
||||||
|
container_name: inventree-worker
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
target: dev
|
||||||
|
entrypoint: /home/inventree/start_dev_worker.sh
|
||||||
|
depends_on:
|
||||||
|
- inventree-server
|
||||||
|
volumes:
|
||||||
|
# Ensure you specify the location of the 'src' directory at the end of this file
|
||||||
|
- src:/home/inventree/src
|
||||||
|
env_file:
|
||||||
|
# Environment variables required for the dev server are configured in dev-config.env
|
||||||
|
- dev-config.env
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
# NOTE: Change /path/to/src 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
|
||||||
|
# Note: This directory must conatin the file *manage.py*
|
||||||
|
device: /path/to/inventree/src
|
@ -19,6 +19,14 @@ else
|
|||||||
cp $INVENTREE_SRC_DIR/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE
|
cp $INVENTREE_SRC_DIR/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Setup a virtual environment
|
||||||
|
python3 -m venv inventree-docker-dev
|
||||||
|
|
||||||
|
source inventree-docker-dev/bin/activate
|
||||||
|
|
||||||
|
echo "Installing required packages..."
|
||||||
|
pip install --no-cache-dir -U -r ${INVENTREE_SRC_DIR}/requirements.txt
|
||||||
|
|
||||||
echo "Starting InvenTree server..."
|
echo "Starting InvenTree server..."
|
||||||
|
|
||||||
# Wait for the database to be ready
|
# Wait for the database to be ready
|
||||||
@ -27,16 +35,14 @@ python manage.py wait_for_db
|
|||||||
|
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
echo "Running InvenTree database migrations and collecting static files..."
|
echo "Running InvenTree database migrations..."
|
||||||
|
|
||||||
# We assume at this stage that the database is up and running
|
# We assume at this stage that the database is up and running
|
||||||
# Ensure that the database schema are up to date
|
# Ensure that the database schema are up to date
|
||||||
python manage.py check || exit 1
|
python manage.py check || exit 1
|
||||||
python manage.py migrate --noinput || exit 1
|
python manage.py migrate --noinput || exit 1
|
||||||
python manage.py migrate --run-syncdb || exit 1
|
python manage.py migrate --run-syncdb || exit 1
|
||||||
python manage.py prerender || exit 1
|
|
||||||
python manage.py collectstatic --noinput || exit 1
|
|
||||||
python manage.py clearsessions || exit 1
|
python manage.py clearsessions || exit 1
|
||||||
|
|
||||||
# Launch a development server
|
# Launch a development server
|
||||||
python manage.py runserver -a 0.0.0.0:$INVENTREE_WEB_PORT
|
python manage.py runserver 0.0.0.0:$INVENTREE_WEB_PORT
|
||||||
|
19
docker/start_dev_worker.sh
Normal file
19
docker/start_dev_worker.sh
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "Starting InvenTree worker..."
|
||||||
|
|
||||||
|
cd $INVENTREE_SRC_DIR
|
||||||
|
|
||||||
|
# Activate virtual environment
|
||||||
|
source inventree-docker-dev/bin/activate
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# Wait for the database to be ready
|
||||||
|
cd $INVENTREE_MNG_DIR
|
||||||
|
python manage.py wait_for_db
|
||||||
|
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
# Now we can launch the background worker process
|
||||||
|
python manage.py qcluster
|
Loading…
x
Reference in New Issue
Block a user