From 5fc19f6ccb4e64cf2366ee47975e961ef8d86cfc Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 5 Jul 2025 10:55:32 +0200 Subject: [PATCH] Solved other port bugs --- Dockerfile | 8 +------- app/app.py | 12 +++++++----- docker-compose.yml | 1 + main.py | 1 - 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1688963..932cdd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,5 @@ RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY app/ . -# Set default port environment variable -ENV PORT=5000 - -# Expose port (optional for documentation) -EXPOSE ${PORT} - # Start command using shell to allow env substitution -CMD ["sh", "-c", "exec python app.py --port=${PORT}"] +CMD sh -c "exec python app.py --port=\${PORT}" diff --git a/app/app.py b/app/app.py index 5e29965..86a644d 100644 --- a/app/app.py +++ b/app/app.py @@ -4,6 +4,12 @@ import yaml from utils.configuration_resolver import ConfigurationResolver from utils.cache_manager import CacheManager from utils.compute_card_classes import compute_card_classes +import logging +logging.basicConfig(level=logging.DEBUG) +FLASK_ENV = os.getenv("FLASK_ENV", "production") +FLASK_PORT = int(os.getenv("PORT", 5000)) +print(f"🔧 Starting app on port {FLASK_PORT}, FLASK_ENV={FLASK_ENV}") + # Initialize the CacheManager cache_manager = CacheManager() @@ -31,9 +37,6 @@ def cache_icons_and_logos(app): app.config["platform"]["favicon"]["cache"] = cache_manager.cache_file(app.config["platform"]["favicon"]["source"]) app.config["platform"]["logo"]["cache"] = cache_manager.cache_file(app.config["platform"]["logo"]["source"]) -# Get the environment variable FLASK_ENV or set a default value -FLASK_ENV = os.getenv("FLASK_ENV", "production") - # Initialize Flask app app = Flask(__name__) @@ -64,5 +67,4 @@ def index(): ) if __name__ == "__main__": - port = int(os.getenv("PORT", 5000)) - app.run(debug=(FLASK_ENV == "development"), host="0.0.0.0", port=port) + app.run(debug=(FLASK_ENV == "development"), host="0.0.0.0", port=FLASK_PORT) diff --git a/docker-compose.yml b/docker-compose.yml index d2b6aee..0b49458 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: - "${PORT:-5000}:${PORT:-5000}" volumes: - ./app:/app + - ./.env:/app./.env environment: - PORT=${PORT:-5000} restart: unless-stopped diff --git a/main.py b/main.py index de868ad..e5bf450 100755 --- a/main.py +++ b/main.py @@ -25,7 +25,6 @@ import os from dotenv import load_dotenv from pathlib import Path -# Always load .env from the script's directory dotenv_path = Path(__file__).resolve().parent / ".env" if dotenv_path.exists():