Skip to content

[DOCKER-COMPOSE] Implement Per-Machine Nginx Configuration Distribution#45

Merged
chutch3 merged 6 commits intomainfrom
feature/issue-36-nginx-distribution
Aug 11, 2025
Merged

[DOCKER-COMPOSE] Implement Per-Machine Nginx Configuration Distribution#45
chutch3 merged 6 commits intomainfrom
feature/issue-36-nginx-distribution

Conversation

@chutch3
Copy link
Copy Markdown
Owner

@chutch3 chutch3 commented Aug 11, 2025

Summary

Implements per-machine nginx configuration generation for Docker Compose deployments as specified in Issue #36. Each machine now gets its own nginx instance that proxies only the services deployed locally on that machine.

Changes Made

Core Functionality ✅

  • Enhanced Web Service Detection: Expanded beyond ports 80/443 to detect all web services vs databases/cache services
  • Machine-Specific Nginx: Each machine generates nginx configs only for services deployed locally
  • Domain Routing: Services accessible via service.BASE_DOMAIN format with BASE_DOMAIN support
  • Health Check Endpoints: Added /health endpoint to nginx configurations
  • Distributed Architecture: No single point of failure - each machine runs its own nginx

Implementation Details

  • New Functions:

    • is_web_service() - Intelligently detects web services vs databases/cache services
    • get_base_domain() - Retrieves BASE_DOMAIN from environment or config
    • generate_nginx_bundles() - Generates nginx bundles for all machines
  • Enhanced Existing Functions:

    • generate_nginx_config_for_machine() - Now uses web service detection and BASE_DOMAIN

CLI Integration ✅

  • Added ./selfhosted.sh generate-nginx bundles [config] command
  • Integration with existing Docker Compose translation engine

Testing

  • Comprehensive Test Suite: 18 tests covering all nginx distribution functionality
  • Test Results: ✅ 15 passing, 3 skipped (advanced features)
  • Test Coverage:
    • Web service detection vs databases
    • Per-machine service isolation
    • Domain format handling
    • Health check endpoints
    • CLI integration
    • Error handling and validation

TDD Workflow Followed

Red Phase ✅

  • Created 18 failing tests defining expected nginx distribution behavior
  • Commit: 48efc9d - "test: add failing tests for nginx distribution enhancement (RED)"

Green Phase ✅

  • Implemented core nginx distribution functionality to make tests pass
  • Commit: 751138c - "feat: enhance nginx distribution for all web services (GREEN)"

Refactor Phase ✅

Issue #36 Requirements Met

Machine-Specific Nginx: Each machine runs nginx that proxies only local services
No Single Point of Failure: Distributed reverse proxy across all machines
Domain Routing: Each service accessible via service.domain.com regardless of machine
Health Isolation: Machine failures don't affect other machine's nginx instances
Enhanced Web Service Detection: All web services get nginx configs (not just ports 80/443)
CLI Integration: ./selfhosted.sh generate-nginx bundles command available

Architecture Impact

This implementation maintains the existing Docker Compose translation engine architecture while enhancing it with:

  • Intelligent web service detection
  • Distributed nginx configuration generation
  • BASE_DOMAIN environment support
  • Health check endpoints
  • CLI command integration

Future Enhancements (Skipped Tests)

The following advanced features are marked as skipped for future implementation:

  • SSL/TLS configuration with certificates
  • Advanced error handling and recovery
  • Upstream load balancing for service replicas

These features don't impact the core nginx distribution functionality and can be added in future iterations.

Related Issues

Testing Instructions

# Run nginx distribution tests
cd tests/unit/scripts
bats nginx_distribution_test.bats

# Test CLI integration
./selfhosted.sh generate-nginx bundles homelab.yaml

# Test with example configs
./selfhosted.sh generate-nginx bundles examples/homelab-multi-node.yaml

@chutch3 chutch3 self-assigned this Aug 11, 2025
@chutch3 chutch3 merged commit f0e53a2 into main Aug 11, 2025
3 checks passed
@chutch3 chutch3 deleted the feature/issue-36-nginx-distribution branch August 11, 2025 12:48
chutch3 added a commit that referenced this pull request Aug 12, 2025
chutch3 added a commit that referenced this pull request Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DOCKER-COMPOSE] Implement Per-Machine Nginx Configuration

1 participant