-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate Procfile and move to dockerfile
- Loading branch information
Showing
7 changed files
with
101 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM python:3.11-bookworm as builder | ||
|
||
RUN pip install poetry==1.7.1 | ||
|
||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
||
WORKDIR /app | ||
|
||
COPY pyproject.toml poetry.lock ./ | ||
RUN touch README.md | ||
|
||
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root | ||
|
||
FROM python:3.11-slim-bookworm as runtime | ||
|
||
ENV VIRTUAL_ENV=/app/.venv \ | ||
PATH="/app/.venv/bin:$PATH" | ||
|
||
RUN mkdir /data | ||
|
||
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} | ||
|
||
COPY src/rollbot ./rollbot | ||
|
||
ENTRYPOINT ["python", "-m", "rollbot"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import logging | ||
import os | ||
|
||
from rollbot.bot import bot | ||
from rollbot.db import SQLiteDB | ||
from rollbot.varenv import var_env_provider | ||
|
||
|
||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="[%(levelname)s] %(asctime)s - %(message)s", | ||
) | ||
token = os.environ["DISCORD_TOKEN"] | ||
db = SQLiteDB(os.environ["SQLITE_PATH"]) | ||
var_env_provider.set_db(db) | ||
|
||
bot.run(token) | ||
db.close() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
import redis | ||
from urllib.parse import urlparse | ||
import sqlite3 | ||
import json | ||
|
||
|
||
def make_db(url): | ||
url = urlparse(url) | ||
return redis.Redis(host=url.hostname, port=url.port, password=url.password) | ||
class SQLiteDB: | ||
def __init__(self, database_url: str): | ||
self.conn = sqlite3.connect(database_url) | ||
self.cursor = self.conn.cursor() | ||
|
||
# Create a table for key-value pairs if it doesn't exist | ||
self.cursor.execute( | ||
""" | ||
CREATE TABLE IF NOT EXISTS key_value ( | ||
key TEXT PRIMARY KEY, | ||
value TEXT | ||
) | ||
""" | ||
) | ||
self.conn.commit() | ||
|
||
def get(self, key: str) -> dict[str, str]: | ||
self.cursor.execute("SELECT value FROM key_value WHERE key = ?", (key,)) | ||
result = self.cursor.fetchone() | ||
if result is not None: | ||
return json.loads(result[0]) | ||
else: | ||
return {} | ||
|
||
def set(self, key: str, value: dict[str, str]) -> None: | ||
serialized_value = json.dumps(value) | ||
self.cursor.execute( | ||
"INSERT OR REPLACE INTO key_value (key, value) VALUES (?, ?)", | ||
(key, serialized_value), | ||
) | ||
self.conn.commit() | ||
|
||
def close(self): | ||
self.conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters