diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a74c931 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.12-bookworm + +RUN apt-get update +RUN apt install dumb-init + +COPY requirements.txt . +RUN pip install -r requirements.txt + +EXPOSE 8000 +EXPOSE 8001 +EXPOSE 8090 +EXPOSE 8091 + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] diff --git a/config.example.toml b/config.example.toml index 31aa483..5a28413 100644 --- a/config.example.toml +++ b/config.example.toml @@ -11,7 +11,10 @@ discord_invite_link="" [database] - db_address="mongodb://localhost:27017" + database_host="localhost" + database_port="27017" + database_user="root" + database_password="password" database_name="elm" [mailing] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7607f49 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +services: + web: + build: . + depends_on: + db: + condition: service_healthy + environment: + PYTHONPATH: /opt/elm + ports: + - "8000:8000" + - "8001:8001" + volumes: + - ./:/opt/elm + entrypoint: ["/bin/sh", "-c", "cd /opt/elm/src && rio run --release --public --port 8000"] + + db: + image: mongo:8 + restart: unless-stopped + + environment: + MONGO_INITDB_ROOT_USERNAME: elm + MONGO_INITDB_ROOT_PASSWORD: elm + MONGO_INITDB_DATABASE: elm + + ports: + - "27017:27017" + + volumes: + - database:/data/db + + healthcheck: + test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping').ok"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 15s + +volumes: + database: diff --git a/src/elm/services/ConfigurationService.py b/src/elm/services/ConfigurationService.py index 169dad0..e9cbd86 100644 --- a/src/elm/services/ConfigurationService.py +++ b/src/elm/services/ConfigurationService.py @@ -66,8 +66,11 @@ class ConfigurationService: def get_database_configuration(self) -> DatabaseConfiguration: try: return DatabaseConfiguration( - database_address=self._config["database"]["database_address"], + database_host=self._config["database"]["database_host"], + database_port=self._config["database"]["database_port"], database_name=self._config["database"]["database_name"], + database_user=self._config["database"]["database_user"], + database_password=self._config["database"]["database_password"], ) except KeyError: logger.fatal("Error loading DatabaseConfiguration, exiting...") diff --git a/src/elm/services/DatabaseService.py b/src/elm/services/DatabaseService.py index 2de3a32..4fa5985 100644 --- a/src/elm/services/DatabaseService.py +++ b/src/elm/services/DatabaseService.py @@ -24,14 +24,24 @@ class DatabaseService: self._db_config = db_config self._client = None self._database = None - self._users = None async def initialize(self) -> None: + mongo_uri = f"mongodb://{self._db_config.database_user}:{self._db_config.database_password}@{self._db_config.database_host}:{self._db_config.database_port}/{self._db_config.database_name}?authSource=admin" if self._client is None: - self._client = AsyncMongoClient(self._db_config.database_address) - self._database = self._client[self._db_config.database_name] - self._users: AsyncCollection = self._database["users"] + self._client = AsyncMongoClient(mongo_uri) + + self._database = self._client[ + self._db_config.database_name + ] + await init_beanie( database=self._database, - document_models=[User, Transaction, Ticket, Seat, CateringTypes.CateringMenuItem, CateringTypes.CateringOrder] + document_models=[ + User, + Transaction, + Ticket, + Seat, + CateringTypes.CateringMenuItem, + CateringTypes.CateringOrder + ] ) diff --git a/src/elm/types/ConfigurationTypes.py b/src/elm/types/ConfigurationTypes.py index fbf6508..7a505d3 100644 --- a/src/elm/types/ConfigurationTypes.py +++ b/src/elm/types/ConfigurationTypes.py @@ -16,8 +16,11 @@ class MailingServiceConfiguration: @dataclass(frozen=True) class DatabaseConfiguration: - database_address: str + database_host: str + database_port: str database_name: str + database_user: str + database_password :str @dataclass(frozen=True) class LanInfo: