Skip to content

feat: Add local .forge config file support with named environments#108

Open
StephenBadger wants to merge 1 commit intolaravel:masterfrom
Blue-Badger-Team:pr/local-environment-config
Open

feat: Add local .forge config file support with named environments#108
StephenBadger wants to merge 1 commit intolaravel:masterfrom
Blue-Badger-Team:pr/local-environment-config

Conversation

@StephenBadger
Copy link

Summary

This PR adds project-level configuration support via a .forge file, enabling teams to commit their Forge server/site mappings directly in their repositories. This eliminates the need to specify server/site IDs for every command and provides a clear, version-controlled deployment configuration.

Key features:

  • Named environments (production, staging, dev) with per-environment server/site config
  • Smart deploy detection: forge deploy staging auto-detects if "staging" is an environment name or a site name
  • Confirmation prompts for production-like environments via "confirm": true setting
  • Interactive setup: forge init guides users through configuration
  • Config management commands: config, config:set, config:remove, config:default
  • Zsh shell completion with environment awareness
  • Backward compatible with existing global config - local config takes priority when present

Example Configuration

{
    "default": "staging",
    "environments": {
        "production": {
            "server": 123456,
            "site": 789012,
            "confirm": true
        },
        "staging": {
            "server": 123456,
            "site": 789013
        }
    }
}

Usage Examples

# Interactive setup
forge init

# Deploy to default environment
forge deploy

# Deploy to specific environment
forge deploy staging
forge deploy production  # Prompts for confirmation

# Skip confirmation
forge deploy production --force

# Config management
forge config              # Display current config
forge config:set          # Interactive add/update
forge config:set prod 123 456 --confirm  # Quick CLI mode
forge config:remove dev
forge config:default staging

# Shell completion
forge completion --install

Implementation Details

  • LocalConfigRepository: Reads .forge files, walks up directories to find config (similar to .env resolution)
  • InteractsWithEnvironments trait: Shared environment resolution and confirmation logic
  • Smart detection in DeployCommand: Distinguishes between environment names and site names automatically
  • Maintains full backward compatibility: Falls back to global config when no local config exists

Files Changed

  • app/Repositories/LocalConfigRepository.php - New repository for local config handling
  • app/Commands/Concerns/InteractsWithEnvironments.php - New trait for environment logic
  • app/Commands/InitCommand.php - New forge init command
  • app/Commands/ConfigCommand.php - New forge config display command
  • app/Commands/ConfigSetCommand.php - New forge config:set command
  • app/Commands/ConfigRemoveCommand.php - New forge config:remove command
  • app/Commands/ConfigDefaultCommand.php - New forge config:default command
  • app/Commands/CompletionCommand.php - New forge completion command
  • app/Commands/DeployCommand.php - Updated with smart environment detection
  • app/Commands/Command.php - Integrated local config support
  • app/Commands/Concerns/InteractsWithIO.php - Updated for environment-aware site resolution
  • app/Providers/ConfigServiceProvider.php - Registered LocalConfigRepository
  • completions/forge.zsh - Zsh completion script
  • README.md - Documentation for the new feature

This follows the existing pattern of local .env.forge.{siteId} files for environment variables, extending the concept to full deployment configuration.

This adds project-level configuration via a `.forge` file, enabling teams
to commit their Forge server/site mappings directly in their repositories.

Key features:
- Named environments (production, staging, dev) with per-environment config
- Smart deploy detection: `forge deploy staging` auto-detects environment names
- Confirmation prompts for production-like environments (`confirm: true`)
- Interactive `forge init` command for easy setup
- Config management commands: config, config:set, config:remove, config:default
- Zsh shell completion with environment awareness
- Backward compatible with existing global config

Example .forge file:
```json
{
    "default": "staging",
    "environments": {
        "production": { "server": 123, "site": 456, "confirm": true },
        "staging": { "server": 123, "site": 789 }
    }
}
```

Usage:
- `forge deploy` - deploys to default environment
- `forge deploy production` - deploys to production (prompts for confirmation)
- `forge deploy --force` - skips confirmation prompt
- `forge init` - interactive setup
- `forge config` - display current configuration
@StephenBadger
Copy link
Author

I made this because I work at an agency, have many clients, each client has potentially a few sites. Juggling the forge cli context was annoying. Now I don't have to. I use this locally every day and though to share it back. Let me know if you want adjustments or have questions.

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.

1 participant