From 1d30809507bbe35a1c41b02fbcf6bdb3e4f7bcb5 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Fri, 13 Jun 2025 17:08:34 -0400 Subject: [PATCH] feat: add Docker migration service --- README.md | 31 +++++++++++++++++++++++++++---- docker-compose.yml | 24 ++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bf69d94..6417635 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ A web application to manage pet pictures from subscribers. Built with Flask, SQL - Modern, responsive UI using Tailwind CSS - Click to view full-size images - Download original images +- Add descriptions to pet pictures ## Setup @@ -29,6 +30,26 @@ python main.py The application will be available at `http://localhost:5000` +### Database Migration + +#### Local Migration + +If you have an existing database and want to add the description field: + +```bash +python migrate.py +``` + +#### Docker Migration + +To run the migration in Docker: + +```bash +docker compose --profile migrate up migrate +``` + +This will safely add the description column to your existing database without affecting existing data. + ### Docker Deployment #### Using Docker Compose (Recommended) @@ -73,14 +94,16 @@ The application will be available at `http://localhost:54321` 1. Visit the homepage to see all uploaded pet pictures 2. Click "Upload New" to add a new pet picture 3. Fill in the subscriber name and select a picture -4. View uploaded pictures on the homepage -5. Click on any picture to view it in full size -6. Use the "Download Original" button to download the original file -7. Mark pictures as posted using the "Mark as Posted" button +4. Add an optional description for the pet picture +5. View uploaded pictures on the homepage +6. Click on any picture to view it in full size +7. Use the "Download Original" button to download the original file +8. Mark pictures as posted using the "Mark as Posted" button ## File Structure - `main.py` - Main Flask application +- `migrate.py` - Database migration script - `templates/` - Jinja2 templates - `base.html` - Base template with common layout - `index.html` - Homepage with picture grid diff --git a/docker-compose.yml b/docker-compose.yml index f151960..820f9dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,11 +11,31 @@ services: environment: - FLASK_APP=main.py - FLASK_ENV=production - - GUNICORN_CMD_ARGS=--workers=4 --bind=0.0.0.0:5000 --timeout=120 + - 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 restart: unless-stopped healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:5000"] + test: + [ + "CMD", + "curl", + "-f", + "http://localhost:5000/", + "--connect-timeout", + "5", + "--retry", + "3", + "--retry-delay", + "5", + ] interval: 30s timeout: 10s retries: 3 start_period: 40s + + migrate: + build: . + volumes: + - ./pet_pictures.db:/app/pet_pictures.db + command: python migrate.py + profiles: + - migrate