From c0f24f2aeaaf09d3a3fe173654dbbd8c6e7777af Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Sun, 12 May 2024 15:37:35 -0500 Subject: [PATCH] chore: initialize mysql database in docker The mysql dockerfile has been pinned at 8.3 to avoid errors in the default authentication plugin. See https://github.com/mysqljs/mysql/pull/2233 for more information. It might be prudent to switch to mysql2 instead of mysqljs for future release. I've renamed all the server model files to have a numeric prefix to allow execution in order. The 99-debug.sql file crashes, but it is not necessary for the functioning of the BHIMA server. You can now type `docker-compose up` and be taken to the BHIMA installation page on localhost. Environmental variables are set in the `.env` file as usual. --- Dockerfile | 4 +++ docker-compose.yml | 9 ++--- package.json | 2 +- server/models/{schema.sql => 01-schema.sql} | 0 .../{functions.sql => 02-functions.sql} | 0 .../{procedures.sql => 03-procedures.sql} | 0 .../models/{triggers.sql => 04-triggers.sql} | 0 server/models/{icd10.sql => 05-icd10.sql} | 0 server/models/{bhima.sql => 06-bhima.sql} | 0 server/models/{admin.sql => 98-admin.sql} | 0 server/models/{debug.sql => 99-debug.sql} | 0 sh/docker-init.sh | 34 ------------------- 12 files changed, 10 insertions(+), 39 deletions(-) rename server/models/{schema.sql => 01-schema.sql} (100%) rename server/models/{functions.sql => 02-functions.sql} (100%) rename server/models/{procedures.sql => 03-procedures.sql} (100%) rename server/models/{triggers.sql => 04-triggers.sql} (100%) rename server/models/{icd10.sql => 05-icd10.sql} (100%) rename server/models/{bhima.sql => 06-bhima.sql} (100%) rename server/models/{admin.sql => 98-admin.sql} (100%) rename server/models/{debug.sql => 99-debug.sql} (100%) delete mode 100755 sh/docker-init.sh diff --git a/Dockerfile b/Dockerfile index 8d8dca52fb..70907ff877 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,10 @@ USER node ENV NODE_ENV production +LABEL org.opencontainers.image.source=https://github.com/third-Culture-Software/bhima +LABEL org.opencontainers.image.description="A hospital information management application for rural Congolese hospitals" +LABEL org.opencontainers.image.licenses=GPL + # Define startup command CMD ["node", "server/app.js"] diff --git a/docker-compose.yml b/docker-compose.yml index 7c9bb3032d..7bce2a75e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,16 +15,17 @@ services: - backend mysql: - image: mysql:8 + image: mysql:8.3 # pin 8.3 ; https://github.com/appsignal/appsignal-nodejs/commit/0586d603c75aa12f8e99f4a5716fd8445f10d79c restart: unless-stopped command: - - --mysql-native-password=ON + #- --mysql-native-password=ON # See https://github.com/appsignal/appsignal-nodejs/commit/0586d603c75aa12f8e99f4a5716fd8445f10d79c - --sql-mode=STRICT_ALL_TABLES,NO_UNSIGNED_SUBTRACTION + - --default-authentication-plugin=mysql_native_password volumes: - mysqldata:/var/lib/mysql/ - - "./temp/docker-build.sql:/docker-entrypoint-initdb.d/bhima.sql" + - ./server/models:/docker-entrypoint-initdb.d environment: - - MYSQL_RANDOM_ROOT_PASSWORD=1 + - MYSQL_RANDOM_ROOT_PASSWORD=yes - MYSQL_USER=$DB_USER - MYSQL_PASSWORD=$DB_PASS - MYSQL_DATABASE=$DB_NAME diff --git a/package.json b/package.json index 6ca56146c1..8144d2a8e9 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "build:db": "cross-env ./sh/build-database.sh", "build:clean": "cross-env ./sh/build-init-database.sh", "build:stock": "cross-env ./sh/build-stock-database.sh", - "build:docker": "cross-env ./sh/docker-init.sh", + "build:docker": "docker compose build", "migrate": "cross-env ./sh/setup-migration-script.sh", "watch": "cross-env ./node_modules/.bin/gulp watch", "check:lang": "cross-env node ./utilities/translation/tfcomp.js client/src/i18n/en client/src/i18n/fr", diff --git a/server/models/schema.sql b/server/models/01-schema.sql similarity index 100% rename from server/models/schema.sql rename to server/models/01-schema.sql diff --git a/server/models/functions.sql b/server/models/02-functions.sql similarity index 100% rename from server/models/functions.sql rename to server/models/02-functions.sql diff --git a/server/models/procedures.sql b/server/models/03-procedures.sql similarity index 100% rename from server/models/procedures.sql rename to server/models/03-procedures.sql diff --git a/server/models/triggers.sql b/server/models/04-triggers.sql similarity index 100% rename from server/models/triggers.sql rename to server/models/04-triggers.sql diff --git a/server/models/icd10.sql b/server/models/05-icd10.sql similarity index 100% rename from server/models/icd10.sql rename to server/models/05-icd10.sql diff --git a/server/models/bhima.sql b/server/models/06-bhima.sql similarity index 100% rename from server/models/bhima.sql rename to server/models/06-bhima.sql diff --git a/server/models/admin.sql b/server/models/98-admin.sql similarity index 100% rename from server/models/admin.sql rename to server/models/98-admin.sql diff --git a/server/models/debug.sql b/server/models/99-debug.sql similarity index 100% rename from server/models/debug.sql rename to server/models/99-debug.sql diff --git a/sh/docker-init.sh b/sh/docker-init.sh deleted file mode 100755 index dfdcf77944..0000000000 --- a/sh/docker-init.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -# bash "strict mode" -# http://redsymbol.net/articles/unofficial-bash-strict-mode/ -set -euo pipefail -IFS=$'\n\t' - -cat server/models/schema.sql > temp/docker-build-schema.sql - -cat server/models/functions.sql \ - server/models/procedures.sql \ - server/models/admin.sql \ - server/models/triggers.sql > temp/docker-build-procedures.sql - -cat server/models/icd10.sql \ - server/models/bhima.sql > temp/docker-build-data.sql - - -sed -i '/DELIMITER/d' temp/docker-build-schema.sql -sed -i '/DELIMITER/d' temp/docker-build-procedures.sql -sed -i '/DELIMITER/d' temp/docker-build-data.sql - -cat temp/docker-build-schema.sql > temp/docker-build.sql -echo "DELIMITER \$\$" >> temp/docker-build.sql -cat temp/docker-build-procedures.sql >> temp/docker-build.sql -echo "DELIMITER ;" >> temp/docker-build.sql -cat temp/docker-build-data.sql >> temp/docker-build.sql -echo "Call zRecomputeEntityMap();" >> temp/docker-build.sql -echo "Call zRecomputeDocumentMap();" >> temp/docker-build.sql -echo "Call zRecalculatePeriodTotals();" >> temp/docker-build.sql - -rm temp/docker-build-schema.sql -rm temp/docker-build-procedures.sql -rm temp/docker-build-data.sql