Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
OP-1205 Review docker usage documentation in oh-core (informatici#1399)
Browse files Browse the repository at this point in the history
* Use dotenv to configure DB parameters and language

* Update readme

* Remove unwanted indentation

* Keep language suffix to ease debug
  • Loading branch information
mwithi authored Sep 9, 2024
1 parent 8c72949 commit b3d61f8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ logs
/rsc/
.idea/
.vscode/
*.iml
*.iml
/.env
20 changes: 10 additions & 10 deletions Dockerfile-ohdb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM mariadb:10.6.11

ENV MYSQL_DATABASE=oh
ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_USER=isf
ENV MYSQL_PASSWORD=isf123
ARG OH_DB_LANG=en

ENV MARIADB_DATABASE=oh
ENV MARIADB_ROOT_PASSWORD=root
ENV MARIADB_USER=isf
ENV MARIADB_PASSWORD=isf123

COPY sql/step_01_create_structure.sql /docker-entrypoint-initdb.d/
COPY sql/step_02_dump_menu.sql /docker-entrypoint-initdb.d/
COPY sql/step_03_dump_default_data_en.sql /docker-entrypoint-initdb.d/
COPY sql/step_03_dump_default_data_${OH_DB_LANG}.sql /docker-entrypoint-initdb.d/
#COPY sql/step_04_all_following_steps.sql /docker-entrypoint-initdb.d/
COPY sql/step_05_update_menu_i18n.sql /docker-entrypoint-initdb.d/
COPY sql/step_06_opd_extended.sql /docker-entrypoint-initdb.d/
Expand All @@ -24,8 +26,6 @@ COPY sql/step_7* /docker-entrypoint-initdb.d/
COPY sql/step_8* /docker-entrypoint-initdb.d/
COPY sql/step_9* /docker-entrypoint-initdb.d/
COPY sql/step_a1* /docker-entrypoint-initdb.d/
COPY sql/data_en/* data_en/
#COPY sql/data_es/* data_es/
#COPY sql/data_it/* data_it/
#COPY sql/data_pt/* data_pt/
#COPY sql/data_fr/* data_fr/
COPY sql/step_03_dump_vaccine_data_${OH_DB_LANG}.sql /docker-entrypoint-initdb.d/step_z100_dump_vaccine_data_${OH_DB_LANG}.sql
COPY sql/step_03_dump_dicomtype_data_${OH_DB_LANG}.sql /docker-entrypoint-initdb.d/step_z101_dump_dicomtype_data_${OH_DB_LANG}.sql
COPY sql/data_${OH_DB_LANG}/* data_${OH_DB_LANG}/
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,44 @@ To run the tests simply issue:

Note: tests are run against an in-memory database (H2).

To run tests against a MariaDB instance:
To run tests against a MariaDB instance, see [How to run DB with Docker](#how-to-run-db-with-docker)

you can change [`src/test/resources/resources/database.properties`][database.prop]
Then you can change [`src/test/resources/resources/database.properties`][database.prop]

From:

jdbc.class=org.h2.Driver
jdbc.url=jdbc:h2:mem:myDb;MODE=MySQL;IGNORECASE=TRUE;DB_CLOSE_DELAY=-1

...
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=update
jdbc.username=root
jdbc.password=root

To:
To: (use .env variables):

jdbc.url=jdbc:mysql://localhost:[OH_MARIADB_PORT]/[OH_MARIADB_DATABASE]
jdbc.username=[OH_MARIADB_USER]
jdbc.password=[OH_MARIADB_PASSWORD]


jdbc.url=jdbc:mysql://localhost:3306/oh
jdbc.username=isf
jdbc.password=isf123
## How to run DB with Docker

Then, run the Docker container in the root folder with:
Copy `dotenv` into `.env` and set parameters as needed, otherwise defaults will be used:

OH_MARIADB_DATABASE=oh
OH_MARIADB_ROOT_PASSWORD=root
OH_MARIADB_USER=isf
OH_MARIADB_PASSWORD=isf123
OH_MARIADB_PORT=3306
OH_DB_LANG=en # refer to sql/data_xx/ folders

Clean previous builds:

# clean previous builds
docker compose rm --stop --volumes --force

# build and run a mariadb instance at localhost:3306
Build and run a mariadb instance at `localhost:[OH_MARIADB_PORT]`:

docker-compose up


Expand Down
27 changes: 17 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
version: '3'
services:
database:
build:
context: ./
dockerfile: Dockerfile-ohdb
image: oh-core_database:latest
ports:
- "3306:3306"
command: mysqld --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" --lower_case_table_names=1
version: '3'
services:
database:
build:
context: ./
dockerfile: Dockerfile-ohdb
args:
OH_DB_LANG: ${OH_DB_LANG}
image: oh-core_database:latest
ports:
- "${OH_MARIADB_PORT}:3306"
command: mysqld --sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" --lower_case_table_names=1
environment:
MARIADB_DATABASE: ${OH_MARIADB_DATABASE}
MARIADB_ROOT_PASSWORD: ${OH_MARIADB_ROOT_PASSWORD}
MARIADB_USER: ${OH_MARIADB_USER}
MARIADB_PASSWORD: ${OH_MARIADB_PASSWORD}
6 changes: 6 additions & 0 deletions dotenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OH_MARIADB_DATABASE=oh
OH_MARIADB_ROOT_PASSWORD=root
OH_MARIADB_USER=isf
OH_MARIADB_PASSWORD=isf123
OH_MARIADB_PORT=3306
OH_DB_LANG=en

0 comments on commit b3d61f8

Please sign in to comment.