Skip to content

Commit

Permalink
2-db-and-pl-demonstration (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyro7 authored Mar 2, 2025
2 parents e5eaa91 + bdcf748 commit 9deeabd
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MONGO_DB_HOST=YOUR_MONGODB_HOSTNAME_HERE
MONGO_DB_PORT=YOUR_MONGODB_PORT_HERE
MONGO_INITDB_ROOT_USERNAME=YOUR_USERNAME_HERE
MONGO_INITDB_ROOT_PASSWORD=YOUR_PASSWORD_HERE
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.12-alpine

RUN addgroup --system gdwrapper && adduser --system --ingroup gdwrapper --disabled-password gdwrapper

USER gdwrapper

RUN cd ~ && mkdir app

Check failure on line 7 in Dockerfile

View workflow job for this annotation

GitHub Actions / Проверка наличия тега 0.8 и работоспособности docker compose

DL3003 warning: Use WORKDIR to switch to a directory

WORKDIR /app

COPY requirements.txt .

RUN pip3 install -r requirements.txt

Check failure on line 13 in Dockerfile

View workflow job for this annotation

GitHub Actions / Проверка наличия тега 0.8 и работоспособности docker compose

DL3042 warning: Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`

COPY ./hello_world .

CMD [ "python3", "main.py" ]
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.1'

services:

mongo:
image: mongo
restart: always
ports:
- ${MONGO_DB_PORT}:${MONGO_DB_PORT}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
networks:
- gdwrapper_network


gdwrapper:
image: gdwrapepr
build: .
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
MONGO_DB_HOST: ${MONGO_DB_HOST}
MONGO_DB_PORT: ${MONGO_DB_PORT}
depends_on:
- mongo
networks:
- gdwrapper_network


networks:
gdwrapper_network:
driver: bridge
34 changes: 34 additions & 0 deletions hello_world/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pymongo import MongoClient
import datetime
import os
from dotenv import load_dotenv


load_dotenv('../.env')


db_uri = f'mongodb://{os.environ['MONGO_INITDB_ROOT_USERNAME']}:{os.environ['MONGO_INITDB_ROOT_PASSWORD']}@{os.environ['MONGO_DB_HOST']}:{os.environ['MONGO_DB_PORT']}/'
client = MongoClient(db_uri)

print('Cписок доступных БД по умолчанию:')
print(client.list_database_names())
print('')


gdwrapper_db = client['gdwrapper_db']
collection = gdwrapper_db['test_collection']
collection.insert_one(
{
'Info': 'This is test data',
'Timestamp': datetime.datetime.now(tz=datetime.timezone.utc)
}
)

print('Cписок доступных БД после добавления gdwrapper_db:')
print(client.list_database_names())
print('')


print('Данные gdwrapper_db из коллекции test_collection:')
for item in client.get_database('gdwrapper_db').get_collection('test_collection').find():
print(item)
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dnspython==2.7.0
dotenv==0.9.9
pymongo==4.11.1
python-dotenv==1.0.1

0 comments on commit 9deeabd

Please sign in to comment.