Skip to content
Closed
Show file tree
Hide file tree
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
38 changes: 38 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
]
},
"dependencies": {
"@apphosting/build": "*",
"@electric-sql/pglite": "^0.3.3",
"@electric-sql/pglite-tools": "^0.2.8",
"@google-cloud/cloud-sql-connector": "^1.3.3",
Expand Down
5 changes: 5 additions & 0 deletions src/apphosting/localbuilds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { adapterBuild } from "@apphosting/build";

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (22)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (20)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (22)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (20)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (22)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (20)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / unit (20)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (22)

Cannot find module '@apphosting/build' or its corresponding type declarations.

Check failure on line 1 in src/apphosting/localbuilds.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (20)

Cannot find module '@apphosting/build' or its corresponding type declarations.

export async function localBuild(projectRoot: string, framework: string): Promise<string> {
return await adapterBuild(projectRoot, framework);
}
19 changes: 14 additions & 5 deletions src/deploy/apphosting/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ export default async function (context: Context, options: Options): Promise<void
}

for (const cfg of context.backendConfigs.values()) {
const projectSourcePath = options.projectRoot ? options.projectRoot : process.cwd();
const zippedSourcePath = await createArchive(cfg, projectSourcePath);
let rootDir = options.projectRoot ?? process.cwd();
if (cfg.localBuild) {
rootDir = context.backendLocalBuilds[cfg.backendId].buildDir;
if (!rootDir) {
throw new FirebaseError(`No local build dir found for ${cfg.backendId}`);
}
}
const zippedSourcePath = await createArchive(cfg, rootDir);
logLabeledBullet("apphosting",`Zipped ${rootDir}`);

const backendLocation = context.backendLocations.get(cfg.backendId);
if (!backendLocation) {
throw new FirebaseError(
Expand All @@ -83,19 +91,20 @@ export default async function (context: Context, options: Options): Promise<void
}
logLabeledBullet(
"apphosting",
`Uploading source code at ${projectSourcePath} for backend ${cfg.backendId}...`,
`Uploading ${rootDir} for backend ${cfg.backendId}...`,
);
const gcsBucketName = `firebaseapphosting-${cfg.localBuild ? "build" : "sources"}-${options.projectNumber}-${backendLocation.toLowerCase()}`;
const { bucket, object } = await gcs.uploadObject(
{
file: zippedSourcePath,
stream: fs.createReadStream(zippedSourcePath),
},
`firebaseapphosting-sources-${options.projectNumber}-${backendLocation.toLowerCase()}`,
gcsBucketName,
);
logLabeledBullet("apphosting", `Source code uploaded at gs://${bucket}/${object}`);
context.backendStorageUris.set(
cfg.backendId,
`gs://firebaseapphosting-sources-${options.projectNumber}-${backendLocation.toLowerCase()}/${path.basename(zippedSourcePath)}`,
`gs://${gcsBucketName}/${path.basename(zippedSourcePath)}`,
);
}
}
18 changes: 18 additions & 0 deletions src/deploy/apphosting/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { Options } from "../../options";
import { needProjectId } from "../../projectUtils";
import { checkbox, confirm } from "../../prompt";
import { logLabeledBullet, logLabeledWarning } from "../../utils";
import { localBuild } from "../../apphosting/localbuilds";
import { Context } from "./args";
import { FirebaseError } from "../../error";

/**
* Prepare backend targets to deploy from source. Checks that all required APIs are enabled,
Expand All @@ -26,6 +28,7 @@ export default async function (context: Context, options: Options): Promise<void
context.backendConfigs = new Map<string, AppHostingSingle>();
context.backendLocations = new Map<string, string>();
context.backendStorageUris = new Map<string, string>();
context.backendLocalBuilds = {};

const configs = getBackendConfigs(options);
const { backends } = await listBackends(projectId, "-");
Expand Down Expand Up @@ -144,6 +147,21 @@ export default async function (context: Context, options: Options): Promise<void
`Skipping deployment of backend(s) ${skippedBackends.map((cfg) => cfg.backendId).join(", ")}.`,
);
}

for ( const [backendId, config] of context.backendConfigs ) {
if (!config.localBuild) {
continue;
}
logLabeledBullet("apphosting", `Starting local build for backend ${config.backendId}`);
let builtAppDir;
try {
builtAppDir = await localBuild(options.projectRoot || "./", "nextjs");
} catch (e) {
throw new FirebaseError(`Local Build for backend ${config.backendId} failed: ${e}`);
}
context.backendLocalBuilds[config.backendId].buildDir = builtAppDir;
}

return;
}

Expand Down
1 change: 1 addition & 0 deletions src/deploy/apphosting/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default async function (context: Context, options: Options): Promise<void
continue;
}
backendIds.push(backendId);
// TODO(9114): Add run_command
let buildConfig;
if (config.localBuild) {
buildConfig = context.backendLocalBuilds[backendId].buildConfig;
Expand Down
Loading