create-svc 0.1.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 +32 -0
- package/index.ts +5 -0
- package/package.json +48 -0
- package/src/cli.ts +300 -0
- package/src/scaffold.test.ts +46 -0
- package/src/scaffold.ts +133 -0
- package/templates/root/.github/workflows/buf-publish.yml +19 -0
- package/templates/root/.github/workflows/ci.yml +26 -0
- package/templates/root/.github/workflows/deploy.yml +22 -0
- package/templates/root/Dockerfile +23 -0
- package/templates/root/README.md +69 -0
- package/templates/root/buf.gen.yaml +10 -0
- package/templates/root/buf.yaml +9 -0
- package/templates/root/cmd/server/main.go +44 -0
- package/templates/root/gen/dns/v1/dns.pb.go +623 -0
- package/templates/root/gen/dns/v1/dnsv1connect/dns.connect.go +192 -0
- package/templates/root/go.mod +10 -0
- package/templates/root/internal/app/service.go +152 -0
- package/templates/root/internal/app/token_source.go +50 -0
- package/templates/root/internal/cloudflare/client.go +160 -0
- package/templates/root/internal/config/config.go +55 -0
- package/templates/root/internal/connectapi/handler.go +79 -0
- package/templates/root/internal/httpapi/routes.go +93 -0
- package/templates/root/internal/vault/client.go +148 -0
- package/templates/root/package.json +12 -0
- package/templates/root/protos/dns/v1/dns.proto +58 -0
- package/templates/root/scripts/cloudrun/bootstrap.ts +65 -0
- package/templates/root/scripts/cloudrun/config.ts +50 -0
- package/templates/root/scripts/cloudrun/deploy.ts +41 -0
- package/templates/root/scripts/cloudrun/lib.ts +244 -0
- package/templates/root/service.yaml +50 -0
- package/templates/root/test/go.test.ts +19 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# {{SERVICE_NAME}}
|
|
2
|
+
|
|
3
|
+
Cloud Run API scaffold generated by `create-service`.
|
|
4
|
+
|
|
5
|
+
## What it includes
|
|
6
|
+
|
|
7
|
+
- Chi HTTP routes
|
|
8
|
+
- ConnectRPC handlers
|
|
9
|
+
- real Cloud Run service manifest in [service.yaml](service.yaml)
|
|
10
|
+
- Bun-based Cloud Run deploy config in [scripts/cloudrun/config.ts](scripts/cloudrun/config.ts)
|
|
11
|
+
- Vault-backed Cloudflare DNS CRUD example
|
|
12
|
+
- script-first deployment via Bun
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- Bun
|
|
17
|
+
- Go 1.25+
|
|
18
|
+
- `gcloud`
|
|
19
|
+
- `gh`
|
|
20
|
+
- `buf`
|
|
21
|
+
- `protoc`
|
|
22
|
+
- `protoc-gen-go`
|
|
23
|
+
- `protoc-gen-connect-go`
|
|
24
|
+
|
|
25
|
+
Install the Go protobuf plugins:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.10
|
|
29
|
+
go install connectrpc.com/connect/cmd/protoc-gen-connect-go@v1.19.1
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
bun dev
|
|
36
|
+
bun gen
|
|
37
|
+
bun lint
|
|
38
|
+
bun test
|
|
39
|
+
bun deploy
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`bun test` uses Bun's test runner to invoke `go test ./...` so the command surface stays Bun-first.
|
|
43
|
+
|
|
44
|
+
## First deploy
|
|
45
|
+
|
|
46
|
+
The runtime reads Vault AppRole credentials from Secret Manager. On the first deploy, seed those two secret values locally:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export BOOTSTRAP_VAULT_ROLE_ID=...
|
|
50
|
+
export BOOTSTRAP_VAULT_SECRET_ID=...
|
|
51
|
+
bun deploy
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`bun deploy` will:
|
|
55
|
+
|
|
56
|
+
1. enable required GCP services
|
|
57
|
+
2. create runtime and deployer service accounts
|
|
58
|
+
3. create the Secret Manager secrets if missing
|
|
59
|
+
4. wire GitHub OIDC for `main` deploys
|
|
60
|
+
5. build the image and apply the Cloud Run manifest through the Bun deploy helper
|
|
61
|
+
|
|
62
|
+
## Local fallback
|
|
63
|
+
|
|
64
|
+
For local development, you can skip Vault and provide the Cloudflare token directly:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
export CLOUDFLARE_API_TOKEN=...
|
|
68
|
+
bun dev
|
|
69
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"log"
|
|
5
|
+
"net/http"
|
|
6
|
+
"time"
|
|
7
|
+
|
|
8
|
+
"github.com/go-chi/chi/v5"
|
|
9
|
+
"golang.org/x/net/http2"
|
|
10
|
+
"golang.org/x/net/http2/h2c"
|
|
11
|
+
|
|
12
|
+
"{{MODULE_PATH}}/internal/app"
|
|
13
|
+
"{{MODULE_PATH}}/internal/config"
|
|
14
|
+
"{{MODULE_PATH}}/internal/connectapi"
|
|
15
|
+
"{{MODULE_PATH}}/internal/httpapi"
|
|
16
|
+
"{{MODULE_PATH}}/internal/vault"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
func main() {
|
|
20
|
+
cfg, err := config.Load()
|
|
21
|
+
if err != nil {
|
|
22
|
+
log.Fatal(err)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
httpClient := &http.Client{Timeout: 15 * time.Second}
|
|
26
|
+
vaultClient := vault.NewAppRoleClient(cfg.VaultAddr, cfg.VaultRoleIDFile, cfg.VaultSecretIDFile, httpClient)
|
|
27
|
+
tokenSource := app.NewCloudflareTokenSource(vaultClient, cfg.VaultSecretPath, cfg.VaultSecretKey)
|
|
28
|
+
service := app.NewDNSService(cfg.CloudflareZoneID, cfg.CloudflareAPIBaseURL, tokenSource)
|
|
29
|
+
|
|
30
|
+
router := chi.NewRouter()
|
|
31
|
+
httpapi.RegisterRoutes(router, service)
|
|
32
|
+
|
|
33
|
+
connectPath, connectHandler := connectapi.NewHandler(service)
|
|
34
|
+
router.Mount(connectPath, connectHandler)
|
|
35
|
+
|
|
36
|
+
server := &http.Server{
|
|
37
|
+
Addr: ":" + cfg.Port,
|
|
38
|
+
ReadHeaderTimeout: 10 * time.Second,
|
|
39
|
+
Handler: h2c.NewHandler(router, &http2.Server{}),
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
log.Printf("listening on %s", server.Addr)
|
|
43
|
+
log.Fatal(server.ListenAndServe())
|
|
44
|
+
}
|