|
| 1 | +import * as apphosting from "../gcp/apphosting"; |
| 2 | +import { logger } from "../logger"; |
| 3 | +import { Command } from "../command"; |
| 4 | +import { Options } from "../options"; |
| 5 | +import { generateId } from "../utils"; |
| 6 | +import { needProjectId } from "../projectUtils"; |
| 7 | + |
| 8 | +export const command = new Command("apphosting:builds:create <backendId>") |
| 9 | + .description("Create a build for an App Hosting backend") |
| 10 | + .option("-l, --location <location>", "Specify the region of the backend", "us-central1") |
| 11 | + .option("-i, --id <buildId>", "Id of the build. If not present, autogenerate a random id", "") |
| 12 | + .option("-b, --branch <branch>", "Repository branch to deploy. Defaults to 'main'", "main") |
| 13 | + .before(apphosting.ensureApiEnabled) |
| 14 | + .action(async (backendId: string, options: Options) => { |
| 15 | + const projectId = needProjectId(options); |
| 16 | + const location = options.location as string; |
| 17 | + const buildId = (options.buildId as string) || generateId(); |
| 18 | + const branch = options.branch as string; |
| 19 | + |
| 20 | + const op = await apphosting.createBuild(projectId, location, backendId, buildId, { |
| 21 | + source: { |
| 22 | + codebase: { |
| 23 | + branch: "main", |
| 24 | + }, |
| 25 | + }, |
| 26 | + }); |
| 27 | + |
| 28 | + logger.info(`Started a build for backend ${backendId} on branch ${branch}.`); |
| 29 | + logger.info("Check status by running:"); |
| 30 | + logger.info(`\tfirebase apphosting:builds:get ${backendId} ${buildId} --location ${location}`); |
| 31 | + return op; |
| 32 | + }); |
0 commit comments