container-superposition 0.1.3 → 0.1.4
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/README.md +365 -9
- package/dist/scripts/init.js +220 -94
- package/dist/scripts/init.js.map +1 -1
- package/dist/tool/commands/doctor.js +2 -2
- package/dist/tool/commands/explain.d.ts.map +1 -1
- package/dist/tool/commands/explain.js +88 -0
- package/dist/tool/commands/explain.js.map +1 -1
- package/dist/tool/commands/plan.d.ts +51 -0
- package/dist/tool/commands/plan.d.ts.map +1 -1
- package/dist/tool/commands/plan.js +523 -1
- package/dist/tool/commands/plan.js.map +1 -1
- package/dist/tool/questionnaire/composer.d.ts +12 -3
- package/dist/tool/questionnaire/composer.d.ts.map +1 -1
- package/dist/tool/questionnaire/composer.js +133 -20
- package/dist/tool/questionnaire/composer.js.map +1 -1
- package/dist/tool/schema/types.d.ts +18 -0
- package/dist/tool/schema/types.d.ts.map +1 -1
- package/dist/tool/utils/gitignore.d.ts +15 -0
- package/dist/tool/utils/gitignore.d.ts.map +1 -0
- package/dist/tool/utils/gitignore.js +41 -0
- package/dist/tool/utils/gitignore.js.map +1 -0
- package/dist/tool/utils/services-export.d.ts +14 -0
- package/dist/tool/utils/services-export.d.ts.map +1 -0
- package/dist/tool/utils/services-export.js +478 -0
- package/dist/tool/utils/services-export.js.map +1 -0
- package/dist/tool/utils/summary.d.ts +69 -0
- package/dist/tool/utils/summary.d.ts.map +1 -0
- package/dist/tool/utils/summary.js +260 -0
- package/dist/tool/utils/summary.js.map +1 -0
- package/docs/overlays.md +48 -5
- package/overlays/.presets/microservice.yml +32 -6
- package/overlays/.presets/web-api.yml +76 -56
- package/overlays/cloudflared/README.md +190 -0
- package/overlays/cloudflared/devcontainer.patch.json +3 -0
- package/overlays/cloudflared/overlay.yml +15 -0
- package/overlays/cloudflared/setup.sh +49 -0
- package/overlays/cloudflared/verify.sh +21 -0
- package/overlays/direnv/README.md +6 -4
- package/overlays/direnv/setup.sh +0 -12
- package/overlays/grpc-tools/README.md +242 -0
- package/overlays/grpc-tools/devcontainer.patch.json +14 -0
- package/overlays/grpc-tools/overlay.yml +14 -0
- package/overlays/grpc-tools/setup.sh +57 -0
- package/overlays/grpc-tools/verify.sh +47 -0
- package/overlays/keycloak/.env.example +5 -0
- package/overlays/keycloak/README.md +238 -0
- package/overlays/keycloak/devcontainer.patch.json +17 -0
- package/overlays/keycloak/docker-compose.yml +32 -0
- package/overlays/keycloak/overlay.yml +23 -0
- package/overlays/keycloak/verify.sh +54 -0
- package/overlays/mailpit/.env.example +4 -0
- package/overlays/mailpit/README.md +191 -0
- package/overlays/mailpit/devcontainer.patch.json +20 -0
- package/overlays/mailpit/docker-compose.yml +17 -0
- package/overlays/mailpit/overlay.yml +26 -0
- package/overlays/mailpit/verify.sh +52 -0
- package/overlays/ngrok/overlay.yml +2 -1
- package/overlays/python/README.md +51 -35
- package/overlays/python/devcontainer.patch.json +7 -4
- package/overlays/python/setup.sh +50 -23
- package/overlays/python/verify.sh +29 -1
- package/package.json +1 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Cloudflared Overlay
|
|
2
|
+
|
|
3
|
+
Cloudflare Tunnel for securely exposing local services to the internet — no port forwarding or firewall configuration required.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **cloudflared** - Cloudflare's tunneling daemon
|
|
8
|
+
- **No account required** - Anonymous tunnels work immediately
|
|
9
|
+
- **Free** - Generous free tier with no connection limits
|
|
10
|
+
- **Named tunnels** - Persistent URLs with a Cloudflare account (optional)
|
|
11
|
+
- **HTTPS by default** - All tunnels use TLS automatically
|
|
12
|
+
|
|
13
|
+
## How It Works
|
|
14
|
+
|
|
15
|
+
`cloudflared` creates an outbound-only connection from your dev container to Cloudflare's edge network. Incoming requests are routed through Cloudflare to your local service — no inbound firewall rules needed.
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Expose your local web server (no account required)
|
|
21
|
+
cloudflared tunnel --url http://localhost:3000
|
|
22
|
+
|
|
23
|
+
# Output:
|
|
24
|
+
# +--------------------------------------------------------------------------------------------+
|
|
25
|
+
# | Your quick Tunnel has been created! Visit it at (it may take some time to be reachable): |
|
|
26
|
+
# | https://random-words-here.trycloudflare.com |
|
|
27
|
+
# +--------------------------------------------------------------------------------------------+
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Common Commands
|
|
31
|
+
|
|
32
|
+
### Anonymous Tunnel (No Account)
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# HTTP service
|
|
36
|
+
cloudflared tunnel --url http://localhost:3000
|
|
37
|
+
|
|
38
|
+
# HTTPS service (pass through TLS)
|
|
39
|
+
cloudflared tunnel --url https://localhost:8443
|
|
40
|
+
|
|
41
|
+
# Custom local port
|
|
42
|
+
cloudflared tunnel --url http://localhost:8080
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Named Tunnel (Requires Cloudflare Account)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# 1. Log in to Cloudflare
|
|
49
|
+
cloudflared login
|
|
50
|
+
|
|
51
|
+
# 2. Create a named tunnel
|
|
52
|
+
cloudflared tunnel create my-dev-tunnel
|
|
53
|
+
|
|
54
|
+
# 3. Route traffic to a domain you own
|
|
55
|
+
cloudflared tunnel route dns my-dev-tunnel dev.yourdomain.com
|
|
56
|
+
|
|
57
|
+
# 4. Run the tunnel
|
|
58
|
+
cloudflared tunnel run my-dev-tunnel
|
|
59
|
+
|
|
60
|
+
# Run with a specific URL
|
|
61
|
+
cloudflared tunnel --url http://localhost:3000 run my-dev-tunnel
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Configuration File
|
|
65
|
+
|
|
66
|
+
Create `~/.cloudflared/config.yml` for persistent configuration:
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
tunnel: my-dev-tunnel
|
|
70
|
+
credentials-file: /home/user/.cloudflared/<tunnel-id>.json
|
|
71
|
+
|
|
72
|
+
ingress:
|
|
73
|
+
- hostname: dev.yourdomain.com
|
|
74
|
+
service: http://localhost:3000
|
|
75
|
+
- hostname: api.yourdomain.com
|
|
76
|
+
service: http://localhost:8080
|
|
77
|
+
- service: http_status:404
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Run using config file
|
|
82
|
+
cloudflared tunnel run
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Status and Diagnostics
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Check version
|
|
89
|
+
cloudflared --version
|
|
90
|
+
|
|
91
|
+
# List your tunnels (requires login)
|
|
92
|
+
cloudflared tunnel list
|
|
93
|
+
|
|
94
|
+
# Get tunnel info
|
|
95
|
+
cloudflared tunnel info my-dev-tunnel
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Use Cases
|
|
99
|
+
|
|
100
|
+
- **Webhook testing** - Receive webhooks from GitHub, Stripe, Twilio, etc.
|
|
101
|
+
- **Mobile device testing** - Test your app on real devices without complex setup
|
|
102
|
+
- **Demo sharing** - Share work-in-progress with clients or colleagues
|
|
103
|
+
- **OAuth callbacks** - Test OAuth flows that require a public redirect URI
|
|
104
|
+
- **Long-running tunnels** - More stable than temporary ngrok tunnels
|
|
105
|
+
|
|
106
|
+
## Webhook Testing Examples
|
|
107
|
+
|
|
108
|
+
### GitHub Webhooks
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# 1. Start tunnel
|
|
112
|
+
cloudflared tunnel --url http://localhost:3000
|
|
113
|
+
|
|
114
|
+
# 2. Copy the *.trycloudflare.com URL
|
|
115
|
+
# 3. Add webhook in GitHub: Settings → Webhooks → Add webhook
|
|
116
|
+
# Payload URL: https://random-words.trycloudflare.com/webhook
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Stripe Webhooks
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Start tunnel
|
|
123
|
+
cloudflared tunnel --url http://localhost:4242
|
|
124
|
+
|
|
125
|
+
# Configure Stripe webhook:
|
|
126
|
+
# Dashboard → Developers → Webhooks → Add endpoint
|
|
127
|
+
# URL: https://random-words.trycloudflare.com/stripe/webhook
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Benefits vs ngrok
|
|
131
|
+
|
|
132
|
+
| Feature | Cloudflared (this overlay) | ngrok |
|
|
133
|
+
| -------------------------- | -------------------------- | --------------------- |
|
|
134
|
+
| **Account required** | No (anonymous tunnels) | Yes |
|
|
135
|
+
| **Free tier limits** | No limits (anonymous) | 40 connections/minute |
|
|
136
|
+
| **Persistent URL (free)** | No (random per session) | No |
|
|
137
|
+
| **Named tunnels** | Yes (with account) | Yes (paid) |
|
|
138
|
+
| **Traffic inspector UI** | No | Yes (port 4040) |
|
|
139
|
+
| **Cloudflare integration** | ✅ Native | No |
|
|
140
|
+
| **Connection stability** | Very stable | Good |
|
|
141
|
+
|
|
142
|
+
## Security Considerations
|
|
143
|
+
|
|
144
|
+
⚠️ When exposing local services to the internet:
|
|
145
|
+
|
|
146
|
+
- Cloudflared exposes your local service to public internet traffic
|
|
147
|
+
- Use HTTPS endpoints when possible
|
|
148
|
+
- Do not expose services with sensitive data without authentication
|
|
149
|
+
- Anonymous tunnels are not persistent — URL changes each session
|
|
150
|
+
|
|
151
|
+
## Troubleshooting
|
|
152
|
+
|
|
153
|
+
### Tunnel not starting
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Check cloudflared version
|
|
157
|
+
cloudflared --version
|
|
158
|
+
|
|
159
|
+
# Run with verbose logging
|
|
160
|
+
cloudflared tunnel --url http://localhost:3000 --loglevel debug
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Connection refused
|
|
164
|
+
|
|
165
|
+
Ensure your local service is running and listening on the specified port:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Check if service is listening
|
|
169
|
+
curl http://localhost:3000
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Named tunnel errors
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# Re-authenticate
|
|
176
|
+
cloudflared login
|
|
177
|
+
|
|
178
|
+
# List tunnels to verify it exists
|
|
179
|
+
cloudflared tunnel list
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## References
|
|
183
|
+
|
|
184
|
+
- [Cloudflare Tunnel Documentation](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/)
|
|
185
|
+
- [cloudflared GitHub](https://github.com/cloudflare/cloudflared)
|
|
186
|
+
- [Cloudflare Free Tunnel Guide](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/)
|
|
187
|
+
|
|
188
|
+
**Related Overlays:**
|
|
189
|
+
|
|
190
|
+
- `ngrok` - Alternative tunneling tool (conflicts with this overlay)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
id: cloudflared
|
|
2
|
+
name: Cloudflared
|
|
3
|
+
description: Cloudflare Tunnel for securely exposing local services to the internet
|
|
4
|
+
category: dev
|
|
5
|
+
supports: []
|
|
6
|
+
requires: []
|
|
7
|
+
suggests: []
|
|
8
|
+
conflicts:
|
|
9
|
+
- ngrok
|
|
10
|
+
tags:
|
|
11
|
+
- dev
|
|
12
|
+
- tunneling
|
|
13
|
+
- proxy
|
|
14
|
+
- cloudflare
|
|
15
|
+
ports: []
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Cloudflared setup script
|
|
3
|
+
# Installs cloudflared from official repository
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
echo "🌐 Setting up Cloudflared..."
|
|
8
|
+
|
|
9
|
+
# Install cloudflared using official package
|
|
10
|
+
echo "📦 Installing cloudflared..."
|
|
11
|
+
|
|
12
|
+
# Pin to a specific version for reproducibility and security
|
|
13
|
+
# Check https://github.com/cloudflare/cloudflared/releases for newer versions
|
|
14
|
+
CF_VERSION="${CLOUDFLARED_VERSION:-2025.2.1}"
|
|
15
|
+
|
|
16
|
+
# Detect architecture
|
|
17
|
+
ARCH=$(uname -m)
|
|
18
|
+
case "$ARCH" in
|
|
19
|
+
x86_64) CF_ARCH="amd64" ;;
|
|
20
|
+
aarch64 | arm64) CF_ARCH="arm64" ;;
|
|
21
|
+
*) echo " ⚠️ Unsupported architecture: $ARCH" ; CF_ARCH="amd64" ;;
|
|
22
|
+
esac
|
|
23
|
+
|
|
24
|
+
CF_URL="https://github.com/cloudflare/cloudflared/releases/download/${CF_VERSION}/cloudflared-linux-${CF_ARCH}"
|
|
25
|
+
curl -sSL "$CF_URL" -o /tmp/cloudflared
|
|
26
|
+
sudo install -m 755 /tmp/cloudflared /usr/local/bin/cloudflared
|
|
27
|
+
rm -f /tmp/cloudflared
|
|
28
|
+
|
|
29
|
+
# Verify installation
|
|
30
|
+
if command -v cloudflared &> /dev/null; then
|
|
31
|
+
echo " ✅ cloudflared installed: $(cloudflared --version)"
|
|
32
|
+
else
|
|
33
|
+
echo " ❌ cloudflared installation failed"
|
|
34
|
+
exit 1
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
echo ""
|
|
38
|
+
echo "✅ Cloudflared setup complete"
|
|
39
|
+
echo ""
|
|
40
|
+
echo "💡 Quick start (no account required):"
|
|
41
|
+
echo " cloudflared tunnel --url http://localhost:3000"
|
|
42
|
+
echo ""
|
|
43
|
+
echo "💡 Named tunnel (persistent URL, requires Cloudflare account):"
|
|
44
|
+
echo " cloudflared login"
|
|
45
|
+
echo " cloudflared tunnel create my-tunnel"
|
|
46
|
+
echo " cloudflared tunnel route dns my-tunnel myapp.example.com"
|
|
47
|
+
echo " cloudflared tunnel run my-tunnel"
|
|
48
|
+
echo ""
|
|
49
|
+
echo "📚 Documentation: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Verification script for Cloudflared overlay
|
|
3
|
+
# Confirms cloudflared is installed
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
echo "🔍 Verifying Cloudflared overlay..."
|
|
8
|
+
echo ""
|
|
9
|
+
|
|
10
|
+
# Check cloudflared
|
|
11
|
+
echo "1️⃣ Checking cloudflared..."
|
|
12
|
+
if command -v cloudflared &> /dev/null; then
|
|
13
|
+
echo " ✅ cloudflared found: $(cloudflared --version)"
|
|
14
|
+
else
|
|
15
|
+
echo " ❌ cloudflared not found"
|
|
16
|
+
exit 1
|
|
17
|
+
fi
|
|
18
|
+
|
|
19
|
+
echo ""
|
|
20
|
+
echo "✅ Cloudflared overlay verification complete"
|
|
21
|
+
echo " Quick start: cloudflared tunnel --url http://localhost:3000"
|
|
@@ -214,7 +214,7 @@ dotenv_if_exists .env
|
|
|
214
214
|
source_env_if_exists .envrc.local
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
Create `.envrc.local` (
|
|
217
|
+
Create `.envrc.local` (automatically gitignored at generation time):
|
|
218
218
|
|
|
219
219
|
```bash
|
|
220
220
|
export PERSONAL_API_KEY="my-secret-key"
|
|
@@ -293,7 +293,7 @@ export NODE_ENV="development"
|
|
|
293
293
|
dotenv_if_exists .env
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
-
**.env** - Do NOT commit (
|
|
296
|
+
**.env** - Do NOT commit (automatically gitignored at generation time):
|
|
297
297
|
|
|
298
298
|
```bash
|
|
299
299
|
# Secrets - never commit
|
|
@@ -447,16 +447,18 @@ Settings are automatically loaded. Reload window if needed:
|
|
|
447
447
|
|
|
448
448
|
### Git
|
|
449
449
|
|
|
450
|
-
|
|
450
|
+
When this overlay is selected, the following patterns are automatically added to your project’s `.gitignore` at generation time — no manual step required:
|
|
451
451
|
|
|
452
452
|
```bash
|
|
453
|
-
# .gitignore
|
|
453
|
+
# .gitignore (managed automatically)
|
|
454
454
|
.env
|
|
455
455
|
.env.local
|
|
456
456
|
.envrc.local
|
|
457
457
|
.direnv/
|
|
458
458
|
```
|
|
459
459
|
|
|
460
|
+
This ensures environment secrets are never accidentally committed.
|
|
461
|
+
|
|
460
462
|
### Docker Compose
|
|
461
463
|
|
|
462
464
|
```bash
|
package/overlays/direnv/setup.sh
CHANGED
|
@@ -117,18 +117,6 @@ EOF
|
|
|
117
117
|
echo "✓ Sample .env.example created"
|
|
118
118
|
fi
|
|
119
119
|
|
|
120
|
-
# Create .gitignore entries for environment files
|
|
121
|
-
if [ -f .gitignore ]; then
|
|
122
|
-
if ! grep -q ".envrc" .gitignore; then
|
|
123
|
-
echo "" >> .gitignore
|
|
124
|
-
echo "# Direnv" >> .gitignore
|
|
125
|
-
echo ".envrc.local" >> .gitignore
|
|
126
|
-
echo ".env" >> .gitignore
|
|
127
|
-
echo ".env.local" >> .gitignore
|
|
128
|
-
echo "✓ Added direnv entries to .gitignore"
|
|
129
|
-
fi
|
|
130
|
-
fi
|
|
131
|
-
|
|
132
120
|
echo "✓ direnv setup complete"
|
|
133
121
|
echo ""
|
|
134
122
|
echo "💡 Usage:"
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# gRPC Tools Overlay
|
|
2
|
+
|
|
3
|
+
Protocol Buffers compiler, Buf schema management CLI, and grpcurl for gRPC API development.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **protoc** - Protocol Buffers compiler (from system packages)
|
|
8
|
+
- **buf** - Modern schema management, linting, and breaking change detection
|
|
9
|
+
- **grpcurl** - Command-line tool for interacting with gRPC servers (like curl for gRPC)
|
|
10
|
+
- **VS Code Extensions:**
|
|
11
|
+
- [vscode-proto3](https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3) - Proto3 syntax highlighting and validation
|
|
12
|
+
- [vscode-buf](https://marketplace.visualstudio.com/items?itemName=bufbuild.vscode-buf) - Buf integration for VS Code
|
|
13
|
+
|
|
14
|
+
## How It Works
|
|
15
|
+
|
|
16
|
+
This overlay installs the gRPC development toolchain into the dev container. `protoc` is installed via system packages, while `buf` and `grpcurl` are downloaded from their official GitHub releases.
|
|
17
|
+
|
|
18
|
+
## Common Commands
|
|
19
|
+
|
|
20
|
+
### protoc (Protocol Buffers Compiler)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Compile .proto files to Go
|
|
24
|
+
protoc --go_out=. --go-grpc_out=. api/v1/service.proto
|
|
25
|
+
|
|
26
|
+
# Compile to Python
|
|
27
|
+
protoc --python_out=. api/v1/service.proto
|
|
28
|
+
|
|
29
|
+
# Compile to JavaScript/TypeScript
|
|
30
|
+
protoc --js_out=import_style=commonjs,binary:. api/v1/service.proto
|
|
31
|
+
|
|
32
|
+
# Check version
|
|
33
|
+
protoc --version
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### buf (Schema Management)
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Initialize buf workspace
|
|
40
|
+
buf config init
|
|
41
|
+
|
|
42
|
+
# Lint .proto files
|
|
43
|
+
buf lint
|
|
44
|
+
|
|
45
|
+
# Detect breaking changes
|
|
46
|
+
buf breaking --against .git#branch=main
|
|
47
|
+
|
|
48
|
+
# Generate code from .proto files
|
|
49
|
+
buf generate
|
|
50
|
+
|
|
51
|
+
# Format .proto files
|
|
52
|
+
buf format -w
|
|
53
|
+
|
|
54
|
+
# Push schema to Buf Schema Registry
|
|
55
|
+
buf push
|
|
56
|
+
|
|
57
|
+
# Check version
|
|
58
|
+
buf --version
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### grpcurl (gRPC Testing)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# List all services on a gRPC server
|
|
65
|
+
grpcurl -plaintext localhost:50051 list
|
|
66
|
+
|
|
67
|
+
# List methods on a service
|
|
68
|
+
grpcurl -plaintext localhost:50051 list mypackage.MyService
|
|
69
|
+
|
|
70
|
+
# Describe a method
|
|
71
|
+
grpcurl -plaintext localhost:50051 describe mypackage.MyService.MyMethod
|
|
72
|
+
|
|
73
|
+
# Call a method
|
|
74
|
+
grpcurl -plaintext -d '{"name": "World"}' localhost:50051 mypackage.MyService/SayHello
|
|
75
|
+
|
|
76
|
+
# Call with headers
|
|
77
|
+
grpcurl -plaintext \
|
|
78
|
+
-H "Authorization: Bearer $TOKEN" \
|
|
79
|
+
-d '{"id": 1}' \
|
|
80
|
+
localhost:50051 mypackage.MyService/GetUser
|
|
81
|
+
|
|
82
|
+
# Stream response
|
|
83
|
+
grpcurl -plaintext localhost:50051 mypackage.MyService/ListUsers
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Example .proto File
|
|
87
|
+
|
|
88
|
+
```protobuf
|
|
89
|
+
syntax = "proto3";
|
|
90
|
+
|
|
91
|
+
package myservice.v1;
|
|
92
|
+
|
|
93
|
+
option go_package = "github.com/myorg/myservice/gen/go/myservice/v1";
|
|
94
|
+
|
|
95
|
+
service UserService {
|
|
96
|
+
rpc GetUser(GetUserRequest) returns (GetUserResponse);
|
|
97
|
+
rpc ListUsers(ListUsersRequest) returns (stream User);
|
|
98
|
+
rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
message User {
|
|
102
|
+
string id = 1;
|
|
103
|
+
string name = 2;
|
|
104
|
+
string email = 3;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
message GetUserRequest {
|
|
108
|
+
string id = 1;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
message GetUserResponse {
|
|
112
|
+
User user = 1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
message ListUsersRequest {}
|
|
116
|
+
|
|
117
|
+
message CreateUserRequest {
|
|
118
|
+
string name = 1;
|
|
119
|
+
string email = 2;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
message CreateUserResponse {
|
|
123
|
+
User user = 1;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## buf.yaml Configuration
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
version: v2
|
|
131
|
+
modules:
|
|
132
|
+
- path: proto
|
|
133
|
+
lint:
|
|
134
|
+
use:
|
|
135
|
+
- DEFAULT
|
|
136
|
+
breaking:
|
|
137
|
+
use:
|
|
138
|
+
- FILE
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## buf.gen.yaml (Code Generation)
|
|
142
|
+
|
|
143
|
+
```yaml
|
|
144
|
+
version: v2
|
|
145
|
+
plugins:
|
|
146
|
+
# Go
|
|
147
|
+
- remote: buf.build/protocolbuffers/go
|
|
148
|
+
out: gen/go
|
|
149
|
+
opt:
|
|
150
|
+
- paths=source_relative
|
|
151
|
+
- remote: buf.build/grpc/go
|
|
152
|
+
out: gen/go
|
|
153
|
+
opt:
|
|
154
|
+
- paths=source_relative
|
|
155
|
+
|
|
156
|
+
# Python
|
|
157
|
+
- remote: buf.build/protocolbuffers/python
|
|
158
|
+
out: gen/python
|
|
159
|
+
|
|
160
|
+
# TypeScript (Node.js)
|
|
161
|
+
- remote: buf.build/connectrpc/node
|
|
162
|
+
out: gen/typescript
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Language-Specific Setup
|
|
166
|
+
|
|
167
|
+
### Go
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
# Install Go gRPC plugins
|
|
171
|
+
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
|
172
|
+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Node.js
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Install grpc-tools for Node.js
|
|
179
|
+
npm install --save-dev grpc-tools @grpc/grpc-js @grpc/proto-loader
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Python
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Install Python gRPC tools
|
|
186
|
+
pip install grpcio grpcio-tools
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Use Cases
|
|
190
|
+
|
|
191
|
+
- **gRPC API development** - Design, implement, and test gRPC services
|
|
192
|
+
- **Protocol Buffers schema management** - Lint, format, and version schemas
|
|
193
|
+
- **gRPC endpoint testing** - Test services without a full client implementation
|
|
194
|
+
- **Microservice communication** - Develop services that communicate via gRPC
|
|
195
|
+
- **API documentation** - Describe and explore gRPC service contracts
|
|
196
|
+
|
|
197
|
+
## Troubleshooting
|
|
198
|
+
|
|
199
|
+
### protoc plugins not found
|
|
200
|
+
|
|
201
|
+
After installing language-specific plugins, ensure they are in your `PATH`:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Go plugins
|
|
205
|
+
export PATH="$PATH:$(go env GOPATH)/bin"
|
|
206
|
+
|
|
207
|
+
# Verify
|
|
208
|
+
which protoc-gen-go
|
|
209
|
+
which protoc-gen-go-grpc
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### buf lint errors
|
|
213
|
+
|
|
214
|
+
Run `buf lint` to see all lint errors:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
buf lint
|
|
218
|
+
# proto/api/v1/service.proto:10:1:Service name "userService" should be PascalCase
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### grpcurl: server does not support the reflection API
|
|
222
|
+
|
|
223
|
+
Enable gRPC server reflection in your service:
|
|
224
|
+
|
|
225
|
+
```go
|
|
226
|
+
// Go example
|
|
227
|
+
import "google.golang.org/grpc/reflection"
|
|
228
|
+
reflection.Register(grpcServer)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## References
|
|
232
|
+
|
|
233
|
+
- [Protocol Buffers Documentation](https://protobuf.dev/)
|
|
234
|
+
- [Buf Documentation](https://buf.build/docs/)
|
|
235
|
+
- [grpcurl GitHub](https://github.com/fullstorydev/grpcurl)
|
|
236
|
+
- [gRPC Documentation](https://grpc.io/docs/)
|
|
237
|
+
|
|
238
|
+
**Related Overlays:**
|
|
239
|
+
|
|
240
|
+
- `go` - Go language runtime
|
|
241
|
+
- `nodejs` - Node.js runtime
|
|
242
|
+
- `python` - Python runtime
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.base.schema.json",
|
|
3
|
+
"features": {
|
|
4
|
+
"./features/cross-distro-packages": {
|
|
5
|
+
"apt": "protobuf-compiler",
|
|
6
|
+
"apk": "protobuf"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"customizations": {
|
|
10
|
+
"vscode": {
|
|
11
|
+
"extensions": ["zxh404.vscode-proto3", "bufbuild.vscode-buf"]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
id: grpc-tools
|
|
2
|
+
name: gRPC Tools
|
|
3
|
+
description: Protocol Buffers compiler, Buf, and grpcurl for gRPC development
|
|
4
|
+
category: dev
|
|
5
|
+
supports: []
|
|
6
|
+
requires: []
|
|
7
|
+
suggests: []
|
|
8
|
+
conflicts: []
|
|
9
|
+
tags:
|
|
10
|
+
- dev
|
|
11
|
+
- grpc
|
|
12
|
+
- protobuf
|
|
13
|
+
- api
|
|
14
|
+
ports: []
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# gRPC Tools setup script
|
|
3
|
+
# Installs buf CLI and grpcurl
|
|
4
|
+
|
|
5
|
+
set -e
|
|
6
|
+
|
|
7
|
+
echo "🔧 Setting up gRPC Tools..."
|
|
8
|
+
|
|
9
|
+
# Install buf CLI
|
|
10
|
+
echo "📦 Installing buf CLI..."
|
|
11
|
+
BUF_VERSION="${BUF_VERSION:-1.47.2}"
|
|
12
|
+
|
|
13
|
+
# Detect architecture
|
|
14
|
+
ARCH=$(uname -m)
|
|
15
|
+
case "$ARCH" in
|
|
16
|
+
x86_64) BUF_ARCH="x86_64" ;;
|
|
17
|
+
aarch64 | arm64) BUF_ARCH="aarch64" ;;
|
|
18
|
+
*) echo " ⚠️ Unsupported architecture: $ARCH, skipping buf installation" ; BUF_ARCH="" ;;
|
|
19
|
+
esac
|
|
20
|
+
|
|
21
|
+
if [ -n "$BUF_ARCH" ]; then
|
|
22
|
+
BUF_URL="https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-Linux-${BUF_ARCH}"
|
|
23
|
+
curl -sSL "$BUF_URL" -o /tmp/buf
|
|
24
|
+
sudo install -m 755 /tmp/buf /usr/local/bin/buf
|
|
25
|
+
rm -f /tmp/buf
|
|
26
|
+
echo " ✅ buf installed: $(buf --version)"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Install grpcurl
|
|
30
|
+
echo "📦 Installing grpcurl..."
|
|
31
|
+
GRPCURL_VERSION="${GRPCURL_VERSION:-1.9.2}"
|
|
32
|
+
|
|
33
|
+
GRPCURL_ARCH="$(uname -m)"
|
|
34
|
+
case "$GRPCURL_ARCH" in
|
|
35
|
+
x86_64) GRPCURL_ARCH="x86_64" ;;
|
|
36
|
+
aarch64 | arm64) GRPCURL_ARCH="arm64" ;;
|
|
37
|
+
*) echo " ⚠️ Unsupported architecture: $GRPCURL_ARCH, skipping grpcurl installation" ; GRPCURL_ARCH="" ;;
|
|
38
|
+
esac
|
|
39
|
+
|
|
40
|
+
if [ -n "$GRPCURL_ARCH" ]; then
|
|
41
|
+
GRPCURL_URL="https://github.com/fullstorydev/grpcurl/releases/download/v${GRPCURL_VERSION}/grpcurl_${GRPCURL_VERSION}_linux_${GRPCURL_ARCH}.tar.gz"
|
|
42
|
+
curl -sSL "$GRPCURL_URL" | sudo tar -xz -C /usr/local/bin grpcurl
|
|
43
|
+
echo " ✅ grpcurl installed: $(grpcurl --version 2>&1 | head -1)"
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
echo ""
|
|
47
|
+
echo "✅ gRPC Tools setup complete"
|
|
48
|
+
echo ""
|
|
49
|
+
echo "💡 Quick start:"
|
|
50
|
+
echo " protoc --version # Protocol Buffers compiler"
|
|
51
|
+
echo " buf --version # Buf CLI (schema management)"
|
|
52
|
+
echo " grpcurl --version # gRPC curl"
|
|
53
|
+
echo ""
|
|
54
|
+
echo "📚 Resources:"
|
|
55
|
+
echo " https://protobuf.dev/ # Protocol Buffers documentation"
|
|
56
|
+
echo " https://buf.build/docs/ # Buf CLI documentation"
|
|
57
|
+
echo " https://github.com/fullstorydev/grpcurl # grpcurl documentation"
|