From 7de0215fd7bccf36aafc3fdd01a18125b1640529 Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Fri, 20 Sep 2024 10:25:17 +0000 Subject: [PATCH 1/3] Modify MongoDB container name to avoid conflicts --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 87a001d0..7f61488c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: mongo-db: image: mongo:7.0-jammy - container_name: mongodb_container + container_name: ims_api_mongodb_container command: ["--replSet", "rs0", "--keyFile", "/etc/mongodb/keys/rs_keyfile"] volumes: - ./mongodb/data:/data/db From 2f066b1021fc75b7bd90b1173983851ac941a7a6 Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Fri, 20 Sep 2024 11:25:24 +0000 Subject: [PATCH 2/3] Update Config docstring --- inventory_management_system_api/core/config.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inventory_management_system_api/core/config.py b/inventory_management_system_api/core/config.py index 61574de2..dad329eb 100644 --- a/inventory_management_system_api/core/config.py +++ b/inventory_management_system_api/core/config.py @@ -3,11 +3,11 @@ """ from pathlib import Path -from typing import Optional, List +from typing import List, Optional from pydantic import BaseModel, ConfigDict, Field, SecretStr, field_validator from pydantic_core.core_schema import ValidationInfo -from pydantic_settings import SettingsConfigDict, BaseSettings +from pydantic_settings import BaseSettings, SettingsConfigDict class APIConfig(BaseModel): @@ -69,9 +69,9 @@ class Config(BaseSettings): """ Overall configuration model for the application. - It includes attributes for the API and database configurations. The class inherits from `BaseSettings` and - automatically reads environment variables. If values are not passed in form of system environment variables at - runtime, it will attempt to read them from the .env file. + It includes attributes for the API, authentication and database configurations. The class inherits from + `BaseSettings` and automatically reads environment variables. If values are not passed in form of system environment + variables at runtime, it will attempt to read them from the .env file. """ api: APIConfig From 535bca4513351d73f8a3708bd18d1fc07e70e1cf Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Fri, 20 Sep 2024 12:35:55 +0000 Subject: [PATCH 3/3] Update readme and dev_cli script --- README.md | 8 ++++---- scripts/dev_cli.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index af1c6595..0fe94cb9 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ replacing `` with the actual hostname for the replica set. For docker you may use ```bash -docker exec -i mongodb_container mongosh --username 'root' --password 'example' --authenticationDatabase=admin --eval "rs.initiate({ _id : 'rs0', members: [{ _id: 0, host: 'mongodb_container:27017' }]})" +docker exec -i ims_api_mongodb_container mongosh --username 'root' --password 'example' --authenticationDatabase=admin --eval "rs.initiate({ _id : 'rs0', members: [{ _id: 0, host: 'ims_api_mongodb_container:27017' }]})" ``` ### Using mock data for testing [Optional] @@ -242,7 +242,7 @@ to populate the database with mock data. If you wish to do this manually the full command is ```bash -docker exec -i mongodb_container mongorestore --username "root" --password "example" --authenticationDatabase=admin --db ims --archive < ./data/mock_data.dump +docker exec -i ims_api_mongodb_container mongorestore --username "root" --password "example" --authenticationDatabase=admin --db ims --archive < ./data/mock_data.dump ``` Otherwise there is a script to generate mock data for testing purposes given in `./scripts/generate_mock_data.py`. To use it from your development environment first ensure the API is running and then execute it with @@ -274,13 +274,13 @@ to update the `./data/mock_data.dump` file and commit the changes. The parameters at the top of the file can be used to change the generated data. NOTE: This script will simply add to the existing database instance. So if you wish to update the `mock_data.dump`, you should first clear the database e.g. using ```bash -docker exec -i mongodb_container mongosh ims --username "root" --password "example" --authenticationDatabase=admin --eval "db.dropDatabase()" +docker exec -i ims_api_mongodb_container mongosh ims --username "root" --password "example" --authenticationDatabase=admin --eval "db.dropDatabase()" ``` Then generate the mock data, import the units and then update the `./data/mock_data.dump` file using `mongodump` via ```bash -docker exec -i mongodb_container mongodump --username "root" --password "example" --authenticationDatabase=admin --db ims --archive > ./data/mock_data.dump +docker exec -i ims_api_mongodb_container mongodump --username "root" --password "example" --authenticationDatabase=admin --db ims --archive > ./data/mock_data.dump ``` ## Notes diff --git a/scripts/dev_cli.py b/scripts/dev_cli.py index d00c05e8..2d03f2cf 100644 --- a/scripts/dev_cli.py +++ b/scripts/dev_cli.py @@ -53,7 +53,7 @@ def run_mongodb_command(args: list[str], stdin: Optional[TextIOWrapper] = None, "docker", "exec", "-i", - "mongodb_container", + "ims_api_mongodb_container", ] + args, stdin=stdin,