From 6ad485692eaf21e22fa68de7933fc8dde2512ca2 Mon Sep 17 00:00:00 2001 From: Dragos DOBRE Date: Thu, 16 May 2024 16:31:02 +0200 Subject: [PATCH 1/6] simplify running --- .github/workflows/openmis-module-test.yml | 4 ++-- Dockerfile | 1 - README.md | 24 +++++++++++------------ concatenate_files.sh | 8 -------- script/concatenate_files.sh | 5 +++-- script/run-initialization.sh | 8 ++++---- 6 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 concatenate_files.sh diff --git a/.github/workflows/openmis-module-test.yml b/.github/workflows/openmis-module-test.yml index f6187aa..a8ac3af 100644 --- a/.github/workflows/openmis-module-test.yml +++ b/.github/workflows/openmis-module-test.yml @@ -54,7 +54,7 @@ jobs: /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'DROP DATABASE IF EXISTS imis_1_4_2' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'CREATE DATABASE imis_1_4_2' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_1_4_2 -i 1.42/openIMIS_ONLINE.sql | grep . | uniq -c - /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_1_4_2 -i "new/output/fullMigrationScipt.sql" | grep . | uniq -c + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_1_4_2 -i "new/output/fullMigrationScript.sql" | grep . | uniq -c env: SA_PASSWORD: GitHub999 ACCEPT_EULA: Y @@ -73,7 +73,7 @@ jobs: /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'DROP DATABASE IF EXISTS imis_main' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'CREATE DATABASE imis_main' /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_main -i "oldMain/output/fullDemoDatabase.sql" | grep . | uniq -cc - /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_main -i "new/output/fullMigrationScipt.sql" | grep . | uniq -c + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis_main -i "new/output/fullMigrationScript.sql" | grep . | uniq -c env: diff --git a/Dockerfile b/Dockerfile index 61aa0d0..d04ef9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,6 @@ ENV SA_PASSWORD=IMISuserP@s ENV DB_USER_PASSWORD=IMISuserP@s ENV DB_NAME=IMIS ENV DB_USER=IMISUser -ENV INIT_MODE=empty RUN mkdir -p /app COPY script/* /app/ COPY sql /app/sql diff --git a/README.md b/README.md index 0dc190e..f67f5fd 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,11 @@ git clone https://github.com/openimis/database_ms_sqlserver * create a new database (i.e. openIMIS.X.Y.Z where X.Y.Z is the openIMIS database version) -* Execute the initial database creation script fullEmpytDatabase.sql or fullDemoDatabase.sql (see "creating SQL script" section on how to get them) +* Execute the initial database creation script fullEmptyDatabase.sql or fullDemoDatabase.sql (see "creating SQL script" section on how to get them) ### Upgrading -In order to upgrade from the previous version of openIMIS database (see [Versioning](#versioning) section), execute the migration script (fullMigrationSript), see "creating SQL script" to get it +In order to upgrade from the previous version of openIMIS database (see [Versioning](#versioning) section), execute the migration script (fullMigrationScript), see "creating SQL script" to get it ## Deployment @@ -43,7 +43,7 @@ Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c6 ### Creating SQL script - SQL files for initialisaiton or update are created using bash script concatenate_files.sh or by downloading the sql-file zip from the latest release https://github.com/openimis/database_ms_sqlserver/releases/latest + SQL files for initialisation or update are created using bash script concatenate_files.sh or by downloading the sql-file zip from the latest release https://github.com/openimis/database_ms_sqlserver/releases/latest ## openIMIS dockerized database @@ -56,13 +56,13 @@ Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c6 ### ENV -- INIT_MODE if set to demo will init the database to demo (works only if not yet init) +- DEMO_DATASET if set to true will init the database to demo (works only if not yet init) otherwise comment it out - SQL_SCRIPT_URL url to init scripts - **ACCEPT_EULA** must be set to Y to accept MS SQL EULA - SA_PASSWORD default: IMISuserP@s -- DB_USER_PASSWORD defautl: IMISuserP@s -- DB_NAMEdefautl: IMIS -- DB_USER defautl: IMISUser +- DB_USER_PASSWORD default: IMISuserP@s +- DB_NAME default: IMIS +- DB_USER default: IMISUser ### gettingstarted @@ -79,7 +79,7 @@ docker build \ -t openimis-db ``` -optinnaly +optional ``` --build-arg SQL_SCRIPT_URL= \ --build-arg DB_USER_PASSWORD=StrongPassword @@ -87,7 +87,7 @@ optinnaly --build-arg DB_NAME=IMIS ``` ***Notes***: -* by setting the ACCEPT_EULA=Y, you explicitely accept [Microsoft EULA](https://go.microsoft.com/fwlink/?linkid=857698) for the dockerized SQL Server 2017. Please ensure you read it and use the provided software according to the terms of that license. +* by setting the ACCEPT_EULA=Y, you explicitly accept [Microsoft EULA](https://go.microsoft.com/fwlink/?linkid=857698) for the dockerized SQL Server 2017. Please ensure you read it and use the provided software according to the terms of that license. * choose a strong password (at least 8 chars,...)... or SQL Server will complain @@ -97,13 +97,13 @@ To restore the backup inside the container: ***Note:*** -the container will check if the database exist, if it doesnot it will take the latest demo release version and deploy it , SQL_SCRIPT_URL is per defautl set to "https://github.com/openimis/database_ms_sqlserver/releases/latest/download/sql-files.zip" -to have data retention when container are recreated volums need to be configured as microsoft docs suggest +The container will check if the database exist. If it does not, it will take the latest demo release version and deploy it, SQL_SCRIPT_URL is by default set to "https://github.com/openimis/database_ms_sqlserver/releases/latest/download/sql-files.zip" +To ensure data retention when containers are recreated, volumes need to be configured as suggested in the Microsoft documentation. * /data:/var/opt/mssql/data : database files * /log:/var/opt/mssql/log : logs files * /secrets:/var/opt/mssql/secrets : secrets -The database is writen within the container. If you want to keep your data between container execution, stop/start the container via `docker stop ` / `docker start ` (using `docker run ... ` recreates a new container from the image... thus without any data) +The database is written within the container. If you want to keep your data between container execution, stop/start the container via `docker stop ` / `docker start ` (using `docker run ... ` recreates a new container from the image, thus without any data) diff --git a/concatenate_files.sh b/concatenate_files.sh deleted file mode 100644 index 1cc154b..0000000 --- a/concatenate_files.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -mkdir output -cat sql/migrations/1_migration_latest.sql sql/stored_procedures/*.sql > output/fullMigrationScipt.sql -cat sql/base/*.sql sql/stored_procedures/*.sql > output/fullEmptyDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/demo/*.sql> output/fullDemoDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/central.sql > output/fullOfflineCentralDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/hf.sql > output/fullOfflineHFDatabase.sql diff --git a/script/concatenate_files.sh b/script/concatenate_files.sh index 1cc154b..6add062 100644 --- a/script/concatenate_files.sh +++ b/script/concatenate_files.sh @@ -1,8 +1,9 @@ #!/bin/bash mkdir output -cat sql/migrations/1_migration_latest.sql sql/stored_procedures/*.sql > output/fullMigrationScipt.sql +cat sql/migrations/1_migration_latest.sql sql/stored_procedures/*.sql > output/fullMigrationScript.sql cat sql/base/*.sql sql/stored_procedures/*.sql > output/fullEmptyDatabase.sql -cat sql/base/*.sql sql/stored_procedures/*.sql sql/demo/*.sql> output/fullDemoDatabase.sql +cat sql/base/*.sql sql/stored_procedures/*.sql sql/demo/*.sql > output/fullDemoDatabase.sql +cat sql/demo/*.sql > output/DemoDataset.sql cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/central.sql > output/fullOfflineCentralDatabase.sql cat sql/base/*.sql sql/stored_procedures/*.sql sql/offline/hf.sql > output/fullOfflineHFDatabase.sql diff --git a/script/run-initialization.sh b/script/run-initialization.sh index 996ddae..e9be919 100644 --- a/script/run-initialization.sh +++ b/script/run-initialization.sh @@ -5,10 +5,10 @@ sleep 60s -# DATABSE initialisation +# DATABASE initialisation -echo "Database initialisaton" -# if the table does not exsit it will create the table +echo "Database initialisation" +# if the table does not exist it will create the table # get "1" if the database exist : tr get only the integer, cut only the first integer (the second is the number of row affected) data=$(/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "SELECT COUNT(*) FROM master.dbo.sysdatabases WHERE name = N'$DB_NAME'" | tr -dc '0-9'| cut -c1 ) @@ -22,7 +22,7 @@ if [ ${data} -eq "0" ]; then #/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP DATABASE IF EXISTS $DB_NAME" /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME" - if [ "$INIT_MODE" = "demo" ]; then + if [ "$DEMO_DATASET" ]; then /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c else /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i output/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c From 25d520b80d08a9679686279161037ce58b3bb185 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Fri, 28 Mar 2025 13:57:47 +0100 Subject: [PATCH 2/6] fix wf module-requirements path --- .github/workflows/openmis-module-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/openmis-module-test.yml b/.github/workflows/openmis-module-test.yml index a8ac3af..258e38e 100644 --- a/.github/workflows/openmis-module-test.yml +++ b/.github/workflows/openmis-module-test.yml @@ -88,7 +88,8 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - python modules-requirements.py openimis.json > modules-requirements.txt + cd script + python modules-requirements.py ../openimis.json > modules-requirements.txt cat modules-requirements.txt pip install -r modules-requirements.txt - name: Django tests latest From 0ccca14b028161b1776e5ce57c719ba177d5b434 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Fri, 28 Mar 2025 14:00:31 +0100 Subject: [PATCH 3/6] install app in the workdir --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2c65ebc..2674585 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,9 @@ ENV SA_PASSWORD=IMISuserP@s ENV DB_USER_PASSWORD=IMISuserP@s ENV DB_NAME=IMIS ENV DB_USER=IMISUser -RUN mkdir -p /app -COPY script/* /app/ -COPY sql /app/sql -WORKDIR /app -RUN chmod a+x /app/*.sh +RUN mkdir -p app +COPY script/* app/ +COPY sql app/sql +WORKDIR app +RUN chmod a+x app/*.sh CMD /bin/bash ./entrypoint.sh From ceb1f1d40954724439236ea52dcfb1d230415973 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Fri, 28 Mar 2025 14:03:12 +0100 Subject: [PATCH 4/6] Update Dockerfile --- Dockerfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2674585..badea47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,7 @@ ENV SA_PASSWORD=IMISuserP@s ENV DB_USER_PASSWORD=IMISuserP@s ENV DB_NAME=IMIS ENV DB_USER=IMISUser -RUN mkdir -p app -COPY script/* app/ -COPY sql app/sql -WORKDIR app -RUN chmod a+x app/*.sh +COPY script/* ./ +COPY sql ./sql +RUN chmod a+x ./*.sh CMD /bin/bash ./entrypoint.sh From fc806a1307202e709dc2041a17b75c56ca5f37a2 Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Fri, 28 Mar 2025 14:08:11 +0100 Subject: [PATCH 5/6] Update Dockerfile --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index badea47..524b0e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ FROM mcr.microsoft.com/mssql/server:2022-latest +RUN START_USER=$(whoiam) +USER root ARG ACCEPT_EULA=Y ENV ACCEPT_EULA=N ARG SA_PASSWORD=IMISuserP@s From c09a7e2c806cdcfbd93f5a041a986e63fa4d5f9d Mon Sep 17 00:00:00 2001 From: Patrick Delcroix Date: Fri, 28 Mar 2025 14:09:25 +0100 Subject: [PATCH 6/6] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 524b0e3..14096f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM mcr.microsoft.com/mssql/server:2022-latest -RUN START_USER=$(whoiam) +RUN START_USER=$(whoami) USER root ARG ACCEPT_EULA=Y ENV ACCEPT_EULA=N