webdrop-bridge/CONFIGURATION_BUNDLING_SUMMARY.md

5.6 KiB

Configuration System Overhaul - Summary

Problem Identified

The application was not bundling the .env configuration file into built executables. This meant:

End users received applications with no configuration Hardcoded defaults in config.py were used instead No way to support different customers with different configurations Users had to manually create .env files after installation

Solution Implemented

Enhanced the build system to bundle .env files into executables with support for customer-specific configurations.

Key Changes

1. Windows Build Script (build/scripts/build_windows.py)

  • Added --env-file command-line parameter
  • Validates .env file exists before building
  • Passes .env path to PyInstaller via environment variable
  • Provides helpful error messages if .env is missing
  • Full argument parsing with argparse

Usage:

# Default: uses .env from project root
python build_windows.py --msi

# Custom config for a customer
python build_windows.py --msi --env-file customer_configs/acme.env

2. macOS Build Script (build/scripts/build_macos.sh)

  • Added --env-file parameter (shell-based)
  • Validates .env file exists before building
  • Exports environment variable for spec file
  • Same functionality as Windows version

Usage:

# Default: uses .env from project root
bash build_macos.sh

# Custom config
bash build_macos.sh --env-file customer_configs/acme.env

3. PyInstaller Spec File (build/webdrop_bridge.spec)

  • Now reads environment variable WEBDROP_ENV_FILE
  • Defaults to project root .env if not specified
  • Validates .env exists before bundling
  • Includes .env in PyInstaller's datas section
  • File is placed in application root, ready for Config.from_env() to find

Changes:

# Get env file from environment variable (set by build script)
# Default to .env in project root if not specified
env_file = os.getenv("WEBDROP_ENV_FILE", os.path.join(project_root, ".env"))

# Verify env file exists
if not os.path.exists(env_file):
    raise FileNotFoundError(f"Configuration file not found: {env_file}")

# Include in datas
datas=[
    ...
    (env_file, "."),  # Include .env file in the root of bundled app
]

4. Documentation (docs/CONFIGURATION_BUILD.md)

  • Complete guide on configuration management
  • Examples for default and custom configurations
  • Multi-customer setup examples
  • Build command reference for Windows and macOS

How It Works

At Build Time

  1. User specifies .env file (or uses default from project root)
  2. Build script validates the file exists
  3. PyInstaller bundles the .env into the application
  4. Users receive a pre-configured executable

At Runtime

  1. Application starts and calls Config.from_env()
  2. Looks for .env in the current working directory
  3. Finds the bundled .env file
  4. Loads all configuration (URLs, paths, logging, etc.)
  5. Application starts with customer-specific settings

Benefits

Multi-customer support - Build different configs for different clients No user setup - Configuration is included in the installer Safe builds - Process fails if .env doesn't exist Override capability - Users can edit .env after installation if needed Clean deployment - Each customer gets exactly what they need

Example: Multi-Customer Deployment

customer_configs/
├── acme_corp.env
│   WEBAPP_URL=https://acme.example.com
│   ALLOWED_ROOTS=Z:/acme_files/
├── globex.env
│   WEBAPP_URL=https://globex.example.com
│   ALLOWED_ROOTS=C:/globex_data/
└── initech.env
    WEBAPP_URL=https://initech.example.com
    ALLOWED_ROOTS=D:/initech/

Build for each:

python build_windows.py --msi --env-file customer_configs/acme_corp.env
python build_windows.py --msi --env-file customer_configs/globex.env
python build_windows.py --msi --env-file customer_configs/initech.env

Each MSI includes the customer's specific configuration.

Files Modified

  1. build/scripts/build_windows.py - Enhanced with .env support
  2. build/scripts/build_macos.sh - Enhanced with .env support
  3. build/webdrop_bridge.spec - Now includes .env in bundle
  4. docs/CONFIGURATION_BUILD.md - New comprehensive guide

Build Command Quick Reference

Windows

# Default configuration
python build/scripts/build_windows.py --msi

# Custom configuration
python build/scripts/build_windows.py --msi --env-file path/to/config.env

# Without MSI (just EXE)
python build/scripts/build_windows.py

# With code signing
python build/scripts/build_windows.py --msi --code-sign

macOS

# Default configuration
bash build/scripts/build_macos.sh

# Custom configuration
bash build/scripts/build_macos.sh --env-file path/to/config.env

# With signing
bash build/scripts/build_macos.sh --sign

# With notarization
bash build/scripts/build_macos.sh --notarize

Testing

To test the new functionality:

# 1. Verify default build (uses project .env)
python build/scripts/build_windows.py --help

# 2. Create a test .env with custom values
# (or use existing .env)

# 3. Try building (will include .env)
# python build/scripts/build_windows.py --msi

Next Steps

  • Configuration bundling implemented
  • Multi-customer support enabled
  • Documentation created
  • 🔄 Test builds with different .env files (optional)
  • 🔄 Document in DEVELOPMENT_PLAN.md if needed

Backward Compatibility

Fully backward compatible

  • Old code continues to work
  • Default behavior (use project .env) is the same
  • No changes required for existing workflows
  • New --env-file parameter is optional