Solved wrong environment bug

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-05 11:41:18 +02:00
parent 9c24a8658f
commit 86fd72b623
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
2 changed files with 5 additions and 10 deletions

View File

@ -14,4 +14,5 @@ services:
- ./.env:/app./.env - ./.env:/app./.env
environment: environment:
- PORT=${PORT:-5000} - PORT=${PORT:-5000}
- FLASK_ENV=${FLASK_ENV:-production}
restart: unless-stopped restart: unless-stopped

14
main.py
View File

@ -33,14 +33,14 @@ else:
print(f"⚠️ Warning: No .env file found at {dotenv_path}") print(f"⚠️ Warning: No .env file found at {dotenv_path}")
PORT = int(os.getenv("PORT", 5000)) PORT = int(os.getenv("PORT", 5000))
def run_command(command, dry_run=False): def run_command(command, dry_run=False, env=None):
"""Utility function to run a shell command.""" """Utility function to run a shell command."""
print(f"Executing: {' '.join(command)}") print(f"Executing: {' '.join(command)}")
if dry_run: if dry_run:
print("Dry run enabled: command not executed.") print("Dry run enabled: command not executed.")
return return
try: try:
subprocess.check_call(command) subprocess.check_call(command, env=env)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
print(f"Error: Command failed with exit code {e.returncode}") print(f"Error: Command failed with exit code {e.returncode}")
sys.exit(e.returncode) sys.exit(e.returncode)
@ -147,18 +147,12 @@ def logs(args):
def dev(args): def dev(args):
""" """
Run the application in development mode using docker-compose. Run the application in development mode using docker-compose.
Command:
FLASK_ENV=development docker-compose up -d
This command sets the FLASK_ENV environment variable to 'development'
and starts the application using docker-compose, enabling hot-reloading.
""" """
env = os.environ.copy() env = os.environ.copy()
env["FLASK_ENV"] = "development" env["FLASK_ENV"] = "development"
command = ["docker-compose", "up", "-d"] command = ["docker-compose", "up", "-d"]
print("Setting FLASK_ENV=development") print("▶️ Starting in development mode (FLASK_ENV=development)")
run_command(command, args.dry_run) run_command(command, args.dry_run, env=env)
def prod(args): def prod(args):
""" """