Skip to content

Commit

Permalink
first task hello_world
Browse files Browse the repository at this point in the history
  • Loading branch information
mantsevat committed Sep 24, 2024
1 parent e557682 commit 678fa3d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hello_world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.11-alpine

WORKDIR /hello_world

COPY requirements.txt .

RUN pip3 install --no-cache-dir -r requirements.txt

COPY . /hello_world

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

services:

mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example

app:
build: .
depends_on:
- mongo
environment:
- MONGO_URL=mongodb://root:example@mongo:27017/

38 changes: 38 additions & 0 deletions hello_world/hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pymongo import MongoClient

def create_users(db):
users = []
for i in range (1, 11):
users.append({"name": "test_user" + str(i), "email": "test_email" + str(i), "password": "testpass" + str(i), "games": []})
col = db["users"]
col.insert_many(users)

def create_games(db):
games = []
for i in range(2):
games.append({"name": "test_game", "players": [], "owner_id": 5*i +1})
col = db["games"]
col.insert_many(games)

def get_db():
connection_string = "mongodb://root:example@mongo:27017/"
client = MongoClient(connection_string)
db = client["secret_santa_db"]
return db

def read_data(db, collection_name):
col = db[collection_name]
for record in col.find():
print(record)

def main():
secret_santa_db = get_db()

create_users(secret_santa_db)
create_games(secret_santa_db)

read_data(secret_santa_db, "users")
read_data(secret_santa_db, "games")

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions hello_world/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pymongo==4.9.1

0 comments on commit 678fa3d

Please sign in to comment.