Skip to content

Commit

Permalink
feat: mongodb entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Spotika committed Aug 21, 2024
1 parent a8b0a0f commit ae44041
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ cython_debug/

.vscode
configs/main.json
mongo_entrypoint/.env
tests/node_modules/
2 changes: 1 addition & 1 deletion configs/test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"database": {
"connect_url": "mongodb://admin:admin@db_test",
"connect_url": "mongodb://test:test@db_test/ELANDB",
"name": "ELANDB"
},
"auth": {
Expand Down
15 changes: 8 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
services:
db:
image: mongo
volumes:
- /var/lib/elan/mongodb_data:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
ports:
- "27017:27017"
env_file: "mongo_entrypoint/.env"
volumes:
- ./mongo_entrypoint:/docker-entrypoint-initdb.d
- /var/lib/elan/mongodb_data:/data/db
api:
build:
context: ./
Expand All @@ -22,10 +21,12 @@ services:
db_test:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin
- MONGO_ELANDB_USERNAME=test
- MONGO_ELANDB_PASSWORD=test
ports:
- "42042:42042"
volumes:
- ./mongo_entrypoint:/docker-entrypoint-initdb.d
api_test:
build:
context: ./
Expand Down
6 changes: 6 additions & 0 deletions mongo_entrypoint/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
db = db.getSiblingDB("ELANDB");
db.createUser({
user: process.env.MONGO_ELANDB_USERNAME,
pwd: process.env.MONGO_ELANDB_PASSWORD,
roles: [{ role: "readWrite", db: "ELANDB" }]
});
24 changes: 12 additions & 12 deletions src/db/types/domain.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Literal
from pydantic import Field

from utils.schemas import BaseModel


TargetType = Literal["user", "group", "contest"]

class Entity(BaseModel):
id: str = Field(alias='_id')
target_type: TargetType
target_id: int
from typing import Literal
from pydantic import Field

from utils.schemas import BaseModel


TargetType = Literal["user", "group", "contest"]

class Entity(BaseModel):
id: str = Field(alias='_id')
target_type: TargetType
target_id: int

0 comments on commit ae44041

Please sign in to comment.