From 02247340d495dc69f407e9c6eda0b6a8f97837f9 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Thu, 7 Aug 2025 23:56:14 -0400 Subject: [PATCH 1/2] fix: resolve image display issues after refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix upload folder path to be relative to Flask app static folder - Update app initialization to use proper static folder structure - Change default development port to 5001 to avoid AirPlay conflicts - Images now display correctly in both public and admin views The refactored app now properly serves uploaded images from the correct static file location. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app/__init__.py | 5 ++++- app/config.py | 4 ++-- main.py | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 27b2d75..b978d6c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -15,7 +15,10 @@ def create_app(): app.config.from_object(Config) # Ensure upload directory exists - os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) + upload_path = os.path.join(app.static_folder, 'uploads') + os.makedirs(upload_path, exist_ok=True) + # Update config to use absolute path for file operations + app.config['UPLOAD_FOLDER'] = upload_path # Setup logging from app.utils.logging_config import setup_logging diff --git a/app/config.py b/app/config.py index 28b860f..64c7bd8 100644 --- a/app/config.py +++ b/app/config.py @@ -11,8 +11,8 @@ class Config: # Flask settings SECRET_KEY = os.environ.get('SECRET_KEY') or os.urandom(24) - # Upload settings - UPLOAD_FOLDER = os.environ.get('UPLOAD_FOLDER') or 'app/static/uploads' + # Upload settings + UPLOAD_FOLDER = os.environ.get('UPLOAD_FOLDER') or 'static/uploads' MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB max file size ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} diff --git a/main.py b/main.py index cb68abb..d038634 100644 --- a/main.py +++ b/main.py @@ -15,4 +15,5 @@ app = create_app() if __name__ == "__main__": # Development server configuration debug_mode = os.environ.get('FLASK_ENV') == 'development' - app.run(debug=debug_mode, host='0.0.0.0', port=5000) + port = int(os.environ.get('PORT', 5001)) # Use port 5001 to avoid AirPlay conflict + app.run(debug=debug_mode, host='0.0.0.0', port=port) -- 2.49.1 From 8814dd899491b9f1d251f4ee95fda694c3ead2a5 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Thu, 7 Aug 2025 23:59:00 -0400 Subject: [PATCH 2/2] perf: reduce Gunicorn workers to 1 for stability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change from 4 workers to 1 worker in both Dockerfile and docker-compose.yml - Helps reduce resource usage and connection reset issues - Better for single-user or low-traffic deployment scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- Dockerfile | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e1979c0..76c5a4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN uv venv && \ ENV FLASK_APP=main.py ENV FLASK_ENV=production ENV PATH="/app/.venv/bin:$PATH" -ENV GUNICORN_CMD_ARGS="--workers=4 --bind=0.0.0.0:5000 --timeout=120" +ENV GUNICORN_CMD_ARGS="--workers=1 --bind=0.0.0.0:5000 --timeout=120" # Expose port EXPOSE 5000 diff --git a/docker-compose.yml b/docker-compose.yml index a38ff51..93db27d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: 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 + - GUNICORN_CMD_ARGS=--workers=1 --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 -- 2.49.1