diff --git a/.gitignore b/.gitignore index d246dc3c..6f642d60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env .vscode/ -.idea/ \ No newline at end of file +.idea/ +venv/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6da0b3eb..8c8b6b4b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,11 @@ services: environment: - CLIENT_ID - TOKEN + - "DATABASE_USER=postgres" + - "DATABASE_PASS=postgres" + - "DATABASE_NAME=postgres" + - "DATABASE_HOST=db" + - "DATABASE_PORT=5432" restart: always api: build: src/ diff --git a/src/pluralkit/bot/__init__.py b/src/pluralkit/bot/__init__.py index 0f51c117..7d4af2ec 100644 --- a/src/pluralkit/bot/__init__.py +++ b/src/pluralkit/bot/__init__.py @@ -1,6 +1,7 @@ import asyncio import json import logging +import os import time from datetime import datetime @@ -111,7 +112,13 @@ class PluralKitBot: async def run(self): try: self.logger.info("Connecting to database...") - self.pool = await db.connect() + self.pool = await db.connect( + os.environ["DATABASE_USER"], + os.environ["DATABASE_PASS"], + os.environ["DATABASE_NAME"], + os.environ["DATABASE_HOST"], + int(os.environ["DATABASE_PORT"]) + ) self.logger.info("Attempting to create tables...") async with self.pool.acquire() as conn: diff --git a/src/pluralkit/db.py b/src/pluralkit/db.py index 91d4ea49..431c9acb 100644 --- a/src/pluralkit/db.py +++ b/src/pluralkit/db.py @@ -11,10 +11,10 @@ from discord.utils import snowflake_time from pluralkit import System, Member, stats logger = logging.getLogger("pluralkit.db") -async def connect(): +async def connect(username, password, database, host, port): while True: try: - return await asyncpg.create_pool(user="postgres", password="postgres", database="postgres", host="db") + return await asyncpg.create_pool(user=username, password=password, database=database, host=host, port=port) except (ConnectionError, asyncpg.exceptions.CannotConnectNowError): pass