# DigiServer Deployment Commands This document contains all necessary `docker exec` commands to deploy and configure DigiServer on a new PC with the same settings as the production system. ## Prerequisites ```bash # Ensure you're in the project directory cd /path/to/digiserver-v2 # Start the containers docker-compose up -d ``` ## 1. Database Initialization and Migrations ### Run all database migrations in sequence: ```bash # Create https_config table docker-compose exec -T digiserver-app python /app/migrations/add_https_config_table.py # Create player_user table docker-compose exec -T digiserver-app python /app/migrations/add_player_user_table.py # Add email to https_config table docker-compose exec -T digiserver-app python /app/migrations/add_email_to_https_config.py # Migrate player_user global settings docker-compose exec -T digiserver-app python /app/migrations/migrate_player_user_global.py ``` **Note:** The `-T` flag prevents Docker from allocating a pseudo-terminal, which is useful for automated deployments. ## 2. HTTPS Configuration via CLI ### Check HTTPS Configuration Status: ```bash docker-compose exec -T digiserver-app python /app/https_manager.py status ``` ### Enable HTTPS with Production Settings: ```bash docker-compose exec -T digiserver-app python /app/https_manager.py enable \ digiserver \ digiserver.sibiusb.harting.intra \ admin@example.com \ 10.76.152.164 \ 443 ``` ### Show Detailed Configuration: ```bash docker-compose exec -T digiserver-app python /app/https_manager.py show ``` ## 3. Admin User Setup ### Create/Reset Admin User (if needed): ```bash docker-compose exec -T digiserver-app python -c " from app.app import create_app from app.models.user import User from app.extensions import db app = create_app() with app.app_context(): # Check if admin exists admin = User.query.filter_by(username='admin').first() if admin: print('āœ… Admin user already exists') else: # Create new admin user admin = User(username='admin', email='admin@example.com') admin.set_password('admin123') # Change this password! admin.is_admin = True db.session.add(admin) db.session.commit() print('āœ… Admin user created with username: admin') " ``` ## 4. Database Verification ### Check Database Tables: ```bash docker-compose exec -T digiserver-app python -c " from app.app import create_app from app.extensions import db from sqlalchemy import inspect app = create_app() with app.app_context(): inspector = inspect(db.engine) tables = inspector.get_table_names() print('šŸ“Š Database Tables:') for table in sorted(tables): print(f' āœ“ {table}') print(f'\\nāœ… Total tables: {len(tables)}') " ``` ### Check HTTPS Configuration in Database: ```bash docker-compose exec -T digiserver-app python -c " from app.app import create_app from app.models.https_config import HTTPSConfig app = create_app() with app.app_context(): config = HTTPSConfig.get_config() if config: print('āœ… HTTPS Configuration Found:') print(f' Status: {\"ENABLED\" if config.https_enabled else \"DISABLED\"}') print(f' Hostname: {config.hostname}') print(f' Domain: {config.domain}') print(f' IP Address: {config.ip_address}') print(f' Port: {config.port}') else: print('āš ļø No HTTPS configuration found') " ``` ## 5. Health Checks ### Test Caddy Configuration: ```bash docker-compose exec -T caddy caddy validate --config /etc/caddy/Caddyfile ``` ### Test Flask Application Health: ```bash docker-compose exec -T digiserver-app python -c " import urllib.request try: response = urllib.request.urlopen('http://localhost:5000/health', timeout=5) print('āœ… Application is responding') print(f' Status: {response.status}') except Exception as e: print(f'āŒ Application health check failed: {e}') " ``` ### Check Docker Container Logs: ```bash # Flask app logs docker-compose logs digiserver-app | tail -50 # Caddy logs docker-compose logs caddy | tail -50 ``` ## 6. Complete Deployment Script Create a file called `deploy.sh` to run all steps automatically: ```bash #!/bin/bash set -e echo "šŸš€ DigiServer Deployment Script" echo "==================================" echo "" # Change to project directory cd /path/to/digiserver-v2 # Step 1: Start containers echo "šŸ“¦ Starting containers..." docker-compose up -d sleep 5 # Step 2: Run migrations echo "šŸ“Š Running database migrations..." docker-compose exec -T digiserver-app python /app/migrations/add_https_config_table.py docker-compose exec -T digiserver-app python /app/migrations/add_player_user_table.py docker-compose exec -T digiserver-app python /app/migrations/add_email_to_https_config.py docker-compose exec -T digiserver-app python /app/migrations/migrate_player_user_global.py # Step 3: Configure HTTPS echo "šŸ”’ Configuring HTTPS..." docker-compose exec -T digiserver-app python /app/https_manager.py enable \ digiserver \ digiserver.sibiusb.harting.intra \ admin@example.com \ 10.76.152.164 \ 443 # Step 4: Verify setup echo "āœ… Verifying setup..." docker-compose exec -T digiserver-app python /app/https_manager.py status echo "" echo "šŸŽ‰ Deployment Complete!" echo "==================================" echo "Access your application at:" echo " - https://digiserver" echo " - https://10.76.152.164" echo " - https://digiserver.sibiusb.harting.intra" echo "" echo "Login with:" echo " Username: admin" echo " Password: (check your password settings)" ``` Make it executable: ```bash chmod +x deploy.sh ``` Run it: ```bash ./deploy.sh ``` ## 7. Troubleshooting ### Restart Services: ```bash # Restart all containers docker-compose restart # Restart just the app docker-compose restart digiserver-app # Restart just Caddy docker-compose restart caddy ``` ### View Caddy Configuration: ```bash docker-compose exec -T caddy cat /etc/caddy/Caddyfile ``` ### Test HTTPS Endpoints: ```bash # Test from host machine (if accessible) curl -k https://digiserver.sibiusb.harting.intra # Test from within containers docker-compose exec -T caddy wget --no-check-certificate -qO- https://localhost/ | head -20 ``` ### Clear Caddy Cache (if certificate issues occur): ```bash docker volume rm digiserver-v2_caddy-data docker volume rm digiserver-v2_caddy-config docker-compose restart caddy ``` ## Important Notes - Always use `-T` flag with `docker-compose exec` in automated scripts to prevent TTY issues - Change default passwords (`admin123`) in production environments - Adjust email address in HTTPS configuration as needed - For different network setups, modify the IP address and domain in the enable HTTPS command - Keep database backups before running migrations - Test all three access points after deployment