Skip to main content

CLI tool for managing Google Cloud Managed Instance Groups

Project description

migs - Google Cloud MIG CLI Tool

A command-line tool that wraps the gcloud CLI to provide an easier experience for managing Google Cloud Managed Instance Groups.

Features

  • List MIGs in your project
  • Spin up/down VMs with exact custom names (auto-detects gcloud beta)
  • Track your personal VMs
  • Automatic SSH config management for VS Code Remote Explorer
  • Easy file/directory uploads
  • Multi-node cluster support with coordinated naming

Installation

pip install migs

Or to build from source:

git clone https://github.com/keatonelvins/migs.git
cd migs
pip install -e .

Prerequisites

  • Python 3.8+
  • gcloud CLI installed and authenticated (gcloud auth login)
  • SSH keys configured for Google Compute Engine
  • (Optional) gcloud beta component for exact VM naming (gcloud components install beta)

Usage

List all MIGs

migs list

Spin up a VM

# With custom name (auto-detects gcloud beta availability)
migs up my-mig -n my-dev-vm           # Creates VM named "my-dev-vm" if beta available
migs up my-mig -n my-dev-vm -d 2h     # Auto-delete after 2 hours
migs up my-mig -n node -c 3           # Creates "node1", "node2", "node3"

# Without custom name (auto-generated)
migs up my-mig                        # Creates "my-mig-username-timestamp"

# Force stable API (bypass auto-detection)
migs up my-mig -n my-dev-vm --stable  # Use stable API (VM gets random name, mapped locally)

List your VMs

migs vms

Sync VM state

migs sync  # Sync local VM list with GCP state
migs sync --discover  # Also discover and claim untracked VMs

Check VM connectivity

migs check my-dev-vm  # Test SSH connectivity

SSH into a VM

migs ssh my-dev-vm
migs ssh my-dev-vm -- tmux attach  # Pass additional SSH arguments

Run scripts

migs run my-dev-vm ./setup.sh  # Runs in tmux session
migs run my-dev-vm ./deploy.sh --session deploy  # Custom session name
migs run my-dev-vm ./script.sh arg1 arg2  # Pass arguments to script

Environment Variables (.env files)

Both ssh and run commands automatically detect and use .env files from your current directory:

# If .env exists in current directory, it will be uploaded and sourced
migs ssh my-dev-vm  # Variables from .env available in shell
migs run my-dev-vm ./app.sh  # Script runs with .env variables

The .env file is uploaded to /tmp/.env on the VM and sourced using set -a; source /tmp/.env; set +a to export all variables.

If $GITHUB_TOKEN exists in your .env, will also configure the gh cli.

Upload files

migs upload my-dev-vm ./myfile.txt
migs upload my-dev-vm ./mydir/ /home/user/

Download files

migs download my-dev-vm /remote/file.txt
migs download my-dev-vm /remote/dir/ ./local/

Spin down a VM

migs down my-dev-vm

Multi-Node Cluster

# Create 4-node cluster with coordinated names
migs up my-mig --name cluster -c 4    # Creates cluster1, cluster2, cluster3, cluster4

# SSH to specific nodes
migs ssh cluster1
migs ssh cluster2

# Run script on all nodes
migs run cluster train.py --all

# Shut down entire cluster
migs down cluster --all

Distributed Training (PyTorch)

The --torchrun flag automatically sets up environment variables for distributed training:

# Run distributed training script on all nodes
migs run cluster train.py --all --torchrun

# This automatically sets on each node:
- HEAD_NODE_IP: Internal IP of cluster1 (head node)
- HEAD_NODE_PORT: 5000
- NNODES: Total number of nodes
- NODE_RANK: 0 for head, 1+ for workers
- NPROC_PER_NODE: Auto-detected GPU count

# Your script can then use torchrun:
torchrun --nproc_per_node=$NPROC_PER_NODE \
         --nnodes=$NNODES \
         --node_rank=$NODE_RANK \
         --master_addr=$HEAD_NODE_IP \
         --master_port=$HEAD_NODE_PORT \
         your_training_script.py

SSH Config

The tool automatically updates your ~/.ssh/config file with entries for your VMs, making them accessible in VS Code Remote Explorer.

Release Instructions

Setup and Installation

# Install development dependencies and tool in editable mode
make dev-install
# Or directly with pip
pip install -e .

# Install packaging tools (needed for building/releasing)
make install-tools

Building and Testing

# Build distribution packages
make build

# Clean build artifacts
make clean

Release Process

First increment the pyproject.toml and src/migs/__init__.py

# Test upload to PyPI
make test-upload

# Production upload to PyPI
make upload

# Full release (clean, build, upload)
make release

Add git version tag:

git tag v0.1.x
git push origin v0.1.x

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

migs-0.1.5.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

migs-0.1.5-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file migs-0.1.5.tar.gz.

File metadata

  • Download URL: migs-0.1.5.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for migs-0.1.5.tar.gz
Algorithm Hash digest
SHA256 10c37cd99fe5ac3dfdbe220b6fda8cf3c78cd3031ca7b1d1f8045670d0139886
MD5 88c372ce1eb5cb7d062ee1ebdab00f6b
BLAKE2b-256 1e86f330bcf331d98898c14e9495862faa4f07d47fd0937a5ca48c4452fd2a44

See more details on using hashes here.

File details

Details for the file migs-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: migs-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for migs-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 96d2fd77ea88a69c4233ff95ab461721c1f7b28c9b8fcd51f4b61ac707a3dc31
MD5 ec501386613ba3aef1d4df42123b472e
BLAKE2b-256 eeb2e23e9c55babe63acf9948c4947b6098befa780934d00d168c886d0aa3ef4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page