From 01328075eac6b428fa1d8ca776c05f1a3e6f7e09 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 15 Jun 2021 23:05:03 +1000 Subject: [PATCH] All "development" related stuff now goes under ./dev - Update dev-config.env - Update docker-compose.dev.yml - Development target of Dockerfile no longer creates any folders - Update entry point scripts --- .gitignore | 5 ++++- docker/Dockerfile | 13 +++++-------- docker/dev-config.env | 14 ++++++++------ docker/docker-compose.dev.yml | 20 ++++++++++---------- docker/start_dev_server.sh | 15 ++++++++------- docker/start_dev_worker.sh | 6 +++--- 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 7c360a8231..849cc21f2a 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,7 @@ secret_key.txt # Coverage reports .coverage -htmlcov/ \ No newline at end of file +htmlcov/ + +# Development files +.dev/ \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 5c5d1dc32a..9d85b8d4b6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -101,14 +101,11 @@ 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 +# The development image requires the source code to be mounted to /home/inventree/ +# So from here, we don't actually "do" anything, apart from some file management -WORKDIR ${INVENTREE_SRC_DIR} +ENV INVENTREE_DEV_DIR = "${INVENTREE_HOME}/dev" -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 +WORKDIR ${INVENTREE_HOME} -CMD ["bash", "/home/inventree/start_dev_server.sh"] +CMD ["bash", "/home/inventree/docker/start_dev_server.sh"] diff --git a/docker/dev-config.env b/docker/dev-config.env index 200c3db479..4d67c35da6 100644 --- a/docker/dev-config.env +++ b/docker/dev-config.env @@ -1,7 +1,9 @@ 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 \ No newline at end of file +INVENTREE_DB_NAME=/home/inventree/dev/inventree_db.sqlite3 +INVENTREE_MEDIA_ROOT=/home/inventree/dev/media +INVENTREE_STATIC_ROOT=/home/inventree/dev/static +INVENTREE_CONFIG_FILE=/home/inventree/dev/config.yaml +INVENTREE_SECRET_KEY_FILE=/home/inventree/dev/secret_key.txt +INVENTREE_DEBUG=true +INVENTREE_WEB_ADDR=127.0.0.1 +INVENTREE_WEB_PORT=8000 \ No newline at end of file diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index ddf50135c9..ee1ec101ca 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -13,8 +13,8 @@ version: "3.8" services: # InvenTree web server services # Uses gunicorn as the web server - inventree-server: - container_name: inventree-server + inventree-dev-server: + container_name: inventree-dev-server build: context: . target: dev @@ -22,7 +22,7 @@ services: - 8000:8000 volumes: # Ensure you specify the location of the 'src' directory at the end of this file - - src:/home/inventree/src + - src:/home/inventree env_file: # Environment variables required for the dev server are configured in dev-config.env - dev-config.env @@ -30,17 +30,17 @@ services: restart: unless-stopped # Background worker process handles long-running or periodic tasks - inventree-worker: - container_name: inventree-worker + inventree-dev-worker: + container_name: inventree-dev-worker build: context: . target: dev - entrypoint: /home/inventree/start_dev_worker.sh + entrypoint: /home/inventree/docker/start_dev_worker.sh depends_on: - - inventree-server + - inventree-dev-server volumes: # Ensure you specify the location of the 'src' directory at the end of this file - - src:/home/inventree/src + - src:/home/inventree env_file: # Environment variables required for the dev server are configured in dev-config.env - dev-config.env @@ -55,5 +55,5 @@ volumes: 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 + # By default, this directory is one level above the "docker" directory + device: ../ diff --git a/docker/start_dev_server.sh b/docker/start_dev_server.sh index d4e33a79a5..ad12ec023a 100644 --- a/docker/start_dev_server.sh +++ b/docker/start_dev_server.sh @@ -16,21 +16,22 @@ if test -f "$INVENTREE_CONFIG_FILE"; then echo "$INVENTREE_CONFIG_FILE exists - skipping" else echo "Copying config file to $INVENTREE_CONFIG_FILE" - cp $INVENTREE_SRC_DIR/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE + cp $INVENTREE_HOME/InvenTree/config_template.yaml $INVENTREE_CONFIG_FILE fi -# Setup a virtual environment -python3 -m venv inventree-docker-dev +# Setup a virtual environment (within the "dev" directory) +python3 -m venv ./dev/env -source inventree-docker-dev/bin/activate +# Activate the virtual environment +source ./dev/env/bin/activate echo "Installing required packages..." -pip install --no-cache-dir -U -r ${INVENTREE_SRC_DIR}/requirements.txt +pip install --no-cache-dir -U -r ${INVENTREE_HOME}/requirements.txt echo "Starting InvenTree server..." # Wait for the database to be ready -cd $INVENTREE_MNG_DIR +cd ${INVENTREE_HOME}/InvenTree python manage.py wait_for_db sleep 10 @@ -45,4 +46,4 @@ python manage.py migrate --run-syncdb || exit 1 python manage.py clearsessions || exit 1 # Launch a development server -python manage.py runserver 0.0.0.0:$INVENTREE_WEB_PORT +python manage.py runserver ${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT} diff --git a/docker/start_dev_worker.sh b/docker/start_dev_worker.sh index 099f447a9c..bfadc1f49a 100644 --- a/docker/start_dev_worker.sh +++ b/docker/start_dev_worker.sh @@ -2,15 +2,15 @@ echo "Starting InvenTree worker..." -cd $INVENTREE_SRC_DIR +cd $INVENTREE_HOME # Activate virtual environment -source inventree-docker-dev/bin/activate +source ./dev/env/bin/activate sleep 5 # Wait for the database to be ready -cd $INVENTREE_MNG_DIR +cd InvenTree python manage.py wait_for_db sleep 10