From 58e69ba69e8f5bc598f48010f67ffc78c9db6ffa Mon Sep 17 00:00:00 2001 From: Marius Robert Macamete Date: Wed, 17 Sep 2025 09:14:30 +0300 Subject: [PATCH] add docker files --- .env | 13 +++++++++ client/Dockerfile | 31 ++++++++++++++++++++ docker-compose.yml | 70 ++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 6 ++++ solarDb/Dockerfile | 32 +++++++++++++++++++++ solarDb/wsgi.py | 1 + 6 files changed, 153 insertions(+) create mode 100644 .env create mode 100644 client/Dockerfile create mode 100644 docker-compose.yml create mode 100644 requirements.txt create mode 100644 solarDb/Dockerfile create mode 100644 solarDb/wsgi.py diff --git a/.env b/.env new file mode 100644 index 0000000..3c5316e --- /dev/null +++ b/.env @@ -0,0 +1,13 @@ +# Public hosts for routing via nginx-proxy +SOLARDB_API_HOST=db.northdanubesoft.eu +SOLARDB_UI_HOST=db.northdanubesoft.eu + +LETSENCRYPT_EMAIL=macamete.robert@gmail.com + +# Flask +FLASK_ENV=production + +# (Optional) If your Flet main file differs: +# FLET_ENTRY=client/main.py + +# For your UI to call the API from the browser, ensure CORS is allowed on API or they share the same parent domain. \ No newline at end of file diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 0000000..96337e7 --- /dev/null +++ b/client/Dockerfile @@ -0,0 +1,31 @@ +# Dockerfile.ui +FROM python:3.13-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +RUN apt-get update && apt-get install -y --no-install-recommends curl \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Install all deps from unified requirements.txt +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy UI code + assets +COPY client/ ./client/ +COPY assets/ ./assets/ +COPY uploads/ ./uploads/ + +RUN mkdir -p /app/uploads + +ENV FLET_ENTRY=client/main.py \ + APP_PORT=5000 \ + API_BASE_URL=https://api.example.com + +EXPOSE 5000 + +HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD curl -fsS http://localhost:5000/ || exit 1 + +CMD ["python", "client/main.py"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..12120ef --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,70 @@ +version: "3.9" + +services: + solardb-api: + build: + context: . + dockerfile: Dockerfile.api + image: solardb-api:latest + container_name: solardb-api + restart: unless-stopped + env_file: + - .env + environment: + # nginx-proxy labels (env) for routing + certs + VIRTUAL_HOST: ${SOLARDB_API_HOST} + LETSENCRYPT_HOST: ${SOLARDB_API_HOST} + LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL} + # Flask/TinyDB + FLASK_ENV: ${FLASK_ENV:-production} + DB_PATH: /data/db.json + volumes: + - solardb_data:/data + expose: + - "5001" + networks: + - reverse-proxy_default + healthcheck: + test: ["CMD", "curl", "-fsS", "http://localhost:5001/healthz"] + interval: 30s + timeout: 5s + retries: 3 + + solardb-ui: + build: + context: . + dockerfile: Dockerfile.ui + image: solardb-ui:latest + container_name: solardb-ui + restart: unless-stopped + env_file: + - .env + environment: + VIRTUAL_HOST: ${SOLARDB_UI_HOST} + LETSENCRYPT_HOST: ${SOLARDB_UI_HOST} + LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL} + # Point your UI to the API public URL (https) + API_BASE_URL: https://${SOLARDB_API_HOST} + # If your entry file differs, uncomment and set it: + # FLET_ENTRY: client/main.py + volumes: + - solardb_uploads:/app/uploads + expose: + - "5000" + depends_on: + - solardb-api + networks: + - reverse-proxy_default + healthcheck: + test: ["CMD", "curl", "-fsS", "http://localhost:5000/"] + interval: 30s + timeout: 5s + retries: 3 + +volumes: + solardb_data: + solardb_uploads: + +networks: + reverse-proxy_default: + external: true \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..211584d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +flask==3.0.3 +tinydb==4.8.2 +gunicorn==22.0.0 +flet==0.23.2 +requests==2.32.3 +flask-cors==4.0.1 \ No newline at end of file diff --git a/solarDb/Dockerfile b/solarDb/Dockerfile new file mode 100644 index 0000000..b85f1da --- /dev/null +++ b/solarDb/Dockerfile @@ -0,0 +1,32 @@ +# Dockerfile.api +FROM python:3.13-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +RUN apt-get update && apt-get install -y --no-install-recommends curl \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Install all deps from unified requirements.txt +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy API code +COPY solarDb/ ./solarDb/ +COPY wsgi.py ./wsgi.py + +# Data dir for TinyDB +RUN mkdir -p /data && chown -R 1000:1000 /data +VOLUME ["/data"] + +ENV FLASK_ENV=production \ + APP_PORT=5001 \ + DB_PATH=/data/db.json + +EXPOSE 5001 + +HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD curl -fsS http://localhost:5001/healthz || exit 1 + +CMD ["gunicorn", "-k", "gthread", "-w", "2", "-b", "0.0.0.0:5001", "--graceful-timeout", "30", "wsgi:app"] \ No newline at end of file diff --git a/solarDb/wsgi.py b/solarDb/wsgi.py new file mode 100644 index 0000000..36ca8fc --- /dev/null +++ b/solarDb/wsgi.py @@ -0,0 +1 @@ +from solarDb.server import app \ No newline at end of file