Skip to content

Conversation

@matrixise
Copy link
Contributor

Summary

This PR implements automatic environment isolation based on git branch names, allowing developers to work on multiple branches simultaneously without conflicts between databases, containers, or Docker volumes.

Key Features

🔄 Automatic Branch Detection

  • Auto-detects current git branch and normalizes the name
  • Uses branch name throughout Docker and database configuration
  • Works seamlessly when switching branches

🐳 Docker Isolation

  • Images: Tagged by branch (python.ie/website:{branch})
  • Containers: Unique names (pythonie-{service}-{branch})
  • Volumes: Isolated per branch (pythonie-postgres-data-{branch}, pythonie-redis-data-{branch})
  • Databases: PostgreSQL (pythonie_{branch}) and SQLite (db-{branch}.sqlite3)

🛠️ New Commands

task branch:info      # Show current branch environment
task branch:verify    # Verify database configuration
task branch:volumes   # List all Docker volumes by branch
task branch:clean     # Remove volumes for current branch

📚 Documentation

  • Comprehensive DOCKER-BRANCHES.md with usage examples and troubleshooting
  • Updated README.md with "Docker Branch Isolation" section
  • .env.example template for custom port overrides

Changes

Infrastructure

  • docker-compose.yml: Dynamic image, container, database, and volume names based on GIT_BRANCH
  • Taskfile.yaml: Auto-detect branch, generate .env file, new branch:* commands
  • dev.py: SQLite databases now isolated by branch (db-{branch}.sqlite3)

Service Updates

  • Upgraded Redis from 6.2 to 7-alpine with persistence
  • Added healthchecks for PostgreSQL and Redis
  • Removed unused minio and mc services
  • Configurable ports for parallel development (WEB_PORT, PG_PORT)

Files Modified

  • .gitignore - Added .env and *.sqlite3
  • docker-compose.yml - Branch-based configuration
  • Taskfile.yaml - Branch detection and new tasks
  • pythonie/pythonie/settings/dev.py - SQLite isolation
  • README.md - Complete documentation
  • DOCKER-BRANCHES.md - Detailed usage guide
  • .env.example - Configuration template

Use Cases

Parallel Development

# Terminal 1: Main branch
git checkout main
task run  # Port 8000, pythonie_main DB

# Terminal 2: Feature branch
git checkout feature/auth
WEB_PORT=8001 PG_PORT=5433 task run  # Port 8001, pythonie_feature-auth DB

Branch Switching

git checkout main
task run  # Automatically uses main database

git checkout feature/xyz
task run  # Automatically uses feature-xyz database (isolated from main)

Testing

Verified on branch feat/docker-branch-isolation:

  • ✅ Docker images tagged correctly
  • ✅ PostgreSQL database created with branch name
  • ✅ SQLite database created with branch name
  • ✅ Volumes isolated per branch
  • ✅ Containers have unique names
  • ✅ All task branch:* commands working
  • ✅ Environment switching on git checkout

Breaking Changes

None. This is fully backward compatible:

  • Default branch name is "dev" if detection fails
  • Existing databases remain accessible
  • No changes to production deployment

🤖 Generated with Claude Code

matrixise and others added 3 commits February 4, 2026 11:39
Implement automatic environment isolation based on git branch names,
allowing developers to work on multiple branches simultaneously without
conflicts between databases, containers, or Docker volumes.

Key changes:
- Auto-detect git branch and normalize name (replace special chars)
- Tag Docker images by branch (python.ie/website:{branch})
- Isolate PostgreSQL databases per branch (pythonie_{branch})
- Create separate Docker volumes per branch
- Add configurable ports for parallel development (WEB_PORT, PG_PORT)
- Upgrade Redis from 6.2 to 7-alpine with persistence
- Add healthchecks for PostgreSQL and Redis
- Remove unused minio and mc services

New Taskfile commands:
- task branch:info - Show current branch environment
- task branch:volumes - List all Docker volumes by branch
- task branch:clean - Remove volumes for current branch
- task env:write - Generate .env file for docker-compose

Documentation:
- Add DOCKER-BRANCHES.md with usage examples and troubleshooting
- Add .env.example template for custom port overrides
- Update .gitignore to exclude generated .env file

This enables developers to switch branches or run multiple instances
in parallel without losing data or experiencing port conflicts.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Extend branch isolation to SQLite databases for local development
and add comprehensive documentation for the branch isolation feature.

Changes to SQLite isolation:
- Modify dev.py to use branch-specific SQLite files (db-{branch}.sqlite3)
- Add *.sqlite3 to .gitignore to exclude database files
- Remove debug print statement from dev.py
- Each branch now has isolated SQLite data without requiring worktrees

Documentation improvements:
- Add complete "Docker Branch Isolation" section to README.md
- Document all branch:* commands (info, verify, volumes, clean)
- Add examples for multi-branch development and branch switching
- Add troubleshooting section for database configuration issues
- Update DOCKER-BRANCHES.md to mention SQLite isolation
- Add note in local setup about GIT_BRANCH export

New Taskfile command:
- task branch:verify - Comprehensive verification of branch configuration
  Shows git branch, expected database, .env file, and PostgreSQL databases

This ensures complete data isolation between branches whether using
Docker (PostgreSQL) or local development (SQLite), preventing data
loss when switching branches.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@matrixise matrixise marked this pull request as draft February 4, 2026 11:16
@matrixise
Copy link
Contributor Author

I've converted this PR to draft status because I realize I've committed too many separate concerns together, which doesn't follow good PR practices.

I will split this work into separate PRs:

  1. First PR: Docker Compose infrastructure updates

    • Upgrade Redis from 6.2 to 7-alpine
    • Add healthchecks for PostgreSQL and Redis
    • Remove unused minio/mc services
    • Other docker-compose.yml improvements
  2. Second PR: Branch isolation feature

    • Automatic environment isolation by git branch
    • Branch-specific Docker images, databases, and volumes
    • New task branch:* commands
    • Documentation (DOCKER-BRANCHES.md, README updates)

This separation will make the changes easier to review and allow for incremental adoption.

I'll close this PR once the split PRs are ready.

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.

2 participants