Skip to content

Latest commit

 

History

History
359 lines (253 loc) · 7.84 KB

File metadata and controls

359 lines (253 loc) · 7.84 KB

🛠️ gbh.tech - Ops CLI

📚 Content

📝 Overview

Ops is an all-purpose deployment automation tool tailored for DevOps & SRE teams. Built in Go, it provides a unified CLI interface for managing deployments, Kubernetes configurations, container registries, secrets, and various DevOps operations across different cloud environments (AWS, Azure, and more).

This tool streamlines common DevOps workflows by combining multiple operations into a single, easy-to-use command-line interface, reducing the complexity of managing multi-cloud deployments and infrastructure operations.

⚡ Requirements

System

  • Go: 1.23.6 or later
  • Operating System: macOS, Linux, or Windows

External

The following tools are required for full functionality:

  • AWS CLI: 2.24.5 or later (for AWS operations)
  • Werf: 2.26.4 or later (for deployment operations)
  • kubectl: For Kubernetes operations
  • Docker: For container operations

Development

  • Node.js: 22.13.0 (for development and release automation)
  • GoReleaser: 2.7.0 (for building releases)

📦 Installation

Install script (recommended)

Install the latest release into ~/.ops/bin (no sudo, adds itself to your shell PATH):

curl -fsSL https://ops.gbh.tech/install | bash

Pin a specific version:

curl -fsSL https://ops.gbh.tech/install | bash -s -- v1.3.0
# or
OPS_VERSION=v1.3.0 curl -fsSL https://ops.gbh.tech/install | bash

Override the install location or opt out of the PATH edit:

OPS_INSTALL_DIR=/opt/ops OPS_NO_MODIFY_PATH=1 \
  curl -fsSL https://ops.gbh.tech/install | bash

Supported platforms: Darwin (arm64, x86_64) and Linux (arm64, x86_64, i386) — matching the archives produced by .goreleaser.yaml. The script downloads the release tarball from GitHub Releases, verifies its SHA-256 checksum, extracts the binary, and updates ~/.bashrc, ~/.zshrc, ~/.bash_profile, or ~/.config/fish/config.fish as appropriate.

The script is served by the worker/ Cloudflare Worker; the script source lives at install.sh and can also be used via curl -fsSL https://raw.githubusercontent.com/gbh-tech/ops/main/install.sh | bash as a fallback.

From Source

  1. Clone the repository:

    git clone <repository-url>
    cd ops
  2. Build from source:

    go build -o ops
  3. Install globally (optional):

    go install

Using go install

go install github.com/gbh-tech/ops@latest

Pre-built binaries

Download the latest binary from the releases page.

Development Setup

If you're contributing to the project:

  1. Install development tools:

    # Using asdf (recommended)
    asdf install
    
    # Or install tools manually according to .tool-versions
  2. Install dependencies:

    go mod download

🚀 How to use

The ops tool is designed with a simple command structure that follows the pattern:

ops [command] [subcommand] [flags]

Basic Usage

  1. Check version:

    ops --version
  2. Get help:

    ops --help
    ops [command] --help
  3. Set target environment: Most commands support the -e or --env flag to specify the target environment:

    ops [command] --env production

Configuration

The tool uses configuration files to manage different environments and settings. Configure your environments and cloud credentials according to your infrastructure setup.

⚙️ Commands

env

# Display current environment
ops env

# Set specific environment
ops env --env staging

kube

# Configure kubectl context for AWS EKS
ops kube config --env production

# Configure kubectl context for Azure AKS
ops kube config --env staging

registry

# Login to container registry (ECR, etc.)
ops registry login --env production

deploy

# Deploy using Werf
ops deploy werf --env production

# Deploy with custom values
ops deploy werf --env staging --set image.tag=v1.2.3

ecs

Manages deployments, migrations, and operations for ECS-based services. The --app flag is optional in single-repo mode and required in mono-repo mode (repo_mode: mono in .ops/config.yaml).

# Deploy an app: register task definition, run migrations, update service
ops ecs deploy --env production --app my-app --tag v1.2.3

# Dry-run: print the resolved task definition without deploying
ops ecs render --env staging --app my-app --tag v1.2.3

# Show current ECS service status
ops ecs status --env production --app my-app

# Wait for the service to reach a stable state
ops ecs wait --env production --app my-app

# Roll back the service to the previous task definition revision
ops ecs rollback --env production --app my-app

# Run a standalone database migration task
ops ecs db-migrate --env production --app my-app

# Remove old task definition revisions, keeping the latest 5 (default)
ops ecs cleanup --env production --app my-app --keep 5

# Tail recent CloudWatch logs for a service (default: last 10 minutes)
ops ecs logs --env production --app my-app --since 30m

git

# Extract ticket ID from current branch
ops git get-ticket-id

# Clean up old Git tags
ops git tag-cleaner

secrets

# Encrypt secrets
ops secrets encrypt --env production

# Decrypt secrets
ops secrets decrypt --env staging

Global flags

  • -e, --env string: Specify the target environment
  • -h, --help: Show help for any command
  • --version: Show version information

🧪 Test

Running tests

Currently, the project uses Go's built-in testing framework. To run tests:

# Run all tests
go test ./...

# Run tests with verbose output
go test -v ./...

# Run tests for a specific package
go test ./pkg/...

Linting

The project uses automated linting in CI/CD. To run linting locally:

# Using golangci-lint (if installed)
golangci-lint run

# Or use go vet
go vet ./...

Build

Verify the build works correctly:

# Build the project
go build

# Run built binary
./ops --version

CI/CD

The project uses GitHub Actions for automated testing and building:

  • Build: Automated builds on pull requests
  • Lint: Code quality checks
  • Release: Automated releases using GoReleaser

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

📄 License

See the LICENSE file for details.

💬 Support

For questions, issues, or contributions, please contact devops@gbh.tech.