diff --git a/Dockerfile b/Dockerfile index 9ab4b9e3df..6d6798f5d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -109,6 +109,11 @@ COPY src ${INVENTREE_HOME}/src COPY tasks.py ${INVENTREE_HOME}/tasks.py RUN cd ${INVENTREE_HOME}/InvenTree && inv frontend-compile +COPY execute.sh ${INVENTREE_HOME}/execute.sh +RUN chmod +x ${INVENTREE_HOME}/execute.sh + +COPY db_version ${INVENTREE_HOME}/db_version + # InvenTree production image: # - Copies required files from local directory # - Starts a gunicorn webserver @@ -163,7 +168,7 @@ WORKDIR ${INVENTREE_HOME} ENTRYPOINT ["/bin/ash", "./docker/init.sh"] # Launch the development server -CMD ["invoke", "server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"] +CMD ${INVENTREE_HOME}/execute.sh # Image target for devcontainer FROM dev as devcontainer diff --git a/db_version b/db_version new file mode 100644 index 0000000000..20adfac7f5 --- /dev/null +++ b/db_version @@ -0,0 +1 @@ +0.15 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a1fedaa017..9f7d3fe6a9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,7 +35,7 @@ services: # InvenTree web server service # Runs the django built-in webserver application - inventree-dev-server: + inventree-dev: depends_on: - inventree-dev-db build: &build_config @@ -53,16 +53,3 @@ services: - docker.dev.env restart: unless-stopped - # Background worker process handles long-running or periodic tasks - inventree-dev-worker: - image: inventree-dev-image - build: *build_config - command: invoke worker - depends_on: - - inventree-dev-server - volumes: - # Mount local source directory to /home/inventree - - ./:/home/inventree:z - env_file: - - docker.dev.env - restart: unless-stopped diff --git a/execute.sh b/execute.sh new file mode 100755 index 0000000000..8272f7f10c --- /dev/null +++ b/execute.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# File to check existence +db_version_old="${INVENTREE_HOME}/db_version.old" +db_version_new="${INVENTREE_HOME}/db_version" + +# Check if the file exists +if [ ! -e "$db_version_old" ]; then + echo "New Installation DB is getting initialised" + # Run setup command + invoke update || exit 2 + + echo "Setup command completed." + cp "$db_version_new" "$db_version_old" +fi +old_version=$(cat "$db_version_old") +new_version=$(cat "$db_version_new") +echo "old version $old_version" +echo "new version $new_version" +# Number to compare (replace with your actual value) + +# Check if the stored version is smaller than new one +if [ "$(awk -v num1=$new_version -v num2=$old_version 'BEGIN { print (num1 < num2) }')" -eq 1 ]; then + echo "Error: Downgrade of version is not allowed." + echo "Old DB version was $old_version, and the new version is $new_version" + exit 1 +fi + +if [ "$(awk -v num1=$old_version -v num2=$new_version 'BEGIN { print (num1 < num2) }')" -eq 1 ]; then + echo "DB upgrade available: Version was $old_version, new version is $new_version" + + # Run update command + invoke update || exit 2 + + echo "Update successful" + + # Copy the old version to the new version after update + cp "$db_version_new" "$db_version_old" +fi + + +# Run invoke server in the background +invoke server -a "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}" | sed "s/^/server: /" & + +# Store the PID of the last background process (invoke server) +server_pid=$! + +# Run invoke worker in the background +invoke worker | sed "s/^/worker: /" & + +# Store the PID of the last background process (invoke worker) +worker_pid=$! + +# Wait for both processes to finish +wait $server_pid +wait $worker_pid + +echo "Both processes have completed."