create-svc 0.1.20 → 0.1.21
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/package.json +1 -1
- package/src/post-scaffold.test.ts +22 -3
- package/src/post-scaffold.ts +31 -6
package/package.json
CHANGED
|
@@ -28,8 +28,8 @@ describe("buildPostScaffoldCommands", () => {
|
|
|
28
28
|
describe("buildDeploymentVerificationCommands", () => {
|
|
29
29
|
test("uses curl health checks for HTTP services", () => {
|
|
30
30
|
expect(buildDeploymentVerificationCommands({ apiHostname: "api.launch.anmho.com", framework: "hono", runtime: "bun" })).toEqual([
|
|
31
|
-
{ command: "
|
|
32
|
-
{ command: "
|
|
31
|
+
{ command: "sh", args: ["-c", 'curl --fail --show-error --silent "https://api.launch.anmho.com/healthz"'] },
|
|
32
|
+
{ command: "sh", args: ["-c", 'curl --fail --show-error --silent "https://api.launch.anmho.com/readyz"'] },
|
|
33
33
|
{
|
|
34
34
|
command: "sh",
|
|
35
35
|
args: [
|
|
@@ -40,12 +40,31 @@ describe("buildDeploymentVerificationCommands", () => {
|
|
|
40
40
|
]);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
test("uses the immediate Cloud Run service URL when project details are available", () => {
|
|
44
|
+
expect(
|
|
45
|
+
buildDeploymentVerificationCommands({
|
|
46
|
+
apiHostname: "api.launch.anmho.com",
|
|
47
|
+
framework: "hono",
|
|
48
|
+
runtime: "bun",
|
|
49
|
+
serviceName: "launch-api",
|
|
50
|
+
gcpProject: "anmho-infra-prod",
|
|
51
|
+
region: "us-west1",
|
|
52
|
+
})
|
|
53
|
+
).toContainEqual({
|
|
54
|
+
command: "sh",
|
|
55
|
+
args: [
|
|
56
|
+
"-c",
|
|
57
|
+
'curl --fail --show-error --silent "$(gcloud run services describe launch-api --project anmho-infra-prod --region us-west1 --format=value(status.url))/healthz"',
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
43
62
|
test("uses auth token and grpcurl for Go ConnectRPC services", () => {
|
|
44
63
|
expect(buildDeploymentVerificationCommands({ apiHostname: "api.launch.anmho.com", framework: "connectrpc", runtime: "go" })).toContainEqual({
|
|
45
64
|
command: "sh",
|
|
46
65
|
args: [
|
|
47
66
|
"-c",
|
|
48
|
-
'TOKEN="$(bun ./scripts/cloudrun/cli.ts auth token)" && grpcurl -H "Authorization: Bearer $TOKEN" -d \'{"limit":1}\' -proto protos/waitlist/v1/waitlist.proto api.launch.anmho.com:443 waitlist.v1.WaitlistService/ListWaitlistEntries',
|
|
67
|
+
'TOKEN="$(bun ./scripts/cloudrun/cli.ts auth token)" && grpcurl -H "Authorization: Bearer $TOKEN" -d \'{"limit":1}\' -proto protos/waitlist/v1/waitlist.proto "api.launch.anmho.com:443" waitlist.v1.WaitlistService/ListWaitlistEntries',
|
|
49
68
|
],
|
|
50
69
|
});
|
|
51
70
|
});
|
package/src/post-scaffold.ts
CHANGED
|
@@ -55,23 +55,26 @@ function runWithRetries(command: PostScaffoldCommand, options: CommandOptions, a
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function buildDeploymentVerificationCommands(
|
|
58
|
-
config: Pick<ScaffoldConfig, "apiHostname" | "framework" | "runtime"> &
|
|
58
|
+
config: Pick<ScaffoldConfig, "apiHostname" | "framework" | "runtime"> &
|
|
59
|
+
Partial<Pick<ScaffoldConfig, "target" | "serviceName" | "gcpProject" | "region">>
|
|
59
60
|
): PostScaffoldCommand[] {
|
|
60
|
-
const origin =
|
|
61
|
+
const origin = verificationOrigin(config);
|
|
61
62
|
const tokenCommand = `TOKEN="$(bun ${serviceCliPath(config)} auth token)"`;
|
|
62
63
|
return [
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
shellVerificationCommand(`curl --fail --show-error --silent "${origin}/healthz"`),
|
|
65
|
+
shellVerificationCommand(`curl --fail --show-error --silent "${origin}/readyz"`),
|
|
65
66
|
protectedVerificationCommand(config, origin, tokenCommand),
|
|
66
67
|
];
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
function protectedVerificationCommand(
|
|
70
|
-
config: Pick<ScaffoldConfig, "apiHostname" | "framework" | "runtime"
|
|
71
|
+
config: Pick<ScaffoldConfig, "apiHostname" | "framework" | "runtime"> &
|
|
72
|
+
Partial<Pick<ScaffoldConfig, "target" | "serviceName" | "gcpProject" | "region">>,
|
|
71
73
|
origin: string,
|
|
72
74
|
tokenCommand: string
|
|
73
75
|
): PostScaffoldCommand {
|
|
74
76
|
if (config.framework === "connectrpc" && config.runtime === "go") {
|
|
77
|
+
const host = verificationHost(config);
|
|
75
78
|
return {
|
|
76
79
|
command: "sh",
|
|
77
80
|
args: [
|
|
@@ -82,7 +85,7 @@ function protectedVerificationCommand(
|
|
|
82
85
|
'-H "Authorization: Bearer $TOKEN"',
|
|
83
86
|
"-d '{\"limit\":1}'",
|
|
84
87
|
"-proto protos/waitlist/v1/waitlist.proto",
|
|
85
|
-
|
|
88
|
+
`"${host}:443"`,
|
|
86
89
|
"waitlist.v1.WaitlistService/ListWaitlistEntries",
|
|
87
90
|
].join(" "),
|
|
88
91
|
],
|
|
@@ -120,6 +123,28 @@ function protectedVerificationCommand(
|
|
|
120
123
|
};
|
|
121
124
|
}
|
|
122
125
|
|
|
126
|
+
function shellVerificationCommand(script: string): PostScaffoldCommand {
|
|
127
|
+
return { command: "sh", args: ["-c", script] };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function verificationOrigin(
|
|
131
|
+
config: Partial<Pick<ScaffoldConfig, "target" | "serviceName" | "gcpProject" | "region">> & Pick<ScaffoldConfig, "apiHostname">
|
|
132
|
+
) {
|
|
133
|
+
if (config.target !== "workers" && config.serviceName && config.gcpProject && config.region) {
|
|
134
|
+
return `$(gcloud run services describe ${config.serviceName} --project ${config.gcpProject} --region ${config.region} --format=value(status.url))`;
|
|
135
|
+
}
|
|
136
|
+
return `https://${config.apiHostname}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function verificationHost(
|
|
140
|
+
config: Partial<Pick<ScaffoldConfig, "target" | "serviceName" | "gcpProject" | "region">> & Pick<ScaffoldConfig, "apiHostname">
|
|
141
|
+
) {
|
|
142
|
+
if (config.target !== "workers" && config.serviceName && config.gcpProject && config.region) {
|
|
143
|
+
return `$(gcloud run services describe ${config.serviceName} --project ${config.gcpProject} --region ${config.region} --format=value(status.url) | sed 's#^https://##')`;
|
|
144
|
+
}
|
|
145
|
+
return config.apiHostname;
|
|
146
|
+
}
|
|
147
|
+
|
|
123
148
|
export function buildPostScaffoldCommands(
|
|
124
149
|
config: Pick<ScaffoldConfig, "framework"> & Partial<Pick<ScaffoldConfig, "target">>
|
|
125
150
|
): PostScaffoldCommand[] {
|