Skip to content

Commit

Permalink
Revert "Clean up App Hosting commands used for testing purposes" and …
Browse files Browse the repository at this point in the history
…gate them behind `internaltesting` flag (#7005)

* Revert "Clean up apphosting commands used for testing purposes (#6978)"

This reverts commit 8a6e608.

* move apphosting builds and rollouts commands behind internaltesting experiment

---------

Co-authored-by: Mathusan Selvarajah <mathusan@google.com>
  • Loading branch information
mathu97 and mathu97 authored Apr 16, 2024
1 parent e3b5eaa commit c7b24b1
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/commands/apphosting-builds-create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as apphosting from "../gcp/apphosting";
import { logger } from "../logger";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";

export const command = new Command("apphosting:builds:create <backendId>")
.description("create a build for an App Hosting backend")
.option("-l, --location <location>", "specify the region of the backend", "us-central1")
.option("-i, --id <buildId>", "id of the build (defaults to autogenerating a random id)", "")
.option("-b, --branch <branch>", "repository branch to deploy (defaults to 'main')", "main")
.before(apphosting.ensureApiEnabled)
.action(async (backendId: string, options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const buildId =
(options.buildId as string) ||
(await apphosting.getNextRolloutId(projectId, location, backendId));
const branch = (options.branch as string | undefined) ?? "main";

const op = await apphosting.createBuild(projectId, location, backendId, buildId, {
source: {
codebase: {
branch,
},
},
});

logger.info(`Started a build for backend ${backendId} on branch ${branch}.`);
logger.info("Check status by running:");
logger.info(`\tfirebase apphosting:builds:get ${backendId} ${buildId} --location ${location}`);
return op;
});
17 changes: 17 additions & 0 deletions src/commands/apphosting-builds-get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as apphosting from "../gcp/apphosting";
import { logger } from "../logger";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";

export const command = new Command("apphosting:builds:get <backendId> <buildId>")
.description("get a build for an App Hosting backend")
.option("-l, --location <location>", "specify the region of the backend", "us-central1")
.before(apphosting.ensureApiEnabled)
.action(async (backendId: string, buildId: string, options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const build = await apphosting.getBuild(projectId, location, backendId, buildId);
logger.info(JSON.stringify(build, null, 2));
return build;
});
27 changes: 27 additions & 0 deletions src/commands/apphosting-rollouts-create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as apphosting from "../gcp/apphosting";
import { logger } from "../logger";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";

export const command = new Command("apphosting:rollouts:create <backendId> <buildId>")
.description("create a rollout using a build for an App Hosting backend")
.option("-l, --location <location>", "specify the region of the backend", "us-central1")
.option("-i, --id <rolloutId>", "id of the rollout (defaults to autogenerating a random id)", "")
.before(apphosting.ensureApiEnabled)
.action(async (backendId: string, buildId: string, options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
// TODO: Should we just reuse the buildId?
const rolloutId =
(options.buildId as string) ||
(await apphosting.getNextRolloutId(projectId, location, backendId));
const build = `projects/${projectId}/backends/${backendId}/builds/${buildId}`;
const op = await apphosting.createRollout(projectId, location, backendId, rolloutId, {
build,
});
logger.info(`Started a rollout for backend ${backendId} with build ${buildId}.`);
logger.info("Check status by running:");
logger.info(`\tfirebase apphosting:rollouts:list --location ${location}`);
return op;
});
26 changes: 26 additions & 0 deletions src/commands/apphosting-rollouts-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as apphosting from "../gcp/apphosting";
import { logger } from "../logger";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";

export const command = new Command("apphosting:rollouts:list <backendId>")
.description("list rollouts of an App Hosting backend")
.option(
"-l, --location <location>",
"region of the rollouts (defaults to listing rollouts from all regions)",
"-",
)
.before(apphosting.ensureApiEnabled)
.action(async (backendId: string, options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
const rollouts = await apphosting.listRollouts(projectId, location, backendId);
if (rollouts.unreachable) {
logger.error(
`WARNING: the following locations were unreachable: ${rollouts.unreachable.join(", ")}`,
);
}
logger.info(JSON.stringify(rollouts.rollouts, null, 2));
return rollouts;
});
8 changes: 8 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ export function load(client: any): any {
client.apphosting.secrets.grantaccess = loadCommand("apphosting-secrets-grantaccess");
client.apphosting.secrets.describe = loadCommand("apphosting-secrets-describe");
client.apphosting.secrets.access = loadCommand("apphosting-secrets-access");
if (experiments.isEnabled("internaltesting")) {
client.apphosting.builds = {};
client.apphosting.builds.get = loadCommand("apphosting-builds-get");
client.apphosting.builds.create = loadCommand("apphosting-builds-create");
client.apphosting.rollouts = {};
client.apphosting.rollouts.create = loadCommand("apphosting-rollouts-create");
client.apphosting.rollouts.list = loadCommand("apphosting-rollouts-list");
}
}
client.login = loadCommand("login");
client.login.add = loadCommand("login-add");
Expand Down

0 comments on commit c7b24b1

Please sign in to comment.