From e6a50d140e7621a65d2aa2b72247082589dbfa4c Mon Sep 17 00:00:00 2001 From: Ke-vin-S Date: Sun, 11 May 2025 00:06:29 +0530 Subject: [PATCH] Docker-compose setup --- .env.example | 11 +++++++++++ Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++++ docker-compose.yaml | 14 ++++++++++++++ entrypoint.sh | 8 ++++++++ 4 files changed, 75 insertions(+) create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 docker-compose.yaml create mode 100644 entrypoint.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..16b126e --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# Django settings +DJANGO_SECRET_KEY=your-secret-key +DJANGO_DEBUG=True +DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 + +# Custom port override (optional) +HOST_PORT=8004 +PORT=8000 + +# Optional database settings (if using a remote DB) +# DATABASE_URL=postgresql://user:password@host:5432/dbname \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bf20bc9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM python:3.11-slim + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +# Set working directory +WORKDIR /app + +# Install system dependencies for Prophet and others +RUN apt-get update && apt-get install -y \ + build-essential \ + libpq-dev \ + gcc \ + g++ \ + curl \ + libatlas-base-dev \ + libblas-dev \ + liblapack-dev \ + libgfortran5 \ + libffi-dev \ + libpython3-dev \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements and install +COPY requirements.txt . +RUN pip install --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the code +COPY . . + +# Optional: run migrations here or in entrypoint +# RUN python forecast_system/manage.py migrate + +# Copy and set permissions for entrypoint +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Set entrypoint +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f63ea39 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,14 @@ +version: '3.9' + +services: + forecasting-app: + build: . + container_name: forecasting_app + ports: + - "${HOST_PORT:-8000}:8000" + env_file: + - .env + volumes: + - .:/app + working_dir: /app/forecast_system + restart: unless-stopped diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..92e9aaf --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +echo "📦 Running migrations..." +python manage.py migrate + +PORT=${PORT:-8000} +echo "🚀 Starting Django server on port $PORT" +python manage.py runserver 0.0.0.0:$PORT