diff --git a/admins_service/main.py b/admins_service/main.py index df9bf5684278b1d058228ff8ea6889e951da1a3f..5bfd693862b2649c127e6690ea13c08fc48a711d 100644 --- a/admins_service/main.py +++ b/admins_service/main.py @@ -18,9 +18,20 @@ app.add_middleware( # SQLite connection # SQLite connection +# parent_directory = Path(__file__).resolve().parent.parent +# db_file_path = parent_directory / "my_ride.db" +# # print(db_file_path) + parent_directory = Path(__file__).resolve().parent.parent +# Specify the path to the SQLite database file in the data directory db_file_path = parent_directory / "my_ride.db" -# print(db_file_path) + +# Check if the database file exists +if not db_file_path.exists(): + # If the database file doesn't exist, use a local database file from the same location + local_db_file_path = Path(__file__).resolve().parent / "local_bike.db" + db_file_path = local_db_file_path + conn = sqlite3.connect(db_file_path) cursor = conn.cursor() diff --git a/database_mysql/Dockerfile b/database_mysql/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..137d09841418db3e0368b1ba359d53a46cb64de9 --- /dev/null +++ b/database_mysql/Dockerfile @@ -0,0 +1,15 @@ +# Use the official MySQL 8.0 image as base +FROM mysql:8.0 + +# Set environment variables +ENV MYSQL_DATABASE=mydatabase \ + MYSQL_ROOT_PASSWORD=mysecretpassword + +# Optionally, if you have SQL initialization scripts, copy them to a directory in the image +# COPY ./sql-scripts/ /docker-entrypoint-initdb.d/ + +# Expose the MySQL port +EXPOSE 3306 + +# Define the entry point +CMD ["mysqld"] diff --git a/docker-compose.yml b/docker-compose.yml index 4b5c4300af03b2c03c18dfcf283e5838ad31eba9..a443d4f0134dc3f2dbc8fdb5cc528874e5fbe284 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,28 +1,55 @@ version: '3' services: - bikes_service: - build: ./bikes_service + # MySQL service + database_mysql: + image: mysql:5.7 ports: - - "8001:8001" + - "3306:3306" + environment: + MYSQL_ROOT_PASSWORD: root_password + MYSQL_DATABASE: your_database + MYSQL_USER: your_username + MYSQL_PASSWORD: your_password + volumes: + - mysql_data:/var/lib/mysql + - ./sql_files:/docker-entrypoint-initdb.d # Mount SQL files for initialization + # Microservices definitions... admins_service: build: ./admins_service ports: - - "8002:8002" + - "${ADMINS_SERVICE_PORT}:8001" + environment: + - SERVICE_PORT=${ADMINS_SERVICE_PORT} + + bikes_service: + build: ./bikes_service + ports: + - "${BIKES_SERVICE_PORT}:8002" + environment: + - SERVICE_PORT=${BIKES_SERVICE_PORT} rentals_service: build: ./rentals_service ports: - - "8003:8003" - + - "${RENTALS_SERVICE_PORT}:8003" + environment: + - SERVICE_PORT=${RENTALS_SERVICE_PORT} + reviews_service: - build: ./bikes_service + build: ./reviews_service ports: - - "8001:8001" + - "${REVIEWS_SERVICE_PORT}:8004" + environment: + - SERVICE_PORT=${REVIEWS_SERVICE_PORT} users_service: - build: ./admins_service + build: ./users_service ports: - - "8002:8002" + - "${USERS_SERVICE_PORT}:8005" + environment: + - SERVICE_PORT=${USERS_SERVICE_PORT} +volumes: + mysql_data: diff --git a/reviews_service/Dockerfile b/reviews_service/Dockerfile index 67ca58e51841e93ed048a1d68c0b27ed2970d9af..9a90e34f747fb744c0f57c4d735a2799e7a9c2f1 100644 --- a/reviews_service/Dockerfile +++ b/reviews_service/Dockerfile @@ -14,7 +14,7 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Expose the port specified by the environment variable -EXPOSE $SERVICE_PORT +EXPOSE 8004 # Command to run the application -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "$SERVICE_PORT"] +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8004"] diff --git a/users_service/Dockerfile b/users_service/Dockerfile index 67ca58e51841e93ed048a1d68c0b27ed2970d9af..31ade53229e29212873f0e273a1e8aff57d8a016 100644 --- a/users_service/Dockerfile +++ b/users_service/Dockerfile @@ -14,7 +14,7 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Expose the port specified by the environment variable -EXPOSE $SERVICE_PORT +EXPOSE 8005 # Command to run the application -CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "$SERVICE_PORT"] +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8005"]