updated docker compose files
This commit is contained in:
70
py_app/app/db_create_scripts/docker_setup_wrapper.py
Normal file
70
py_app/app/db_create_scripts/docker_setup_wrapper.py
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Docker-compatible Database Setup Script
|
||||
Reads configuration from environment variables or config file
|
||||
"""
|
||||
|
||||
import mariadb
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
def get_db_config():
|
||||
"""Get database configuration from environment or config file"""
|
||||
# Try environment variables first (Docker)
|
||||
if os.getenv('DB_HOST'):
|
||||
return {
|
||||
"user": os.getenv('DB_USER', 'trasabilitate'),
|
||||
"password": os.getenv('DB_PASSWORD', 'Initial01!'),
|
||||
"host": os.getenv('DB_HOST', 'localhost'),
|
||||
"port": int(os.getenv('DB_PORT', '3306')),
|
||||
"database": os.getenv('DB_NAME', 'trasabilitate')
|
||||
}
|
||||
|
||||
# Fallback to config file (traditional deployment)
|
||||
config_file = os.path.join(os.path.dirname(__file__), '../../instance/external_server.conf')
|
||||
if os.path.exists(config_file):
|
||||
settings = {}
|
||||
with open(config_file, 'r') as f:
|
||||
for line in f:
|
||||
if '=' in line:
|
||||
key, value = line.strip().split('=', 1)
|
||||
settings[key] = value
|
||||
|
||||
return {
|
||||
"user": settings.get('username', 'trasabilitate'),
|
||||
"password": settings.get('password', 'Initial01!'),
|
||||
"host": settings.get('server_domain', 'localhost'),
|
||||
"port": int(settings.get('port', '3306')),
|
||||
"database": settings.get('database_name', 'trasabilitate')
|
||||
}
|
||||
|
||||
# Default configuration
|
||||
return {
|
||||
"user": "trasabilitate",
|
||||
"password": "Initial01!",
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
"database": "trasabilitate"
|
||||
}
|
||||
|
||||
def print_step(step_num, description):
|
||||
"""Print formatted step information"""
|
||||
print(f"\n{'='*60}")
|
||||
print(f"Step {step_num}: {description}")
|
||||
print('='*60)
|
||||
|
||||
def print_success(message):
|
||||
"""Print success message"""
|
||||
print(f"✅ {message}")
|
||||
|
||||
def print_error(message):
|
||||
"""Print error message"""
|
||||
print(f"❌ {message}")
|
||||
|
||||
# Get configuration
|
||||
DB_CONFIG = get_db_config()
|
||||
|
||||
print(f"Using database configuration: {DB_CONFIG['user']}@{DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']}")
|
||||
|
||||
# Import the rest from the original setup script
|
||||
@@ -5,6 +5,7 @@ This script creates all necessary database tables, triggers, and initial data
|
||||
for quick deployment of the application.
|
||||
|
||||
Usage: python3 setup_complete_database.py
|
||||
Supports both traditional and Docker deployments via environment variables.
|
||||
"""
|
||||
|
||||
import mariadb
|
||||
@@ -13,12 +14,13 @@ import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
# Database configuration
|
||||
# Database configuration - supports environment variables (Docker) or defaults
|
||||
DB_CONFIG = {
|
||||
"user": "trasabilitate",
|
||||
"password": "Initial01!",
|
||||
"host": "localhost",
|
||||
"database": "trasabilitate"
|
||||
"user": os.getenv("DB_USER", "trasabilitate"),
|
||||
"password": os.getenv("DB_PASSWORD", "Initial01!"),
|
||||
"host": os.getenv("DB_HOST", "localhost"),
|
||||
"port": int(os.getenv("DB_PORT", "3306")),
|
||||
"database": os.getenv("DB_NAME", "trasabilitate")
|
||||
}
|
||||
|
||||
def print_step(step_num, description):
|
||||
|
||||
Reference in New Issue
Block a user