From cd4c92e13cef77334a7e4b3064e682c5fa861b51 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:53:53 +0000 Subject: [PATCH 1/4] feat: Added Dockerfile for local MongoDB Atlas set --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a4ac34a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +# Use the official MongoDB image as the base +FROM mongo:latest + +# Set environment variables for MongoDB +ENV MONGO_INITDB_ROOT_USERNAME=admin +ENV MONGO_INITDB_ROOT_PASSWORD=password + +# Optional: Copy initialization script to the container +COPY init-mongo.js /docker-entrypoint-initdb.d/ From 2184c604bd36153703ae998e8675dfe24a0751b4 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:54:23 +0000 Subject: [PATCH 2/4] feat: Added docker-compose.yml for MongoDB service --- docker-compose.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..11f1b84 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.8' +services: + mongodb: + build: . + ports: + - "27017:27017" + environment: + MONGO_INITDB_ROOT_USERNAME: admin + MONGO_INITDB_ROOT_PASSWORD: password From bcf4f8bf4fc53eae3140dcd22b202a4d8bf78cc4 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:55:40 +0000 Subject: [PATCH 3/4] feat: Updated API/database.py --- API/database.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/API/database.py b/API/database.py index ccdfc98..aaba593 100644 --- a/API/database.py +++ b/API/database.py @@ -1,10 +1,16 @@ +import os from datetime import datetime from pymongo import MongoClient class Database: - def __init__(self, uri="mongodb://localhost:27017/", db_name="ImageDB"): + def __init__(self, db_name="ImageDB"): + use_docker_db = os.environ.get('USE_DOCKER_DB', 'False') == 'True' + if use_docker_db: + uri = "mongodb://admin:password@localhost:27017/" + else: + uri = "mongodb://localhost:27017/" self.client = MongoClient(uri) self.db = self.client[db_name] From 83c38eb83771a4c9d61571faf1d2c85cb99598d3 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:56:50 +0000 Subject: [PATCH 4/4] feat: Updated README.md --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f5ef6f..dd262a3 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,25 @@ This project requires Python 3.7 or later. ### Running the Server -To start FLask and FastAPI, run the given command: +To run the application and MongoDB Atlas locally using Docker, follow these steps: + +1. Build and run the Docker container: + ```bash + docker-compose up --build + ``` + This command builds the MongoDB container and runs it alongside your application. + +2. To switch between the local Docker-based MongoDB Atlas and the cloud version, set the `USE_DOCKER_DB` environment variable in your application's environment: + - For using the Docker-based MongoDB Atlas, set `USE_DOCKER_DB=True`. + - For using the cloud version of MongoDB Atlas, set `USE_DOCKER_DB=False`. + +3. To stop the Docker container, use the following command: + ```bash + docker-compose down + ``` + This command stops and removes the containers, networks, and volumes created by `docker-compose up`. + +To start Flask and FastAPI without Docker, run the given command: ```bash python main.py ```