From 5205846b6286f25cb3e9b9da9d3b502f8a384e10 Mon Sep 17 00:00:00 2001 From: christian Date: Sun, 21 Jan 2024 14:30:28 +0100 Subject: [PATCH 01/12] first implementation of improved docker only devel version --- Dockerfile | 7 +++++- db_version | 1 + docker-compose.yml | 15 +----------- execute.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 db_version create mode 100755 execute.sh diff --git a/Dockerfile b/Dockerfile index 9ab4b9e3dfa9..6d6798f5d3da 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 000000000000..20adfac7f5a9 --- /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 a1fedaa0179b..9f7d3fe6a97b 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 000000000000..8272f7f10cd8 --- /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." From c7fae4c8e869e0777449d1675044de8bcf4a5c70 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Feb 2024 00:26:49 +0100 Subject: [PATCH 02/12] move execute skript --- Dockerfile | 2 +- execute.sh => docker/execute.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename execute.sh => docker/execute.sh (100%) diff --git a/Dockerfile b/Dockerfile index e657d415997a..dea7c60c6ff8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -103,7 +103,7 @@ 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 +COPY docker/execute.sh ${INVENTREE_HOME}/execute.sh RUN chmod +x ${INVENTREE_HOME}/execute.sh COPY db_version ${INVENTREE_HOME}/db_version diff --git a/execute.sh b/docker/execute.sh similarity index 100% rename from execute.sh rename to docker/execute.sh From 28d06a4c5da3aadf778ddf188d4cbad8fe308211 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Feb 2024 00:27:19 +0100 Subject: [PATCH 03/12] reintroduce seperate worker task --- docker-compose.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9f7d3fe6a97b..a1fedaa0179b 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: + inventree-dev-server: depends_on: - inventree-dev-db build: &build_config @@ -53,3 +53,16 @@ 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 From 34a25863b5ef6063164c42f8db4014bab5d22950 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Feb 2024 00:32:24 +0100 Subject: [PATCH 04/12] reset work command --- Dockerfile | 2 +- docker/execute.sh | 19 +------------------ 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index dea7c60c6ff8..89bc192e060a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -162,7 +162,7 @@ WORKDIR ${INVENTREE_HOME} ENTRYPOINT ["/bin/ash", "./docker/init.sh"] # Launch the development server -CMD ${INVENTREE_HOME}/execute.sh +CMD ["invoke", "server", "-a", "${INVENTREE_WEB_ADDR}:${INVENTREE_WEB_PORT}"] # Image target for devcontainer FROM dev as devcontainer diff --git a/docker/execute.sh b/docker/execute.sh index 8272f7f10cd8..b76dd5c35d86 100755 --- a/docker/execute.sh +++ b/docker/execute.sh @@ -38,21 +38,4 @@ if [ "$(awk -v num1=$old_version -v num2=$new_version 'BEGIN { print (num1 < num 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." +echo "Database migration/update checks completed." From 6c33c5f927e593ebd29da90e6892c967ba3ec110 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Feb 2024 00:35:40 +0100 Subject: [PATCH 05/12] run database checks only in server process --- docker/init.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker/init.sh b/docker/init.sh index 132a94379660..402b1f59afa4 100644 --- a/docker/init.sh +++ b/docker/init.sh @@ -52,5 +52,11 @@ fi cd ${INVENTREE_HOME} +# Check for database updates +if($2 == 'server') then + echo "Running database update checks" + source ./execute.sh +fi + # Launch the CMD *after* the ENTRYPOINT completes exec "$@" From c77809434fe07a45298139f6807b1a6956b3a0bc Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 2 Apr 2024 20:41:23 +0200 Subject: [PATCH 06/12] style fix --- db_version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db_version b/db_version index 20adfac7f5a9..2856407c03e6 100644 --- a/db_version +++ b/db_version @@ -1 +1 @@ -0.15 \ No newline at end of file +0.15 From fbca4c0e5951cbbbed50db50acb173c0672feff7 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Mon, 22 Jul 2024 09:58:52 +0200 Subject: [PATCH 07/12] Update Dockerfile --- contrib/container/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/container/Dockerfile b/contrib/container/Dockerfile index e31078ef70a2..1b4fee321b90 100644 --- a/contrib/container/Dockerfile +++ b/contrib/container/Dockerfile @@ -110,7 +110,7 @@ COPY src ${INVENTREE_HOME}/src COPY tasks.py ${INVENTREE_HOME}/tasks.py RUN cd ${INVENTREE_HOME} && inv frontend-compile -COPY docker/execute.sh ${INVENTREE_HOME}/execute.sh +COPY contrib/container/execute.sh ${INVENTREE_HOME}/execute.sh RUN chmod +x ${INVENTREE_HOME}/execute.sh COPY db_version ${INVENTREE_HOME}/db_version From 9a4216797aa1ec97da1d9ae526c87701faca7165 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Aug 2024 09:04:30 +0200 Subject: [PATCH 08/12] move to using api_version --- contrib/container/execute.sh | 9 ++++----- db_version | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 db_version diff --git a/contrib/container/execute.sh b/contrib/container/execute.sh index b76dd5c35d86..c6fa958694c9 100755 --- a/contrib/container/execute.sh +++ b/contrib/container/execute.sh @@ -2,7 +2,7 @@ # File to check existence db_version_old="${INVENTREE_HOME}/db_version.old" -db_version_new="${INVENTREE_HOME}/db_version" +new_version="$(python3 .github/scripts/version_check.py only_version)" # Check if the file exists if [ ! -e "$db_version_old" ]; then @@ -11,10 +11,9 @@ if [ ! -e "$db_version_old" ]; then invoke update || exit 2 echo "Setup command completed." - cp "$db_version_new" "$db_version_old" + echo "$db_version" > "$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) @@ -34,8 +33,8 @@ if [ "$(awk -v num1=$old_version -v num2=$new_version 'BEGIN { print (num1 < num echo "Update successful" - # Copy the old version to the new version after update - cp "$db_version_new" "$db_version_old" + # Write the the new version to the old version file after update + echo "$db_version" > "$db_version_old" fi echo "Database migration/update checks completed." diff --git a/db_version b/db_version deleted file mode 100644 index 2856407c03e6..000000000000 --- a/db_version +++ /dev/null @@ -1 +0,0 @@ -0.15 From 7d10d69537cdd75518be281593230cb95e54fdaf Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Aug 2024 09:59:28 +0200 Subject: [PATCH 09/12] fix typo --- contrib/container/execute.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/container/execute.sh b/contrib/container/execute.sh index c6fa958694c9..e766f97718e7 100755 --- a/contrib/container/execute.sh +++ b/contrib/container/execute.sh @@ -11,7 +11,7 @@ if [ ! -e "$db_version_old" ]; then invoke update || exit 2 echo "Setup command completed." - echo "$db_version" > "$db_version_old" + echo "$new_version" > "$db_version_old" fi old_version=$(cat "$db_version_old") echo "old version $old_version" @@ -34,7 +34,7 @@ if [ "$(awk -v num1=$old_version -v num2=$new_version 'BEGIN { print (num1 < num echo "Update successful" # Write the the new version to the old version file after update - echo "$db_version" > "$db_version_old" + echo "$new_version" > "$db_version_old" fi echo "Database migration/update checks completed." From 51ce61a0d75b4e9b4331a9c0720a810c414707fb Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Aug 2024 12:01:40 +0200 Subject: [PATCH 10/12] remove unneeded section --- contrib/container/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/contrib/container/Dockerfile b/contrib/container/Dockerfile index 0fe9af563ed2..3ce3d080ed91 100644 --- a/contrib/container/Dockerfile +++ b/contrib/container/Dockerfile @@ -120,8 +120,6 @@ RUN cd ${INVENTREE_HOME} && inv frontend-compile COPY contrib/container/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 From 218f9c037bc93e22ba8f8181ca257675c7efd3ae Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Aug 2024 12:53:20 +0200 Subject: [PATCH 11/12] Make safer to execute --- contrib/container/execute.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/container/execute.sh b/contrib/container/execute.sh index e766f97718e7..0a076d0d70a1 100755 --- a/contrib/container/execute.sh +++ b/contrib/container/execute.sh @@ -2,7 +2,7 @@ # File to check existence db_version_old="${INVENTREE_HOME}/db_version.old" -new_version="$(python3 .github/scripts/version_check.py only_version)" +new_version="$(python3 ${INVENTREE_HOME}/.github/scripts/version_check.py only_version)" # Check if the file exists if [ ! -e "$db_version_old" ]; then From 8d8fbd43a71ffc11d337a6793785d6dcf169befa Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Fri, 23 Aug 2024 17:32:50 +0200 Subject: [PATCH 12/12] Update contrib/container/execute.sh Co-authored-by: ChristianSchindler <52111837+ChristianSchindler@users.noreply.github.com> --- contrib/container/execute.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/container/execute.sh b/contrib/container/execute.sh index 0a076d0d70a1..3e3c369d89a5 100755 --- a/contrib/container/execute.sh +++ b/contrib/container/execute.sh @@ -12,6 +12,7 @@ if [ ! -e "$db_version_old" ]; then echo "Setup command completed." echo "$new_version" > "$db_version_old" + exit 0 fi old_version=$(cat "$db_version_old") echo "old version $old_version"