From f73c66c1a1c6aff42c9afa062cc711233e568100 Mon Sep 17 00:00:00 2001 From: Sami Abuzakuk Date: Sun, 12 Oct 2025 17:09:35 +0200 Subject: [PATCH] Update dockerfile --- Dockerfile | 27 ++++++++++++--------------- backend/requirements.txt | 2 ++ docker/crontab | 2 -- docker/entry.sh | 12 ++++++++---- docker/services.cron | 2 ++ frontend/src/lib/api.ts | 4 +++- 6 files changed, 27 insertions(+), 22 deletions(-) delete mode 100644 docker/crontab create mode 100644 docker/services.cron diff --git a/Dockerfile b/Dockerfile index 36b6792..2e1251b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,31 +5,28 @@ FROM python:3.12-slim RUN apt-get update && apt-get install -y \ curl \ cron \ - && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ && apt-get install -y nodejs \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Setup backend WORKDIR /app/backend -COPY backend/* . +ADD backend . +RUN python3 -m venv venv +RUN . /app/backend/venv/bin/activate && pip install -r requirements.txt -RUN pip install -r requirements.txt - -# Setup frontend WORKDIR /app/frontend -COPY frontend/* . - -# Setup docker -WORKDIR /app/docker -COPY docker/* /app/docker/ - -RUN chmod +x entry.sh -RUN chmod 0644 cronfile +ADD frontend . WORKDIR /app -EXPOSE 5173 +COPY docker/* . +RUN chmod 0644 services.cron +RUN crontab services.cron +RUN chmod +x entry.sh + +EXPOSE 8080 8000 # Command to start cron and the backend -CMD ["sh", "-c", "/app/docker/entry.sh"] +CMD ["sh", "-c", "/app/entry.sh"] diff --git a/backend/requirements.txt b/backend/requirements.txt index 6d8abca..29d0507 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,2 +1,4 @@ requests uvicorn +fastapi +sqlalchemy diff --git a/docker/crontab b/docker/crontab deleted file mode 100644 index 702de83..0000000 --- a/docker/crontab +++ /dev/null @@ -1,2 +0,0 @@ -*/1 * * * * python3 /app/backend/get_notifications.py -*/5 * * * * python3 /app/backend/run_scripts.py diff --git a/docker/entry.sh b/docker/entry.sh index a7345f9..67cce83 100644 --- a/docker/entry.sh +++ b/docker/entry.sh @@ -1,9 +1,12 @@ #!/bin/bash -# Navigate to the frontend directory and start the Svelte app +source /app/backend/venv/bin/activate + +# Navigate to the frontend directory, install dependencies, and start the Svelte app cd frontend +npm install npm run build -npm run dev & +npm run dev -- --host 0.0.0.0 --port 8080 & # Navigate back to the root directory cd .. @@ -14,8 +17,9 @@ python3 -m venv venv cd ../.. # Start the backend using uvicorn -uvicorn backend.backend:app --host 0.0.0.0 --port 8000 & +cd backend +uvicorn backend:app --host 0.0.0.0 --port 8000 & +cd .. # Start the cron daemon -crontab docker/cronfile cron -f diff --git a/docker/services.cron b/docker/services.cron new file mode 100644 index 0000000..f15999d --- /dev/null +++ b/docker/services.cron @@ -0,0 +1,2 @@ +*/1 * * * * . /app/backend/venv/bin/activate && python3 /app/backend/get_notifications.py >> /var/log/cron.log 2>&1 +*/5 * * * * cd /app/backend && . /app/backend/venv/bin/activate && python3 /app/backend/run_scripts.py >> /var/log/cron.log 2>&1 diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 9174e0b..89c873e 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,4 +1,6 @@ -export const API_URL = 'http://127.0.0.1:8000'; +import { env } from '$env/dynamic/public'; + +export const API_URL = env.PUBLIC_API_URL || 'http://localhost:8080'; /** * Type definitions for Subscriptions and Notifications