@marcfargas/skills 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -2
- package/google-cloud/gcloud/SKILL.md +140 -0
- package/google-cloud/gcloud/auth.md +107 -0
- package/google-cloud/gcloud/automation.md +165 -0
- package/google-cloud/gcloud/compute.md +113 -0
- package/google-cloud/gcloud/data.md +119 -0
- package/google-cloud/gcloud/iam.md +137 -0
- package/google-cloud/gcloud/serverless.md +169 -0
- package/google-cloud/gcloud/storage.md +122 -0
- package/package.json +34 -5
- package/release/pre-release/SKILL.md +338 -0
- package/terminal/vhs/SKILL.md +248 -0
- package/index.js +0 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Skills
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reusable skills for AI coding agents. Works with [pi](https://github.com/mariozechner/pi-coding-agent), [Claude Code](https://docs.anthropic.com/en/docs/claude-code), [Cursor](https://cursor.sh), and any agent that supports the [Agent Skills standard](https://agentskills.io/specification).
|
|
4
|
+
|
|
5
|
+
## Available Skills
|
|
6
|
+
|
|
7
|
+
| Category | Skill | Description |
|
|
8
|
+
|----------|-------|-------------|
|
|
9
|
+
| ☁️ Google Cloud | [gcloud](google-cloud/gcloud/) | GCP CLI with agent safety model — hub + 7 reference files |
|
|
10
|
+
| 🚀 Release | [pre-release](release/pre-release/) | Pre-release checklist + AI-written changesets via @changesets/cli |
|
|
11
|
+
| 🎬 Terminal | [vhs](terminal/vhs/) | Record terminal sessions as GIF/MP4 with [VHS](https://github.com/charmbracelet/vhs) |
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
### One command (39+ agents)
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx skills add marcfargas/skills
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Installs to Claude Code, Cursor, Copilot, Amp, Cline, Windsurf, Gemini CLI, and [30+ more agents](https://skills.sh) automatically.
|
|
22
|
+
|
|
23
|
+
### pi
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pi install npm:@marcfargas/skills
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or add to `~/.pi/agent/settings.json`:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"packages": ["npm:@marcfargas/skills"]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Manual (any agent)
|
|
38
|
+
|
|
39
|
+
Copy the skill directory into your agent's skill folder:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
cp -r google-cloud/gcloud ~/.claude/skills/gcloud
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Skill Design Principles
|
|
46
|
+
|
|
47
|
+
1. **Safety first** — destructive operations classified and gated, costs flagged
|
|
48
|
+
2. **Hub + spoke** — thin SKILL.md hub (~140 lines) + per-topic reference files loaded on demand
|
|
49
|
+
3. **Agent-native** — `--format=json` everywhere, idempotent patterns, error handling
|
|
50
|
+
4. **Portable** — no hardcoded paths or personal config
|
|
51
|
+
5. **Tested** — validated with Gemini, GPT, and Claude before publishing
|
|
52
|
+
|
|
53
|
+
## Structure
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
skills/
|
|
57
|
+
├── google-cloud/
|
|
58
|
+
│ └── gcloud/ # 8 files, ~1100 lines total
|
|
59
|
+
├── release/
|
|
60
|
+
│ └── pre-release/ # 1 file
|
|
61
|
+
├── terminal/
|
|
62
|
+
│ └── vhs/ # 1 file
|
|
63
|
+
└── README.md
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## External Skills (planned)
|
|
67
|
+
|
|
68
|
+
Some skills are developed in their own repositories and synced here:
|
|
69
|
+
|
|
70
|
+
| Skill | Source Repo | Status |
|
|
71
|
+
|-------|-------------|--------|
|
|
72
|
+
| odoo | `odoo-toolbox` | Planned |
|
|
73
|
+
| go-easy | `go-easy` | Planned |
|
|
74
|
+
|
|
75
|
+
## Contributing
|
|
76
|
+
|
|
77
|
+
Skills follow the [Agent Skills specification](https://agentskills.io/specification). Requirements:
|
|
78
|
+
|
|
79
|
+
- `SKILL.md` with YAML frontmatter (`name`, `description`)
|
|
80
|
+
- `name` matches parent directory (kebab-case, max 64 chars)
|
|
81
|
+
- `description` present (max 1024 chars)
|
|
82
|
+
- No hardcoded paths or credentials
|
|
83
|
+
- Destructive operations clearly marked
|
|
84
|
+
|
|
85
|
+
### Validation
|
|
86
|
+
|
|
87
|
+
Use [skills-ref](https://github.com/agentskills/agentskills) (Python — the official reference implementation from the spec authors) to validate skills locally:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install skills-ref
|
|
91
|
+
|
|
92
|
+
# Validate a skill directory
|
|
93
|
+
agentskills validate path/to/skill
|
|
94
|
+
|
|
95
|
+
# Read parsed properties as JSON
|
|
96
|
+
agentskills read-properties path/to/skill
|
|
97
|
+
|
|
98
|
+
# Generate <available_skills> XML prompt block
|
|
99
|
+
agentskills to-prompt path/to/skill-a path/to/skill-b
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
CI runs `agentskills validate` on every push — see [`.github/workflows/validate.yml`](.github/workflows/validate.yml).
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gcloud
|
|
3
|
+
description: >-
|
|
4
|
+
Google Cloud Platform CLI (gcloud, gcloud storage, bq).
|
|
5
|
+
Use when: managing GCP resources, deploying to Cloud Run/Cloud Functions/GKE/App Engine,
|
|
6
|
+
working with Cloud Storage, BigQuery, IAM, Compute Engine, Cloud SQL, Pub/Sub,
|
|
7
|
+
Secret Manager, Artifact Registry, Cloud Build, Cloud Scheduler, Cloud Tasks,
|
|
8
|
+
Vertex AI, VPC/networking, DNS, logging/monitoring, or any GCP service.
|
|
9
|
+
Also covers: authentication, project/config management, CI/CD integration,
|
|
10
|
+
serverless deployments, container registry, docker push to GCP, managing secrets,
|
|
11
|
+
Workload Identity Federation, and infrastructure automation.
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# gcloud — Google Cloud Platform CLI
|
|
15
|
+
|
|
16
|
+
Command-line interface for managing Google Cloud resources.
|
|
17
|
+
Covers `gcloud`, `gcloud storage` (replaces `gsutil`), and `bq` (BigQuery).
|
|
18
|
+
|
|
19
|
+
## Platform Notes (Windows + Git Bash)
|
|
20
|
+
|
|
21
|
+
- Install: `scoop install gcloud` (preferred) or `GoogleCloudSDKInstaller.exe`
|
|
22
|
+
- If installed via scoop, `gcloud components install` may not work — use scoop to manage
|
|
23
|
+
- Config: `%APPDATA%/gcloud/` (PowerShell) or `~/.config/gcloud/` (Git Bash)
|
|
24
|
+
- Service account keys: store in `$TEMP` or project `.secrets/`, **never commit**
|
|
25
|
+
- Python: gcloud requires Python; scoop install handles this automatically
|
|
26
|
+
|
|
27
|
+
### ⚠️ Path Translation Gotcha
|
|
28
|
+
|
|
29
|
+
Git Bash auto-translates `/`-prefixed args, breaking some gcloud commands:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# FIX — disable MSYS path conversion:
|
|
33
|
+
export MSYS_NO_PATHCONV=1
|
|
34
|
+
|
|
35
|
+
# Or per-command:
|
|
36
|
+
MSYS_NO_PATHCONV=1 gcloud projects add-iam-policy-binding my-project ...
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
> **⚠️ Cost**: Commands that create resources (instances, clusters, databases) incur
|
|
40
|
+
> GCP charges. Always confirm project and region before creating.
|
|
41
|
+
|
|
42
|
+
## Agent Safety Model
|
|
43
|
+
|
|
44
|
+
Operations classified by risk. **Follow this model for all gcloud commands.**
|
|
45
|
+
|
|
46
|
+
| Level | Gate | Examples |
|
|
47
|
+
|-------|------|----------|
|
|
48
|
+
| **READ** | Proceed autonomously | `list`, `describe`, `get`, `logs read`, `config list`, `gcloud storage ls` |
|
|
49
|
+
| **WRITE** | Confirm with user; note cost if billable | `create`, `deploy`, `update`, `enable`, `gcloud storage cp` (upload) |
|
|
50
|
+
| **DESTRUCTIVE** | Always confirm; show what's affected | `delete`, `rm`, `gsutil rm -r`, `bq rm -r`, `rsync -d`, IAM removal |
|
|
51
|
+
| **EXPENSIVE** | Confirm + state approximate cost | GKE clusters (~$70+/mo), SQL instances (~$8-400/mo), VMs (~$5-2k/mo) |
|
|
52
|
+
| **SECURITY** | Confirm + explain impact | `--allow-unauthenticated`, firewall rules, IAM owner/editor grants |
|
|
53
|
+
| **FORBIDDEN** | Refuse; escalate to human | `gcloud iam service-accounts keys create`, `gcloud projects delete`, passwords in CLI args |
|
|
54
|
+
|
|
55
|
+
**Rules**:
|
|
56
|
+
- **Never combine `--quiet` with destructive operations** — it suppresses the only safety gate
|
|
57
|
+
- **Never put passwords/secrets as command-line arguments** — visible in process list & shell history
|
|
58
|
+
- **Always use `--format=json`** for machine-parseable output (agents can't reliably parse tables)
|
|
59
|
+
- **When in doubt, treat as DESTRUCTIVE**
|
|
60
|
+
|
|
61
|
+
## Command Structure
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
gcloud [RELEASE_LEVEL] COMPONENT ENTITY OPERATION [ARGS] [FLAGS]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Key global flags: `--project`, `--format`, `--filter`, `--limit`, `--quiet`, `--verbosity`, `--async`
|
|
68
|
+
|
|
69
|
+
## Service Reference
|
|
70
|
+
|
|
71
|
+
| Service | File | Key Commands |
|
|
72
|
+
|---------|------|-------------|
|
|
73
|
+
| Auth & Config | [auth.md](auth.md) | Login, ADC, impersonation, config profiles |
|
|
74
|
+
| IAM & Projects | [iam.md](iam.md) | Projects, APIs, service accounts, Secret Manager |
|
|
75
|
+
| Compute & Networking | [compute.md](compute.md) | VMs, SSH, firewall, VPC, DNS, static IPs |
|
|
76
|
+
| Serverless | [serverless.md](serverless.md) | Cloud Run, Functions, App Engine, Scheduler, Tasks |
|
|
77
|
+
| Storage & Artifacts | [storage.md](storage.md) | gcloud storage, Artifact Registry |
|
|
78
|
+
| Data | [data.md](data.md) | Cloud SQL, BigQuery (bq), Pub/Sub |
|
|
79
|
+
| Automation & CI/CD | [automation.md](automation.md) | Scripting, output formats, filtering, GitHub Actions, operations |
|
|
80
|
+
|
|
81
|
+
**Read the per-service file for full command reference.**
|
|
82
|
+
|
|
83
|
+
## Pre-Flight Checks
|
|
84
|
+
|
|
85
|
+
Before working with any GCP service:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 1. Correct project?
|
|
89
|
+
gcloud config get-value project
|
|
90
|
+
|
|
91
|
+
# 2. Default region set?
|
|
92
|
+
gcloud config get-value compute/region
|
|
93
|
+
|
|
94
|
+
# 3. Required API enabled? (most APIs are disabled by default)
|
|
95
|
+
gcloud services list --filter="name:run.googleapis.com" --format="value(name)" | grep -q run || \
|
|
96
|
+
gcloud services enable run.googleapis.com
|
|
97
|
+
|
|
98
|
+
# 4. Billing enabled?
|
|
99
|
+
gcloud billing projects describe $(gcloud config get-value project) --format="value(billingEnabled)"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**If you hit `PERMISSION_DENIED: ... API has not been enabled`**, enable the API
|
|
103
|
+
mentioned in the error and retry.
|
|
104
|
+
|
|
105
|
+
## Troubleshooting
|
|
106
|
+
|
|
107
|
+
| Problem | Diagnosis | Fix |
|
|
108
|
+
|---------|-----------|-----|
|
|
109
|
+
| Auth failure | `gcloud auth list` | `gcloud auth login` or check key file |
|
|
110
|
+
| Permission denied | Check IAM (see [iam.md](iam.md)) | Grant correct role |
|
|
111
|
+
| API not enabled | Error message says which API | `gcloud services enable API_NAME` |
|
|
112
|
+
| Quota exceeded | `gcloud compute project-info describe` | Request increase in Console |
|
|
113
|
+
| Wrong project | `gcloud config get-value project` | `gcloud config set project X` |
|
|
114
|
+
| Wrong region | `gcloud config get-value compute/region` | Set correct region; related resources must match |
|
|
115
|
+
| Config confusion | `gcloud config configurations list` | Check active config, override with `--project` |
|
|
116
|
+
| Slow commands | Large result set | Use `--filter`, `--limit`, `--format=value` |
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Debug mode
|
|
120
|
+
gcloud compute instances list --verbosity=debug
|
|
121
|
+
|
|
122
|
+
# Full environment info
|
|
123
|
+
gcloud info
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Quick Reference
|
|
127
|
+
|
|
128
|
+
| Task | Command |
|
|
129
|
+
|------|---------|
|
|
130
|
+
| Login | `gcloud auth login` |
|
|
131
|
+
| Set project | `gcloud config set project PROJECT_ID` |
|
|
132
|
+
| Current project | `gcloud config get-value project` |
|
|
133
|
+
| Enable API | `gcloud services enable API.googleapis.com` |
|
|
134
|
+
| List anything | `gcloud COMPONENT list --format=json` |
|
|
135
|
+
| Describe anything | `gcloud COMPONENT describe NAME --format=json` |
|
|
136
|
+
| JSON output | `--format=json` |
|
|
137
|
+
| Single value | `--format="value(field)"` |
|
|
138
|
+
| Filter | `--filter="field=value"` |
|
|
139
|
+
| Quiet ⚠️ | `--quiet` — suppresses ALL prompts including delete confirmations |
|
|
140
|
+
| Help | `gcloud COMPONENT --help` |
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Auth & Configuration
|
|
2
|
+
|
|
3
|
+
## Authentication
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# Interactive login (opens browser)
|
|
7
|
+
gcloud auth login
|
|
8
|
+
|
|
9
|
+
# Headless / remote
|
|
10
|
+
gcloud auth login --no-browser
|
|
11
|
+
|
|
12
|
+
# Check who's authenticated
|
|
13
|
+
gcloud auth list
|
|
14
|
+
|
|
15
|
+
# Revoke
|
|
16
|
+
gcloud auth revoke user@example.com
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Service Account Impersonation (Preferred)
|
|
20
|
+
|
|
21
|
+
**Always prefer impersonation over key files** — short-lived tokens, no key distribution risk.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Single command
|
|
25
|
+
gcloud compute instances list --impersonate-service-account=SA_EMAIL
|
|
26
|
+
|
|
27
|
+
# Set as default
|
|
28
|
+
gcloud config set auth/impersonate_service_account SA_EMAIL
|
|
29
|
+
|
|
30
|
+
# Clear
|
|
31
|
+
gcloud config unset auth/impersonate_service_account
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Application Default Credentials (ADC)
|
|
35
|
+
|
|
36
|
+
For client libraries (Python, Node.js, Go, etc.):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Set up ADC
|
|
40
|
+
gcloud auth application-default login
|
|
41
|
+
|
|
42
|
+
# With impersonation
|
|
43
|
+
gcloud auth application-default login --impersonate-service-account=SA_EMAIL
|
|
44
|
+
|
|
45
|
+
# Revoke
|
|
46
|
+
gcloud auth application-default revoke
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**ADC search order**:
|
|
50
|
+
1. `GOOGLE_APPLICATION_CREDENTIALS` env var
|
|
51
|
+
2. `~/.config/gcloud/application_default_credentials.json`
|
|
52
|
+
3. GCE/GKE metadata server (when running on GCP)
|
|
53
|
+
|
|
54
|
+
## Service Account (CI/CD only)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Activate with key file (CI/CD environments)
|
|
58
|
+
gcloud auth activate-service-account --key-file=key.json
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> ⚠️ **Avoid key files when possible** — use Workload Identity Federation for
|
|
62
|
+
> GitHub Actions, or impersonation for development. Key files are static
|
|
63
|
+
> credentials that can leak.
|
|
64
|
+
|
|
65
|
+
## Configuration Profiles
|
|
66
|
+
|
|
67
|
+
Manage multiple environments without confusion:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Create per-environment configs
|
|
71
|
+
gcloud config configurations create dev
|
|
72
|
+
gcloud config set project my-project-dev
|
|
73
|
+
gcloud config set account dev@example.com
|
|
74
|
+
gcloud config set compute/region europe-west1
|
|
75
|
+
gcloud config set compute/zone europe-west1-b
|
|
76
|
+
|
|
77
|
+
gcloud config configurations create prod
|
|
78
|
+
gcloud config set project my-project-prod
|
|
79
|
+
gcloud config set auth/impersonate_service_account prod-sa@project.iam.gserviceaccount.com
|
|
80
|
+
|
|
81
|
+
# Switch environments
|
|
82
|
+
gcloud config configurations activate dev
|
|
83
|
+
gcloud config configurations list
|
|
84
|
+
|
|
85
|
+
# One-off override (doesn't change active config)
|
|
86
|
+
gcloud compute instances list --configuration=prod
|
|
87
|
+
gcloud compute instances list --project=other-project
|
|
88
|
+
|
|
89
|
+
# View current settings
|
|
90
|
+
gcloud config list
|
|
91
|
+
gcloud config get-value project
|
|
92
|
+
gcloud config get-value compute/region
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Region/Zone Consistency
|
|
96
|
+
|
|
97
|
+
Related GCP resources **must** be in the same region. Before creating any resource:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
gcloud config get-value compute/region
|
|
101
|
+
gcloud config get-value compute/zone
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Common mismatches that cause failures:
|
|
105
|
+
- VM in `europe-west1-b` connecting to Cloud SQL in `us-central1`
|
|
106
|
+
- GKE cluster in one zone, persistent disks in another
|
|
107
|
+
- Cloud Run in `europe-west1` accessing a VPC in `us-east1`
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Automation, Scripting & CI/CD
|
|
2
|
+
|
|
3
|
+
## Output Formats
|
|
4
|
+
|
|
5
|
+
**Always use `--format=json` for agent consumption.** Table output breaks parsing.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gcloud compute instances list --format=json # Full JSON
|
|
9
|
+
gcloud compute instances list --format="value(name)" # Raw values, one per line
|
|
10
|
+
gcloud compute instances list --format="csv(name,zone,status)"
|
|
11
|
+
gcloud compute instances list --format="table(name,zone.basename(),machineType.basename(),status)"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Filtering
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Server-side (efficient — sent to API)
|
|
18
|
+
gcloud compute instances list --filter="zone:europe-west1 AND status=RUNNING"
|
|
19
|
+
gcloud compute instances list --filter="name~^web-.*" # regex
|
|
20
|
+
gcloud compute instances list --filter="NOT status=TERMINATED"
|
|
21
|
+
gcloud compute instances list --filter="createTime>2026-01-01"
|
|
22
|
+
|
|
23
|
+
# Combine with format + limit
|
|
24
|
+
gcloud compute instances list \
|
|
25
|
+
--filter="status=RUNNING" \
|
|
26
|
+
--format="value(name)" \
|
|
27
|
+
--limit=10
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Idempotent Patterns
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Check-before-create
|
|
34
|
+
if ! gcloud compute instances describe my-vm --zone=europe-west1-b &>/dev/null; then
|
|
35
|
+
gcloud compute instances create my-vm --zone=europe-west1-b --machine-type=e2-medium
|
|
36
|
+
else
|
|
37
|
+
echo "Instance already exists"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# Enable-if-not-enabled (safe to run multiple times)
|
|
41
|
+
gcloud services enable compute.googleapis.com
|
|
42
|
+
|
|
43
|
+
# Delete-if-exists (suppress error if already gone)
|
|
44
|
+
gcloud compute instances delete my-vm --zone=europe-west1-b --quiet 2>/dev/null || true
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Error Handling
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Capture and check
|
|
51
|
+
OUTPUT=$(gcloud compute instances create my-vm 2>&1)
|
|
52
|
+
if [ $? -ne 0 ]; then
|
|
53
|
+
echo "Error: $OUTPUT" >&2
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# Retry with backoff
|
|
58
|
+
for i in 1 2 3 4 5; do
|
|
59
|
+
gcloud run deploy my-service --source=. --region=europe-west1 && break
|
|
60
|
+
echo "Attempt $i failed, retrying in $((i * 5))s..."
|
|
61
|
+
sleep $((i * 5))
|
|
62
|
+
done
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Waiting for Long-Running Operations
|
|
66
|
+
|
|
67
|
+
Many GCP operations (SQL instances, GKE clusters, deployments) take minutes.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Option 1: Synchronous (default — blocks until done)
|
|
71
|
+
# Most commands wait automatically. This is usually best.
|
|
72
|
+
gcloud sql instances create my-db --database-version=POSTGRES_15 --tier=db-f1-micro --region=europe-west1
|
|
73
|
+
|
|
74
|
+
# Option 2: Async + explicit wait
|
|
75
|
+
gcloud compute instances create my-vm --zone=europe-west1-b --async --format="value(targetLink)"
|
|
76
|
+
gcloud compute operations wait OPERATION_NAME --zone=europe-west1-b
|
|
77
|
+
|
|
78
|
+
# Option 3: Poll pattern (for services without `wait`)
|
|
79
|
+
OPERATION=$(gcloud sql operations list --instance=my-db --filter="status=RUNNING" --format="value(name)" --limit=1)
|
|
80
|
+
while [ -n "$OPERATION" ]; do
|
|
81
|
+
STATUS=$(gcloud sql operations describe "$OPERATION" --format="value(status)")
|
|
82
|
+
if [[ "$STATUS" == "DONE" ]]; then
|
|
83
|
+
echo "Operation complete"
|
|
84
|
+
break
|
|
85
|
+
fi
|
|
86
|
+
echo "Status: $STATUS — waiting 10s..."
|
|
87
|
+
sleep 10
|
|
88
|
+
done
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Agent note**: Default synchronous mode is usually best. Use `--async` only when
|
|
92
|
+
parallelizing multiple independent operations.
|
|
93
|
+
|
|
94
|
+
## Cloud Build
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Build and push container image
|
|
98
|
+
gcloud builds submit --tag=europe-west1-docker.pkg.dev/PROJECT_ID/my-repo/my-image:tag .
|
|
99
|
+
|
|
100
|
+
# Build with config
|
|
101
|
+
gcloud builds submit --config=cloudbuild.yaml .
|
|
102
|
+
|
|
103
|
+
# List builds
|
|
104
|
+
gcloud builds list --format=json --limit=10
|
|
105
|
+
|
|
106
|
+
# View build logs
|
|
107
|
+
gcloud builds log BUILD_ID
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## CI/CD: GitHub Actions
|
|
111
|
+
|
|
112
|
+
### With Workload Identity Federation (preferred — no keys)
|
|
113
|
+
|
|
114
|
+
```yaml
|
|
115
|
+
- uses: google-github-actions/auth@v2
|
|
116
|
+
with:
|
|
117
|
+
workload_identity_provider: projects/PROJECT_NUM/locations/global/workloadIdentityPools/POOL/providers/PROVIDER
|
|
118
|
+
service_account: SA_EMAIL
|
|
119
|
+
|
|
120
|
+
- uses: google-github-actions/setup-gcloud@v2
|
|
121
|
+
|
|
122
|
+
- run: gcloud run deploy my-service --image=IMG:${{ github.sha }} --region=europe-west1
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### With Service Account Key (fallback)
|
|
126
|
+
|
|
127
|
+
```yaml
|
|
128
|
+
- uses: google-github-actions/auth@v2
|
|
129
|
+
with:
|
|
130
|
+
credentials_json: ${{ secrets.GCP_SA_KEY }}
|
|
131
|
+
|
|
132
|
+
- uses: google-github-actions/setup-gcloud@v2
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Environment Variables
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Make scripts portable
|
|
139
|
+
PROJECT_ID="${GCP_PROJECT_ID:-my-default-project}"
|
|
140
|
+
REGION="${GCP_REGION:-europe-west1}"
|
|
141
|
+
|
|
142
|
+
gcloud config set project "$PROJECT_ID"
|
|
143
|
+
gcloud config set compute/region "$REGION"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Vertex AI (overview)
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# List models
|
|
150
|
+
gcloud ai models list --region=europe-west1 --format=json
|
|
151
|
+
|
|
152
|
+
# List endpoints
|
|
153
|
+
gcloud ai endpoints list --region=europe-west1 --format=json
|
|
154
|
+
|
|
155
|
+
# Deploy model to endpoint
|
|
156
|
+
gcloud ai endpoints deploy-model ENDPOINT_ID \
|
|
157
|
+
--model=MODEL_ID \
|
|
158
|
+
--region=europe-west1 \
|
|
159
|
+
--display-name="v1"
|
|
160
|
+
|
|
161
|
+
# Predict
|
|
162
|
+
gcloud ai endpoints predict ENDPOINT_ID \
|
|
163
|
+
--region=europe-west1 \
|
|
164
|
+
--json-request=request.json
|
|
165
|
+
```
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Compute Engine & Networking
|
|
2
|
+
|
|
3
|
+
## Compute Engine
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# READ — list instances
|
|
7
|
+
gcloud compute instances list --format=json
|
|
8
|
+
gcloud compute instances list --filter="status=RUNNING AND zone:europe-west1" --format=json
|
|
9
|
+
|
|
10
|
+
# EXPENSIVE — create instance (~$5-2000+/mo depending on type)
|
|
11
|
+
gcloud compute instances create my-vm \
|
|
12
|
+
--zone=europe-west1-b \
|
|
13
|
+
--machine-type=e2-medium \
|
|
14
|
+
--image-family=debian-12 \
|
|
15
|
+
--image-project=debian-cloud \
|
|
16
|
+
--boot-disk-size=20GB \
|
|
17
|
+
--tags=http-server
|
|
18
|
+
|
|
19
|
+
# SSH (uses IAP tunneling by default — secure)
|
|
20
|
+
gcloud compute ssh my-vm --zone=europe-west1-b
|
|
21
|
+
gcloud compute ssh my-vm --zone=europe-west1-b --tunnel-through-iap # explicit
|
|
22
|
+
|
|
23
|
+
# SCP
|
|
24
|
+
gcloud compute scp local.txt my-vm:~/remote.txt --zone=europe-west1-b
|
|
25
|
+
|
|
26
|
+
# Lifecycle
|
|
27
|
+
gcloud compute instances stop my-vm --zone=europe-west1-b
|
|
28
|
+
gcloud compute instances start my-vm --zone=europe-west1-b
|
|
29
|
+
|
|
30
|
+
# ⚠️ DESTRUCTIVE
|
|
31
|
+
gcloud compute instances delete my-vm --zone=europe-west1-b
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Firewall Rules
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# READ
|
|
38
|
+
gcloud compute firewall-rules list --format=json
|
|
39
|
+
|
|
40
|
+
# ⚠️ SECURITY — opens network ports
|
|
41
|
+
gcloud compute firewall-rules create allow-http \
|
|
42
|
+
--allow=tcp:80 --target-tags=http-server --network=default
|
|
43
|
+
|
|
44
|
+
gcloud compute firewall-rules create allow-https \
|
|
45
|
+
--allow=tcp:443 --target-tags=https-server --network=default
|
|
46
|
+
|
|
47
|
+
# ⚠️ DESTRUCTIVE
|
|
48
|
+
gcloud compute firewall-rules delete allow-http
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## VPC & Subnets
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Create VPC
|
|
55
|
+
gcloud compute networks create my-vpc --subnet-mode=auto
|
|
56
|
+
gcloud compute networks list --format=json
|
|
57
|
+
|
|
58
|
+
# Create subnet
|
|
59
|
+
gcloud compute networks subnets create my-subnet \
|
|
60
|
+
--network=my-vpc --range=10.0.0.0/24 --region=europe-west1
|
|
61
|
+
|
|
62
|
+
gcloud compute networks subnets list --format=json
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Static IPs
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
gcloud compute addresses create my-ip --region=europe-west1
|
|
69
|
+
gcloud compute addresses list --format=json
|
|
70
|
+
|
|
71
|
+
# ⚠️ Unattached static IPs cost ~$2.88/month
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## DNS
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
gcloud dns managed-zones create my-zone \
|
|
78
|
+
--dns-name="example.com." --description="My zone"
|
|
79
|
+
|
|
80
|
+
gcloud dns record-sets list --zone=my-zone --format=json
|
|
81
|
+
|
|
82
|
+
# Add A record
|
|
83
|
+
gcloud dns record-sets create www.example.com. \
|
|
84
|
+
--zone=my-zone --type=A --ttl=300 --rrdatas="1.2.3.4"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Load Balancing (overview)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
gcloud compute backend-services list --format=json
|
|
91
|
+
gcloud compute url-maps list --format=json
|
|
92
|
+
gcloud compute forwarding-rules list --format=json
|
|
93
|
+
|
|
94
|
+
# ⚠️ EXPENSIVE — load balancers cost ~$18+/month
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Logging & Monitoring
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Read logs
|
|
101
|
+
gcloud logging read "resource.type=gce_instance" --limit=20 --format=json
|
|
102
|
+
gcloud logging read "severity>=ERROR AND timestamp>=\"$(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)\"" --limit=50 --format=json
|
|
103
|
+
|
|
104
|
+
# Tail logs (live)
|
|
105
|
+
gcloud logging tail "resource.type=gce_instance"
|
|
106
|
+
|
|
107
|
+
# Write log entry
|
|
108
|
+
gcloud logging write my-log "Test message" --severity=INFO
|
|
109
|
+
|
|
110
|
+
# Monitoring
|
|
111
|
+
gcloud monitoring dashboards list --format=json
|
|
112
|
+
gcloud monitoring policies list --format=json # alert policies
|
|
113
|
+
```
|