A powerful and elegant CLI tool for managing Google Cloud Compute Engine instances with clean architecture design.
- π VM Operations: Start, stop, and monitor GCE instances
- Support for multiple VMs in parallel
- Fail-fast behavior for safety
- π Status Monitoring: View VM status with intelligent uptime tracking
- Supports days, hours, minutes, and seconds
- Automatic format selection:
7d12h45m,2h30m,5m30s,45s
- βοΈ Machine Type Management: Change VM configurations on the fly
- π Schedule Policies: Automate VM start/stop schedules
- π¨ Beautiful Output: Styled terminal output with tables and emojis
- β‘ Parallel Execution: Fast operations with concurrent API calls
- ποΈ Clean Architecture: Well-structured codebase following best practices
- β Comprehensive Tests: 80+ test cases with race detection and integration tests
curl -sSL "https://raw.githubusercontent.com/haru-256/gcectl/main/scripts/install.sh" | shPrerequisites
- Go 1.21 or higher
git clone https://github.com/haru-256/gcectl.git
cd gcectl/go
make build
# Binary will be available at bin/mainYou can enable shell completion for bash, zsh, or fish. Please refer to the following commands result.
gcectl completion bash --help # for bash
gcectl completion zsh --help # for zsh
gcectl completion fish --help # for fishFor example, in fish, you can enable completion by running:
gcectl completion fish > "${HOME}/.config/fish/completions/gcectl.fish"Create a configuration file at ~/.config/gcectl/config.yaml:
default-project: your-gcp-project
default-zone: us-central1-a
vm:
- name: my-vm
project: your-gcp-project
zone: us-central1-a
- name: dev-vm
project: your-gcp-project
zone: asia-northeast1-a# List all VMs with status and uptime
gcectl list
# View detailed information about a VM
gcectl describe my-vm
# Start one or more VMs
gcectl on my-vm
gcectl on vm1 vm2 vm3
# Stop one or more VMs
gcectl off my-vm
gcectl off vm1 vm2
# Change machine type (VM must be stopped)
gcectl set machine-type my-vm e2-medium
# Set schedule policy
gcectl set schedule-policy my-vm my-schedule-policy
# Unset schedule policy
gcectl set schedule-policy my-vm my-schedule-policy --ungcectl listOutput:
ββββββββββββ¬βββββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬ββββββββββββββ¬βββββββββββ¬ββββββββββ
β Name β Project β Zone β Machine-Type β Status β Schedule β Uptime β
ββββββββββββΌβββββββββββββΌβββββββββββββββΌβββββββββββββββΌββββββββββββββΌβββββββββββΌββββββββββ€
β my-vm β my-project β us-central1-aβ e2-medium β π’ RUNNING β policy-1 β 2h30m β
β dev-vm β my-project β us-west1-a β n1-standard-1β οΏ½ RUNNING β β 7d12h45mβ
β test-vm β my-project β asia-east1-a β e2-small β π’ RUNNING β β 5m30s β
β old-vm β my-project β us-east1-b β e2-micro β οΏ½π΄ STOPPED β β N/A β
ββββββββββββ΄βββββββββββββ΄βββββββββββββββ΄βββββββββββββββ΄ββββββββββββββ΄βββββββββββ΄ββββββββββ
Uptime Format:
- Days:
7d12h45m(days, hours, minutes) - Hours:
2h30m(hours, minutes) - Minutes:
5m30s(minutes, seconds) - Seconds:
45s(seconds only)
gcectl describe my-vmOutput:
β’ Name : my-vm
β’ Project : my-project
β’ Zone : us-central1-a
β’ MachineType : e2-medium
β’ Status : π’ RUNNING
β’ Uptime : 2h30m
β’ SchedulePolicy: my-schedule-policy
# Start a single VM
$ gcectl on my-vm
Starting VM my-vm...
[SUCCESS] | VM my-vm started successfully
# Start multiple VMs in parallel
$ gcectl on vm1 vm2 vm3
Starting 3 VMs...
[SUCCESS] | All VMs started successfully# Stop a single VM
$ gcectl off my-vm
Stopping VM my-vm...
[SUCCESS] | VM my-vm stopped successfully
# Stop multiple VMs in parallel
$ gcectl off vm1 vm2
Stopping 2 VMs...
[SUCCESS] | All VMs stopped successfully$ gcectl set machine-type my-vm e2-standard-2
Updating machine type for VM my-vm...
[SUCCESS] | Set machine-type to e2-standard-2This project follows Clean Architecture principles with strict layer separation:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Interface Layer β
β (cmd/, internal/interface/presenter/) β
β β’ CLI Commands (Cobra) β
β β’ Console Presentation (lipgloss) β
β β’ Progress Indicators β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β Use Case Layer β
β (usecase/) β
β β’ Business Logic Orchestration β
β β’ VM Operations (Start, Stop, Update) β
β β’ Parallel Execution with errgroup β
β β’ Data Retrieval (List, Describe) β
β β’ Shared Utilities (Uptime Calculation) β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β Domain Layer β
β (domain/model/, domain/repository/) β
β β’ Core Entities (VM, Status) β
β β’ Business Rules (CanStart, CanStop) β
β β’ Repository Interfaces β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β Infrastructure Layer β
β (infrastructure/gcp/, infrastructure/config/) β
β β’ GCP Compute Engine API Client β
β β’ Configuration Management (YAML) β
β β’ Logging & Error Handling β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Dependency Rule: Dependencies point inward only
- Layer Independence: Inner layers have no knowledge of outer layers
- Progress Control: Progress display managed in presentation layer (cmd)
- Repository Pattern: Abstract external API interactions
- Parallel Execution: Multiple VM operations using errgroup
- YAGNI: Use cases applied only where business logic exists
For detailed architecture documentation, see go/README.md.
The project maintains high test coverage with comprehensive test suites:
cd go
# Run all tests
make test
# Run tests with verbose output
go test ./... -v
# Run tests with coverage
go test ./... -cover
# Run specific test package
go test ./internal/usecase/... -vTest Coverage:
- β 80+ test cases
- β Domain layer: Business rule tests
- β Use case layer: Mock-based integration tests
- β Infrastructure layer: Integration tests for GCP operations
- β Presenter layer: Output validation tests
- β Race detection enabled
- β Table-driven test patterns
cd go
make build
# Output: bin/maincd go
make lint
# Uses golangci-lint with strict configurationgcectl/
βββ go/ # Go implementation
β βββ cmd/ # CLI commands
β β βββ describe.go # Describe VM command
β β βββ list.go # List VMs command
β β βββ on.go # Start VM command
β β βββ off.go # Stop VM command
β β βββ root.go # Root command
β β βββ set/ # Set command group
β β βββ machine_type.go # Set machine type
β β βββ schedule.go # Set/unset schedule
β βββ internal/
β β βββ domain/ # Domain layer
β β β βββ model/ # Entities (VM)
β β β βββ repository/ # Repository interfaces
β β βββ usecase/ # Use case layer
β β β βββ describe_vm.go # Describe VM use case
β β β βββ list_vms.go # List VMs use case
β β β βββ vm_uptime.go # Shared uptime logic
β β β βββ start_vm.go # Start VM use case
β β β βββ stop_vm.go # Stop VM use case
β β β βββ update_machine_type.go
β β βββ infrastructure/ # Infrastructure layer
β β β βββ gcp/ # GCP API client
β β β βββ config/ # Configuration
β β β βββ log/ # Logging
β β βββ interface/ # Interface layer
β β βββ presenter/ # Console presenter
β βββ main.go # Application entry
β βββ config.yaml # Example config
β βββ Makefile # Build automation
β
βββ terraform/ # Infrastructure as Code
β βββ environments/dev/ # Dev environment
β βββ modules/ # Reusable modules
β βββ gce/ # GCE instance module
β βββ tfstate_gcs_bucket/ # State bucket module
β
βββ rust/ # Rust implementation (WIP)
The CLI uses emoji indicators for quick status recognition:
- π’ RUNNING - VM is running
- π΄ STOPPED - VM is stopped
- π‘ STAGING - VM is being staged
- π PROVISIONING - VM is provisioning
- π΅ STOPPING - VM is stopping
- β« TERMINATED - VM is terminated
- βͺ SUSPENDING - VM is suspending
- π€ SUSPENDED - VM is suspended
- π REPAIRING - VM is being repaired
- Go Implementation: See go/README.md for detailed documentation
- Terraform: Infrastructure provisioning configurations in terraform/
- Architecture Deep Dive: go/README.md#architecture--design-philosophy
Contributions are welcome! Please follow these guidelines:
- Follow Clean Architecture: Respect layer boundaries
- Add Tests: Aim for >80% coverage for new code
- Update Documentation: Keep README and docstrings current
- Run Quality Checks: Ensure
make testandmake lintpass - Keep Use Cases Lean: Add use case layer only when business logic exists
See CONTRIBUTING.md for more details (if available).
- Start/Stop VM operations (single and multiple VMs)
- List VMs with status and uptime
- Describe VM details
- Set machine type
- Set/unset schedule policies
- Clean Architecture implementation
- Progress indicators with ExecuteWithProgress helper
- Parallel execution for multiple VMs (errgroup)
- Comprehensive test coverage (80+ tests)
- Integration tests for GCP operations
- Styled console output
- Intelligent uptime formatting (days/hours/minutes/seconds)
- Success logging for each operation
- Interactive TUI mode (bubbletea)
- List available machine types
- VM cost estimation
- Configuration validation command
- Export VM details (JSON/YAML)
- GoReleaser for multi-platform releases
- Homebrew formula
- Docker image
This project is licensed under the MIT License - see the LICENSE file for details.
haru-256
- GitHub: @haru-256
- Cobra - CLI framework
- Lipgloss - Terminal styling
- Google Cloud Go SDK - GCP API client
Made with β€οΈ and Clean Architecture