From f7d010f28d7f1b93f370d54472eebc26430103ffbc45ed774ab37d509646c254 Mon Sep 17 00:00:00 2001 From: Timothy Kim Date: Mon, 19 Jan 2026 20:41:48 -0500 Subject: [PATCH] Use Docker for local development environment - Update README and CLAUDE.md with Docker-based dev workflow - Add Dockerfile for containerized deployment - Add gunicorn to requirements.txt - Dev uses volume mount for live code reloading Co-Authored-By: Claude Opus 4.5 --- CLAUDE.md | 23 ++++++++++++----------- Dockerfile | 26 ++++++++++++++++++++++++++ README.md | 22 ++++++++++------------ src/requirements.txt | 1 + 4 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 Dockerfile diff --git a/CLAUDE.md b/CLAUDE.md index a45e717..c9c3304 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -17,7 +17,7 @@ Kebuu is a spending tracker web app built with Flask. Currently in early develop - **Backend**: Flask 3.0, SQLAlchemy, Flask-Login - **Auth**: bcrypt password hashing, Altcha CAPTCHA (self-hosted) - **Forms**: Flask-WTF with CSRF protection -- **Server**: Gunicorn (production), Flask dev server (local) +- **Server**: Docker + Gunicorn (dev and prod) - **Database**: SQLite (dev), PostgreSQL (prod) ## Directory Structure @@ -42,23 +42,24 @@ src/ ## Commands -### Local Development -```bash -cd src -pip install -r requirements.txt -python app.py -``` - -### Docker +### Build ```bash docker build -t kebuu . +``` + +### Development +```bash +docker run -p 5000:5000 --env-file .env.dev -v $(pwd)/src:/app kebuu +``` + +### Production +```bash docker run -p 5000:5000 --env-file .env.prod kebuu ``` ### Testing ```bash -cd src -python -m unittest discover +docker run --env-file .env.dev kebuu python -m unittest discover ``` ## Environment Variables diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0c23b53 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM python:3.12-slim + +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements first for better caching +COPY src/requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY src/ . + +# Create non-root user for security +RUN useradd --create-home appuser && chown -R appuser:appuser /app +USER appuser + +EXPOSE 5000 + +# Default to production; override with --env-file at runtime +CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:create_app()"] diff --git a/README.md b/README.md index 2a91492..4fe1667 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,7 @@ A spending tracker web application built with Flask. ## Setup -### 1. Install Dependencies - -```bash -cd src -pip install -r requirements.txt -``` - -### 2. Create Environment Files +### 1. Create Environment Files Copy the example file and configure for your environment: @@ -33,17 +26,22 @@ Generate secure keys with: python -c "import secrets; print(secrets.token_hex(32))" ``` +### 2. Build Docker Image + +```bash +docker build -t kebuu . +``` + ### 3. Run the Application **Development:** ```bash -cd src -python app.py +docker run -p 5000:5000 --env-file .env.dev -v $(pwd)/src:/app kebuu ``` +The volume mount (`-v`) enables live code reloading during development. -**Production (Docker):** +**Production:** ```bash -docker build -t kebuu . docker run -p 5000:5000 --env-file .env.prod kebuu ``` diff --git a/src/requirements.txt b/src/requirements.txt index 7171dc0..44e442b 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -6,3 +6,4 @@ bcrypt==4.1.2 python-dotenv==1.0.0 email-validator==2.1.0 altcha==0.1.2 +gunicorn==21.2.0