-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as apphosting from "../gcp/apphosting"; | ||
import { logger } from "../logger"; | ||
import { Command } from "../command"; | ||
import { Options } from "../options"; | ||
import { needProjectId } from "../projectUtils"; | ||
|
||
function generateId(n = 6): string { | ||
const letters = "abcdefghijklmnopqrstuvwxyz"; | ||
const allChars = "01234567890-abcdefghijklmnopqrstuvwxyz"; | ||
let id = letters[Math.floor(Math.random() * letters.length)]; | ||
for (let i = 1; i < n; i++) { | ||
const idx = Math.floor(Math.random() * allChars.length); | ||
id += allChars[idx]; | ||
} | ||
return id; | ||
} | ||
|
||
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. If not present, autogenerate a random id", "") | ||
.option("-b, --branch <branch>", "Repository branch to deploy. Defaults to 'main'", "main") | ||
.before(apphosting.ensureApiEnabled) | ||
Check failure on line 23 in src/commands/apphosting-builds-create.ts
|
||
.action(async (backendId: string, options: Options) => { | ||
const projectId = needProjectId(options); | ||
const location = options.location as string; | ||
const buildId = (options.buildId as string) || generateId(); | ||
const branch = options.branch as string; | ||
|
||
const op = await apphosting.createBuild(projectId, location, backendId, buildId, { | ||
source: { | ||
codebase: { | ||
branch: "main", | ||
}, | ||
}, | ||
}); | ||
|
||
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; | ||
}); |
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("Create a build for an App Hosting backend") | ||
.option("-l, --location <location>", "Specify the region of the backend", "us-central1") | ||
.before(apphosting.ensureApiEnabled) | ||
Check failure on line 10 in src/commands/apphosting-builds-get.ts
|
||
.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; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as apphosting from "../gcp/apphosting"; | ||
import { logger } from "../logger"; | ||
import { Command } from "../command"; | ||
import { Options } from "../options"; | ||
import { needProjectId } from "../projectUtils"; | ||
|
||
function generateId(n = 6): string { | ||
const letters = "abcdefghijklmnopqrstuvwxyz"; | ||
const allChars = "01234567890-abcdefghijklmnopqrstuvwxyz"; | ||
let id = letters[Math.floor(Math.random() * letters.length)]; | ||
for (let i = 1; i < n; i++) { | ||
const idx = Math.floor(Math.random() * allChars.length); | ||
id += allChars[idx]; | ||
} | ||
return id; | ||
} | ||
|
||
export const command = new Command("apphosting:rollouts:create <backendId> <buildId>") | ||
.description("Create 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. If not present, autogenerate a random id", "") | ||
.before(apphosting.ensureApiEnabled) | ||
Check failure on line 22 in src/commands/apphosting-rollouts-create.ts
|
||
.action(async (backendId: string, buildId: string, options: Options) => { | ||
const projectId = needProjectId(options); | ||
const location = options.location as string; | ||
const rolloutId = (options.buildId as string) || generateId(); | ||
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; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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>", | ||
"Rgion of the rollouts. Defaults to listing rollouts from all regions", | ||
"-" | ||
) | ||
.before(apphosting.ensureApiEnabled) | ||
Check failure on line 14 in src/commands/apphosting-rollouts-list.ts
|
||
.action(async (backendId: string, options: Options) => { | ||
const projectId = needProjectId(options); | ||
const location = options.location as string; | ||
const rollouts = await apphosting.listRollouts(projectId, location, backendId); | ||
logger.info(JSON.stringify(rollouts, null, 2)); | ||
return rollouts; | ||
}); |