Skip to content
Draft
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
31 changes: 15 additions & 16 deletions npm-shrinkwrap.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
]
},
"dependencies": {
"@apphosting/build": "^0.1.6",
"@apphosting/common": "^0.0.8",
"@apphosting/build": "^0.1.7",
"@electric-sql/pglite": "^0.3.3",
"@electric-sql/pglite-tools": "^0.2.8",
"@google-cloud/cloud-sql-connector": "^1.3.3",
Expand Down
3 changes: 2 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const appDistributionOrigin = () =>
"https://firebaseappdistribution.googleapis.com",
);
export const apphostingOrigin = () =>
utils.envOverride("FIREBASE_APPHOSTING_URL", "https://firebaseapphosting.googleapis.com");
utils.envOverride("FIREBASE_APPHOSTING_URL", "https://staging-firebaseapphosting.sandbox.googleapis.com");
// firebaseapphosting.googleapis.com");
export const apphostingP4SADomain = () =>
utils.envOverride(
"FIREBASE_APPHOSTING_P4SA_DOMAIN",
Expand Down
1 change: 1 addition & 0 deletions src/apphosting/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ export async function createBackend(
const defaultServiceAccount = defaultComputeServiceAccountEmail(projectId);
const backendReqBody: Omit<Backend, BackendOutputOnlyFields> = {
servingLocality: "GLOBAL_ACCESS",
runtime: {value: "nodejs22"},
codebase: repository
? {
repository: `${repository.name}`,
Expand Down
7 changes: 4 additions & 3 deletions src/deploy/apphosting/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Options } from "../../options";
import { needProjectId } from "../../projectUtils";
import { logLabeledBullet } from "../../utils";
import { Context } from "./args";
import { createArchive } from "./util";
import { createArchive, createTarArchive } from "./util";

/**
* Zips and uploads App Hosting source code to Google Cloud Storage in preparation for
Expand Down Expand Up @@ -71,9 +71,9 @@ export default async function (context: Context, options: Options): Promise<void
throw new FirebaseError(`No local build dir found for ${cfg.backendId}`);
}
}
const zippedSourcePath = await createArchive(cfg, rootDir, builtAppDir);
const zippedSourcePath = await createTarArchive(cfg, rootDir, builtAppDir);
logLabeledBullet(
"apphosting",
"apphosting....",
`Zipped ${cfg.localBuild ? "built app" : "source"} for backend ${cfg.backendId}`,
);

Expand All @@ -94,6 +94,7 @@ export default async function (context: Context, options: Options): Promise<void
stream: fs.createReadStream(zippedSourcePath),
},
bucketName,
gcs.ContentType.TAR
);
logLabeledBullet("apphosting", `Uploaded at gs://${bucket}/${object}`);
context.backendStorageUris[cfg.backendId] =
Expand Down
11 changes: 5 additions & 6 deletions src/deploy/apphosting/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ export default async function (context: Context, options: Options): Promise<void

const localBuildBackends = backendIds.filter((id) => context.backendLocalBuilds[id]);
if (localBuildBackends.length > 0) {
logLabeledWarning(
"apphosting",
`Skipping backend(s) ${localBuildBackends.join(", ")}. Local Builds are not supported yet.`,
);
backendIds = backendIds.filter((id) => !localBuildBackends.includes(id));
console.log(localBuildBackends);
console.log(context.backendStorageUris);
console.log(context.backendLocalBuilds);
}

if (backendIds.length === 0) {
Expand All @@ -46,16 +44,17 @@ export default async function (context: Context, options: Options): Promise<void
const rollouts = backendIds.map((backendId) =>
// TODO(9114): Add run_command
// TODO(914): Set the buildConfig.
// TODO(914): Set locallyBuiltSource.
orchestrateRollout({
projectId,
backendId,
location: context.backendLocations[backendId],
buildInput: {
config: context.backendLocalBuilds[backendId].buildConfig,
source: {
archive: {
userStorageUri: context.backendStorageUris[backendId],
rootDirectory: context.backendConfigs[backendId].rootDir,
locallyBuiltSource: true, // generalize
},
},
},
Expand Down
50 changes: 50 additions & 0 deletions src/deploy/apphosting/util.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
import * as archiver from "archiver";
import * as fs from "fs";
import * as path from "path";
import * as tar from "tar";

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (24)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (20)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / agent_evals_build (22)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (20)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / agent_evals_build (22)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (24)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / vscode_unit (22)

Cannot find module 'tar' or its corresponding type declarations.

Check failure on line 4 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / check-json-schema (20)

Cannot find module 'tar' or its corresponding type declarations.
import * as tmp from "tmp";
import { FirebaseError } from "../../error";
import { AppHostingSingle } from "../../firebaseConfig";
import * as fsAsync from "../../fsAsync";

export async function createTarArchive(
config: AppHostingSingle,
rootDir: string,
targetSubDir?: string,
): Promise<string> {
const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".tar.gz" }).name;

const targetDir = targetSubDir ? path.join(rootDir, targetSubDir) : rootDir;
// We must ignore firebase-debug.log or weird things happen if you're in the public dir when you deploy.
// const ignore = config.ignore || [".git"];
const ignore = ["firebase-debug.log", "firebase-debug.*.log", ".git"];
//const gitIgnorePatterns = parseGitIgnorePatterns(targetDir);
//ignore.push(...gitIgnorePatterns);
const rdrFiles = await fsAsync.readdirRecursive({
path: targetDir,
ignore: ignore,
isGitIgnore: true,
});
const allFiles: string[] = rdrFiles.map((rdrf) => path.relative(rootDir, rdrf.name));
console.log(allFiles);


// `tar` returns a `TypeError` if `allFiles` is empty. Let's check a feww things.
try {
fs.statSync(rootDir);
} catch (err: any) {
if (err.code === "ENOENT") {
throw new FirebaseError(`Could not read directory "${rootDir}"`);
}
throw err;
}
if (!allFiles.length) {
throw new FirebaseError(
`Cannot create a tar archive with 0 files from directory "${rootDir}"`,
);
}

await tar.create(
{
gzip: true,
file: tmpFile,
cwd: rootDir,
portable: true,
},
allFiles,
);
return tmpFile
}

/**
* Locates the source code for a backend and creates an archive to eventually upload to GCS.
* Based heavily on functions upload logic in src/deploy/functions/prepareFunctionsUpload.ts.
Expand Down
7 changes: 6 additions & 1 deletion src/gcp/apphosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as deploymentTool from "../deploymentTool";
import { FirebaseError } from "../error";
import { DeepOmit, RecursiveKeyOf, assertImplements } from "../metaprogramming";

export const API_VERSION = "v1beta";
export const API_VERSION = "v1alpha";

export const client = new Client({
urlPrefix: apphostingOrigin(),
Expand All @@ -22,6 +22,10 @@ interface Codebase {
rootDirectory: string;
}

interface Runtime {
value: string;
}

/**
* Specifies how Backend's data is replicated and served.
* GLOBAL_ACCESS: Stores and serves content from multiple points-of-presence (POP)
Expand All @@ -35,6 +39,7 @@ export interface Backend {
name: string;
mode?: string;
codebase?: Codebase;
runtime?: Runtime;
servingLocality: ServingLocality;
labels: Record<string, string>;
createTime: string;
Expand Down
Loading