From b71187009b288d39b80d0976200445262788a09c Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Thu, 7 Aug 2025 23:40:12 -0400 Subject: [PATCH] feat: update Docker setup for refactored app structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update Dockerfile to copy new app/ directory structure - Fix docker-compose.yml volume paths for app/static/uploads - Add environment variable support for new config system - Update migration service to use migrate_session_changes.py - Add .dockerignore for optimized builds - Remove obsolete version field from docker-compose.yml - Create comprehensive README_DOCKER.md documentation The Docker setup now fully supports the refactored Flask application with modular structure, authentication, and like system. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .dockerignore | 70 ++++++++++---------- Dockerfile | 8 ++- README_DOCKER.md | 160 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 11 ++-- 4 files changed, 206 insertions(+), 43 deletions(-) create mode 100644 README_DOCKER.md diff --git a/.dockerignore b/.dockerignore index a50f384..3a210af 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,46 +1,44 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv +venv/ + +# Database files (will be mounted as volume) +*.db + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + # Git .git .gitignore -# Python -__pycache__/ -*.py[cod] -*$py.class -*.so -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# Virtual Environment -venv/ -ENV/ - -# IDE -.idea/ +# IDE files .vscode/ +.idea/ *.swp *.swo -# Database -*.db +# Logs +logs/ +*.log -# Uploads -static/uploads/* -!static/uploads/.gitkeep +# Development files +.env +.env.local -# Docker -Dockerfile -.dockerignore \ No newline at end of file +# Cache directories +.cache/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ce05a39..e1979c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,11 +15,13 @@ RUN pip install uv # Copy project files COPY pyproject.toml . COPY main.py . -COPY templates/ templates/ +COPY app/ app/ +COPY migrate_session_changes.py . +COPY README_MIGRATION.md . COPY README.md . -# Create uploads directory -RUN mkdir -p static/uploads +# Create uploads directory in the correct location +RUN mkdir -p app/static/uploads # Create and activate virtual environment, then install dependencies RUN uv venv && \ diff --git a/README_DOCKER.md b/README_DOCKER.md new file mode 100644 index 0000000..1b0c287 --- /dev/null +++ b/README_DOCKER.md @@ -0,0 +1,160 @@ +# Docker Setup for Pets of Powerwashing + +## Updated for Refactored Architecture + +The Docker setup has been updated to work with the refactored Flask application structure. + +## Quick Start + +### 1. Build and Run +```bash +# Build and start the application +docker compose up --build + +# Or run in detached mode +docker compose up --build -d +``` + +### 2. Run Database Migration +```bash +# Run the migration (first time setup or after schema changes) +docker compose --profile migrate up migrate +``` + +### 3. Access the Application +- **Web Interface**: http://localhost:54321 +- **Admin Login**: username: `admin`, password: `password123` + +## File Structure Changes + +The refactored application now uses this structure: +``` +app/ +├── static/uploads/ # Upload directory (mounted as volume) +├── templates/ # HTML templates +├── models/ # Database models +├── routes/ # Route handlers (blueprints) +├── utils/ # Utilities and helpers +└── ... +``` + +## Docker Configuration + +### Environment Variables + +You can customize the application through environment variables: + +```yaml +environment: + # Flask settings + - FLASK_ENV=production + + # Application settings + - UPLOAD_FOLDER=app/static/uploads + - DATABASE_PATH=pet_pictures.db + - ADMIN_USERNAME=admin + - ADMIN_PASSWORD=password123 + + # Optional: Override secret key for production + - SECRET_KEY=your-secret-key-here +``` + +### Volume Mounts + +- `./app/static/uploads:/app/app/static/uploads` - Persistent file uploads +- `./pet_pictures.db:/app/pet_pictures.db` - Persistent database + +## Services + +### Web Service (`web`) +- **Port**: 54321 (maps to internal port 5000) +- **Process**: Gunicorn with 4 workers +- **Health Check**: HTTP check every 30 seconds +- **Restart Policy**: unless-stopped + +### Migration Service (`migrate`) +- **Purpose**: Database schema updates +- **Usage**: `docker compose --profile migrate up migrate` +- **Script**: Uses `migrate_session_changes.py` + +## Commands + +### Development +```bash +# Build only +docker compose build + +# View logs +docker compose logs -f + +# Stop services +docker compose down + +# Remove everything including volumes +docker compose down -v +``` + +### Production +```bash +# Start in production mode +FLASK_ENV=production docker compose up -d + +# Update and restart +docker compose pull +docker compose up --build -d +``` + +## Troubleshooting + +### Common Issues + +**1. Permission Issues with Uploads** +```bash +# Fix upload directory permissions +sudo chown -R 1000:1000 ./app/static/uploads +``` + +**2. Database Migration Fails** +```bash +# Run migration manually +docker compose exec web python migrate_session_changes.py +``` + +**3. Build Fails** +```bash +# Clean build +docker compose build --no-cache +``` + +### Health Check + +The application includes a health check that: +- Tests HTTP connectivity on port 5000 +- Retries 3 times with 5-second delays +- Runs every 30 seconds +- Allows 40 seconds for startup + +## Security Notes + +**For Production:** +1. Change default admin credentials via environment variables +2. Set a secure `SECRET_KEY` +3. Use HTTPS reverse proxy (nginx/traefik) +4. Limit file upload sizes +5. Regular database backups + +## File Locations in Container + +- **Application**: `/app/` +- **Database**: `/app/pet_pictures.db` +- **Uploads**: `/app/app/static/uploads/` +- **Logs**: `/app/logs/` (if logging enabled) + +## Changes from Previous Version + +✅ **Updated paths** for refactored app structure +✅ **New migration script** (`migrate_session_changes.py`) +✅ **Added environment variables** for configuration +✅ **Improved .dockerignore** for smaller builds +✅ **Removed obsolete version** from docker-compose.yml +✅ **Better volume mapping** for uploads directory \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 820f9dd..a38ff51 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,17 +1,20 @@ -version: "3.8" - services: web: build: . ports: - "54321:5000" volumes: - - ./static/uploads:/app/static/uploads + - ./app/static/uploads:/app/app/static/uploads - ./pet_pictures.db:/app/pet_pictures.db environment: - FLASK_APP=main.py - FLASK_ENV=production - GUNICORN_CMD_ARGS=--workers=4 --bind=0.0.0.0:5000 --timeout=120 --keep-alive=5 --worker-class=sync --worker-connections=1000 --max-requests=1000 --max-requests-jitter=50 + # Application configuration + - UPLOAD_FOLDER=app/static/uploads + - DATABASE_PATH=pet_pictures.db + - ADMIN_USERNAME=admin + - ADMIN_PASSWORD=password123 restart: unless-stopped healthcheck: test: @@ -36,6 +39,6 @@ services: build: . volumes: - ./pet_pictures.db:/app/pet_pictures.db - command: python migrate.py + command: python migrate_session_changes.py profiles: - migrate