From 972247ee5bac6cb4e49bfc4bfcbe85b4188b55f1 Mon Sep 17 00:00:00 2001 From: Rainy21 Date: Thu, 19 Mar 2026 02:36:53 -0400 Subject: [PATCH] added docker and modify the file so it work --- .dockerignore | 7 +++++++ Dockerfile | 20 ++++++++++++++++++++ cache/__init__.py | 0 cache/redis_client.py | 6 +++++- db/__init__.py | 0 db/urls.db | Bin 16384 -> 16384 bytes docker-compose.yml | 17 +++++++++++++++++ main.py | 26 ++++++++++++++++++-------- requirements.txt | 4 ++++ 9 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 cache/__init__.py create mode 100644 db/__init__.py create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8a1ca13 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.venv +__pycache__ +.pytest_cache +.git +test/ +*.db +server.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..966d31d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.11-slim + +# Set the working directory +WORKDIR /app + +# Copy the requirements file and install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code +COPY . . + +# Ensure the database directory exists for SQLite persistence +RUN mkdir -p /app/db + +# Expose the application port +EXPOSE 8000 + +# Command to start the application +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/cache/__init__.py b/cache/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cache/redis_client.py b/cache/redis_client.py index b54de85..259f03c 100644 --- a/cache/redis_client.py +++ b/cache/redis_client.py @@ -1,3 +1,7 @@ import redis +import os -redis_client = redis.Redis(host="localhost", port=6379, decode_responses=True) +redis_host = os.getenv("REDIS_HOST", "localhost") +redis_port = int(os.getenv("REDIS_PORT", 6379)) + +redis_client = redis.Redis(host=redis_host, port=redis_port, decode_responses=True) diff --git a/db/__init__.py b/db/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/db/urls.db b/db/urls.db index dc569a6566c77ef272281a43e6301f03a43ecf8f..d41cbb0e61b2cf42a11de6e73fb7be9ded401043 100644 GIT binary patch delta 468 zcmZo@U~Fh$oFL7}K2gS*k$q#r5`G>QzJm<>8~DTd{_!2$EGV#%uil!4l|jS* zJkl+rq@X0wS52K_n9sGczYA0DhBxrvLx| delta 60 scmZo@U~Fh$oFL7}JW