Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --location from apphosting:builds:get #8245

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/commands/apphosting-backends-create.ts
Original file line number Diff line number Diff line change
@@ -6,14 +6,15 @@ import { doSetup } from "../apphosting/backend";
import { ensureApiEnabled } from "../gcp/apphosting";
import { APPHOSTING_TOS_ID } from "../gcp/firedata";
import { requireTosAcceptance } from "../requireTosAcceptance";
import { logWarning } from "../utils";

export const command = new Command("apphosting:backends:create")
.description("create a Firebase App Hosting backend")
.option(
"-a, --app <webAppId>",
"specify an existing Firebase web app's ID to associate your App Hosting backend with",
)
.option("-l, --location <location>", "specify the location of the backend", "")
.option("-l, --location <location>", "specify the location of the backend")
.option(
"-s, --service-account <serviceAccount>",
"specify the service account used to run the server",
@@ -23,9 +24,15 @@ export const command = new Command("apphosting:backends:create")
.before(requireInteractive)
.before(requireTosAcceptance(APPHOSTING_TOS_ID))
.action(async (options: Options) => {
if (options.location !== undefined) {
logWarning(
"--location is being removed in the next major release. " +
"The CLI will prompt for a Primary Region where appropriate.",
);
}
const projectId = needProjectId(options);
const webAppId = options.app;
const location = options.location;
const location = options.location as string;
const serviceAccount = options.serviceAccount;

await doSetup(
7 changes: 5 additions & 2 deletions src/commands/apphosting-backends-delete.ts
Original file line number Diff line number Diff line change
@@ -15,12 +15,15 @@ import * as ora from "ora";

export const command = new Command("apphosting:backends:delete <backend>")
.description("delete a Firebase App Hosting backend")
.option("-l, --location <location>", "specify the location of the backend", "-")
.option("-l, --location <location>", "specify the location of the backend")
.withForce()
.before(apphosting.ensureApiEnabled)
.action(async (backendId: string, options: Options) => {
const projectId = needProjectId(options);
let location = options.location as string;
if (options.location !== undefined) {
utils.logWarning("--location is being removed in the next major release.");
}
let location = (options.location as string) ?? "-";
let backend: apphosting.Backend;
if (location === "-" || location === "") {
backend = await getBackendForAmbiguousLocation(
7 changes: 5 additions & 2 deletions src/commands/apphosting-backends-get.ts
Original file line number Diff line number Diff line change
@@ -8,11 +8,14 @@ import { printBackendsTable } from "./apphosting-backends-list";

export const command = new Command("apphosting:backends:get <backend>")
.description("print info about a Firebase App Hosting backend")
.option("-l, --location <location>", "backend location", "-")
.option("-l, --location <location>", "backend location")
.before(apphosting.ensureApiEnabled)
.action(async (backend: string, options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
if (options.location !== undefined) {
logWarning("--location is being removed in the next major release.");
}
const location = (options.location as string) ?? "-";

let backendsList: apphosting.Backend[] = [];
try {
10 changes: 7 additions & 3 deletions src/commands/apphosting-backends-list.ts
Original file line number Diff line number Diff line change
@@ -6,16 +6,20 @@ import { needProjectId } from "../projectUtils";
import { Options } from "../options";
import * as apphosting from "../gcp/apphosting";
import * as Table from "cli-table3";
import { logWarning } from "../utils";

const TABLE_HEAD = ["Backend", "Repository", "URL", "Location", "Updated Date"];
const TABLE_HEAD = ["Backend", "Repository", "URL", "Primary Region", "Updated Date"];

export const command = new Command("apphosting:backends:list")
.description("list Firebase App Hosting backends")
.option("-l, --location <location>", "list backends in the specified location", "-")
.option("-l, --location <location>", "list backends in the specified location")
.before(apphosting.ensureApiEnabled)
.action(async (options: Options) => {
if (options.location !== undefined) {
logWarning("--location is being removed in the next major release.");
}
const projectId = needProjectId(options);
const location = options.location as string;
const location = (options.location as string) ?? "-";
let backendRes: apphosting.ListBackendsResponse;
try {
backendRes = await apphosting.listBackends(projectId, location);
8 changes: 6 additions & 2 deletions src/commands/apphosting-builds-create.ts
Original file line number Diff line number Diff line change
@@ -3,16 +3,20 @@ import { logger } from "../logger";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { logWarning } from "../utils";

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("-l, --location <location>", "specify the region of the backend")
.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;
if (options.location !== undefined) {
logWarning("--location is being removed in the next major release.");
}
const location = (options.location as string) ?? "us-central1";
const buildId =
(options.buildId as string) ||
(await apphosting.getNextRolloutId(projectId, location, backendId));
31 changes: 26 additions & 5 deletions src/commands/apphosting-builds-get.ts
Original file line number Diff line number Diff line change
@@ -3,15 +3,36 @@
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { logWarning } from "../utils";
import { FirebaseError } from "../error";

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;
const builds = await apphosting.listBuilds(projectId, /* location: */ "-", /* backendId */ "-");
const matchingBuilds = builds.builds.filter((b) => {
const parsedBuild = apphosting.parseBuildName(b.name);
if (parsedBuild.backendId === backendId && parsedBuild.buildId === buildId) {
return true;
}
});
if (matchingBuilds.length > 0) {
if (matchingBuilds.length > 1) {
logWarning(
`Detected multiple backends with same backendId (${backendId}) and buildId (${buildId}) within the same global location. ` +
"Please delete and recreate any backends that share an ID with another. Use `apphosting:backends:list` to see all backends.",
);
}
logger.info(JSON.stringify(matchingBuilds[0], null, 2));
return matchingBuilds[0];
}
if (builds.unreachable && builds.unreachable.length !== 0) {
logWarning(
`Backends with the following primary regions are unreachable: ${builds.unreachable}.\n` +

Check warning on line 33 in src/commands/apphosting-builds-get.ts

GitHub Actions / lint (20)

Invalid type "string[]" of template literal expression
"If your backend is in one of these regions, please try again later.",
);
}
throw new FirebaseError(`No build ${buildId} found for any backend ${backendId}.`);
});
8 changes: 6 additions & 2 deletions src/commands/apphosting-rollouts-create.ts
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@ import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { FirebaseError } from "../error";
import { createRollout } from "../apphosting/rollout";
import { logWarning } from "../utils";

export const command = new Command("apphosting:rollouts:create <backendId>")
.description("create a rollout using a build for an App Hosting backend")
.option("-l, --location <location>", "specify the region of the backend", "-")
.option("-l, --location <location>", "specify the region of the backend")
.option(
"-b, --git-branch <gitBranch>",
"repository branch to deploy (mutually exclusive with -g)",
@@ -17,7 +18,10 @@ export const command = new Command("apphosting:rollouts:create <backendId>")
.before(apphosting.ensureApiEnabled)
.action(async (backendId: string, options: Options) => {
const projectId = needProjectId(options);
const location = options.location as string;
if (options.location !== undefined) {
logWarning("--location is being removed in the next major release.");
}
const location = (options.location as string) ?? "-";

const branch = options.gitBranch as string | undefined;
const commit = options.gitCommit as string | undefined;
7 changes: 5 additions & 2 deletions src/commands/apphosting-rollouts-list.ts
Original file line number Diff line number Diff line change
@@ -3,18 +3,21 @@ import { logger } from "../logger";
import { Command } from "../command";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { logWarning } from "../utils";

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) => {
if (options.location !== undefined) {
logWarning("--location is being removed in the next major release.");
}
const projectId = needProjectId(options);
const location = options.location as string;
const location = (options.location as string) ?? "-";
const rollouts = await apphosting.listRollouts(projectId, location, backendId);
if (rollouts.unreachable) {
logger.error(
14 changes: 14 additions & 0 deletions src/gcp/apphosting.ts
Original file line number Diff line number Diff line change
@@ -250,7 +250,7 @@
done: boolean;
// oneof result
error?: Status;
response?: any;

Check warning on line 253 in src/gcp/apphosting.ts

GitHub Actions / lint (20)

Unexpected any. Specify a different type
// end oneof result
}

@@ -357,6 +357,20 @@
return res.body;
}

/**
* Parse a Build name
*/
export function parseBuildName(buildName: string): {
projectName: string;
location: string;
backendId: string;
buildId: string;
} {
// sample value: "projects/<project-name>/locations/us-central1/backends/<backend-id>/builds/<build-id>"
const [, projectName, , location, , backendId, , buildId] = buildName.split("/");
return { projectName, location, backendId, buildId };
}

/**
* Get a Build by Id
*/
@@ -532,14 +546,14 @@
/**
* Ensure that the App Hosting API is enabled on the project.
*/
export async function ensureApiEnabled(options: any): Promise<void> {

Check warning on line 549 in src/gcp/apphosting.ts

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const projectId = needProjectId(options);

Check warning on line 550 in src/gcp/apphosting.ts

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `{ projectId?: string | undefined; project?: string | undefined; rc?: RC | undefined; }`
return await ensure(projectId, apphostingOrigin(), "app hosting", true);
}

/**
* Generates the next build ID to fit with the naming scheme of the backend API.
* @param counter Overrides the counter to use, avoiding an API call.

Check warning on line 556 in src/gcp/apphosting.ts

GitHub Actions / lint (20)

Expected @param names to be "projectId, location, backendId, counter". Got "counter"
*/
export async function getNextRolloutId(
projectId: string,
Loading