diff --git a/.dockerignore b/.dockerignore index f0a8e50..f545a73 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,21 +1,54 @@ +# Version control .git .gitignore -__pycache__/ -*.py[cod] -*.so -*.egg -*.egg-info/ -.venv/ -env/ -venv/ -build/ -dist/ -node_modules/ -.DS_Store -.env -.env.* -delphi.db -cookies.txt -data-import/* -!data-import/.gitkeep +# Python +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +env +pip-log.txt +pip-delete-this-directory.txt +.tox +.coverage +.coverage.* +.pytest_cache +nosetests.xml +coverage.xml +*.cover +*.log +.venv +venv/ + +# IDE +.vscode +.idea +*.swp +*.swo +*~ + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Documentation +README.md +TODO.md +*.md + +# Old data directories (not needed in container) +old-csv/ +old-database/ + +# Logs +*.log + +# Temporary files +*.tmp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index be396da..0d44b75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,33 @@ -FROM python:3.12-slim - -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 +# Use Python 3.13 slim image as base +FROM python:3.13-slim +# Set working directory WORKDIR /app -# Minimal tooling for healthcheck -RUN apt-get update && apt-get install -y --no-install-recommends curl \ +# Install system dependencies +RUN apt-get update && apt-get install -y \ + gcc \ && rm -rf /var/lib/apt/lists/* -COPY requirements.txt ./ +# Copy requirements first for better layer caching +COPY requirements.txt . + +# Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt -# Copy application -COPY app ./app -COPY static ./static -COPY delphi-logo.webp ./delphi-logo.webp -COPY old-csv ./old-csv -COPY old-database ./old-database -COPY data-import ./data-import +# Copy application code +COPY . . -ENV DATABASE_URL=sqlite:///./delphi.db +# Create non-root user for security +RUN useradd --create-home --shell /bin/bash app && chown -R app:app /app +USER app +# Expose port EXPOSE 8000 -HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD curl -fsS http://localhost:8000/health || exit 1 - -CMD ["uvicorn","app.main:app","--host","0.0.0.0","--port","8000"] +# Health check +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:8000/health || exit 1 +# Run the application +CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/delphi.db b/delphi.db index 8330bff..75208c5 100644 Binary files a/delphi.db and b/delphi.db differ diff --git a/docker-compose.yml b/docker-compose.yml index 3b57e71..922e6dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,24 @@ -version: "3.9" +version: '3.8' services: - web: + delphi-db: build: . - container_name: delphicg-web ports: - "8000:8000" environment: - - SECRET_KEY=${SECRET_KEY} + - SECRET_KEY=your-secret-key-here-change-this-in-production - DATABASE_URL=sqlite:///./delphi.db volumes: - - ./data-import:/app/data-import + # Mount the database file so it persists between container restarts - ./delphi.db:/app/delphi.db - - ./old-csv:/app/old-csv:ro - - ./static/logo:/app/static/logo + # Mount data-import directory for file uploads + - ./data-import:/app/data-import + # Mount static files + - ./static:/app/static + restart: unless-stopped healthcheck: - test: ["CMD-SHELL", "curl -fsS http://localhost:8000/health || exit 1"] + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] interval: 30s - timeout: 3s + timeout: 10s retries: 3 - + start_period: 40s \ No newline at end of file