Skip to content

Commit baa0e11

Browse files
authored
turtle onboarding fixes (#6781)
* fixes for initializing turtles * fix up tests to be better * fix delete command * capture specific error status * revert test file * formatting is hard
1 parent 14a1ba0 commit baa0e11

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

src/commands/apphosting-backends-delete.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ const TABLE_HEAD = [
2020
"Updated Date",
2121
];
2222

23-
export const command = new Command("apphosting:backends:delete")
24-
.description("Delete a backend from a Firebase project")
23+
export const command = new Command("apphosting:backends:delete <backend>")
24+
.description("delete a backend from a Firebase project")
2525
.option("-l, --location <location>", "App Backend location", "")
26-
.option("-s, --backend <backend>", "Backend Id", "")
2726
.withForce()
2827
.before(apphosting.ensureApiEnabled)
29-
.action(async (options: Options) => {
28+
.action(async (backendId: string, options: Options) => {
3029
const projectId = needProjectId(options);
3130
let location = options.location as string;
32-
const backendId = options.backend as string;
3331
if (!backendId) {
3432
throw new FirebaseError("Backend id can't be empty.");
3533
}

src/gcp/apphosting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ export async function createRollout(
399399
backendId: string,
400400
rolloutId: string,
401401
rollout: DeepOmit<Rollout, RolloutOutputOnlyFields | "name">,
402+
validateOnly = false,
402403
): Promise<Operation> {
403404
const res = await client.post<DeepOmit<Rollout, RolloutOutputOnlyFields | "name">, Operation>(
404405
`projects/${projectId}/locations/${location}/backends/${backendId}/rollouts`,
@@ -409,7 +410,7 @@ export async function createRollout(
409410
...deploymentTool.labels(),
410411
},
411412
},
412-
{ queryParams: { rolloutId } },
413+
{ queryParams: { rolloutId, validateOnly: validateOnly ? "true" : "false" } },
413414
);
414415
return res.body;
415416
}

src/init/features/apphosting/index.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as clc from "colorette";
2+
23
import * as repo from "./repo";
34
import * as poller from "../../../operation-poller";
45
import * as apphosting from "../../../gcp/apphosting";
@@ -204,9 +205,44 @@ export async function orchestrateRollout(
204205
const buildId = await apphosting.getNextRolloutId(projectId, location, backendId, 1);
205206
const buildOp = await apphosting.createBuild(projectId, location, backendId, buildId, buildInput);
206207

207-
const rolloutOp = await apphosting.createRollout(projectId, location, backendId, buildId, {
208+
const rolloutBody = {
208209
build: `projects/${projectId}/locations/${location}/backends/${backendId}/builds/${buildId}`,
209-
});
210+
};
211+
212+
let tries = 0;
213+
let done = false;
214+
while (!done) {
215+
tries++;
216+
try {
217+
const validateOnly = true;
218+
await apphosting.createRollout(
219+
projectId,
220+
location,
221+
backendId,
222+
buildId,
223+
rolloutBody,
224+
validateOnly,
225+
);
226+
done = true;
227+
} catch (err: unknown) {
228+
if (err instanceof FirebaseError && err.status === 400) {
229+
if (tries >= 5) {
230+
throw err;
231+
}
232+
await new Promise((resolve) => setTimeout(resolve, 1000));
233+
} else {
234+
throw err;
235+
}
236+
}
237+
}
238+
239+
const rolloutOp = await apphosting.createRollout(
240+
projectId,
241+
location,
242+
backendId,
243+
buildId,
244+
rolloutBody,
245+
);
210246

211247
const rolloutPoll = poller.pollOperation<Rollout>({
212248
...apphostingPollerOptions,

0 commit comments

Comments
 (0)