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 @@ -103,8 +103,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
1 change: 1 addition & 0 deletions src/apphosting/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// SSL.
const maybeNodeError = err as { cause: { code: string }; code: string };
if (
/HANDSHAKE_FAILURE/.test(maybeNodeError?.cause?.code) ||

Check warning on line 52 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Use `String#includes()` method with a string instead
"EPROTO" === maybeNodeError?.code
) {
return false;
Expand Down Expand Up @@ -315,7 +315,7 @@
* Prompts the user for a backend id and verifies that it doesn't match a pre-existing backend.
*/
export async function promptNewBackendId(projectId: string, location: string): Promise<string> {
while (true) {

Check warning on line 318 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected constant condition
const backendId = await input({
default: "my-web-app",
message: "Provide a name for your backend [1-30 characters]",
Expand Down Expand Up @@ -356,6 +356,7 @@
const defaultServiceAccount = defaultComputeServiceAccountEmail(projectId);
const backendReqBody: Omit<Backend, BackendOutputOnlyFields> = {
servingLocality: "GLOBAL_ACCESS",
runtime: {value: "nodejs22"},

Check failure on line 359 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `value:·"nodejs22"` with `·value:·"nodejs22"·`

Check failure on line 359 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Replace `value:·"nodejs22"` with `·value:·"nodejs22"·`

Check failure on line 359 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `value:·"nodejs22"` with `·value:·"nodejs22"·`
codebase: repository
? {
repository: `${repository.name}`,
Expand Down Expand Up @@ -624,7 +625,7 @@
message: locationDisambugationPrompt,
choices: [...backendsByLocation.keys()],
});
return backendsByLocation.get(location)!;

Check warning on line 628 in src/apphosting/backend.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
}

/**
Expand Down
6 changes: 3 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 { needProjectId } from "../../projectUtils";
import { logLabeledBullet } from "../../utils";
import { Context } from "./args";
import { createArchive } from "./util";
import { createArchive, createTarArchive } from "./util";

Check failure on line 10 in src/deploy/apphosting/deploy.ts

View workflow job for this annotation

GitHub Actions / unit (22)

'createArchive' is defined but never used

Check failure on line 10 in src/deploy/apphosting/deploy.ts

View workflow job for this annotation

GitHub Actions / unit (24)

'createArchive' is defined but never used

Check failure on line 10 in src/deploy/apphosting/deploy.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'createArchive' is defined but never used

/**
* Zips and uploads App Hosting source code to Google Cloud Storage in preparation for
Expand All @@ -33,7 +33,7 @@
`Failed to find config for backend ${backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`,
);
}
const baseName = `firebaseapphosting-sources-${options.projectNumber}-${loc.toLowerCase()}`;

Check warning on line 36 in src/deploy/apphosting/deploy.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string | undefined" of template literal expression
const resolvedName = await gcs.upsertBucket({
product: "apphosting",
createMessage: `Creating Cloud Storage bucket in ${loc} to store App Hosting source code uploads at ${baseName}...`,
Expand Down Expand Up @@ -71,9 +71,9 @@
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 @@ -87,7 +87,7 @@
"apphosting",
`Uploading ${cfg.localBuild ? "built app" : "source"} for backend ${cfg.backendId}...`,
);
const bucketName = bucketsPerLocation[backendLocation]!;

Check warning on line 90 in src/deploy/apphosting/deploy.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
const { bucket, object } = await gcs.uploadObject(
{
file: zippedSourcePath,
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 @@

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 @@
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,

Check failure on line 52 in src/deploy/apphosting/release.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `↹` with `········`

Check failure on line 52 in src/deploy/apphosting/release.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Replace `↹` with `········`

Check failure on line 52 in src/deploy/apphosting/release.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `↹` with `········`
source: {
archive: {
userStorageUri: context.backendStorageUris[backendId],
rootDirectory: context.backendConfigs[backendId].rootDir,
locallyBuiltSource: true, // generalize

Check failure on line 57 in src/deploy/apphosting/release.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `↹` with `········`

Check failure on line 57 in src/deploy/apphosting/release.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Replace `↹` with `········`

Check failure on line 57 in src/deploy/apphosting/release.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `↹` with `········`
},
},
},
Expand All @@ -78,7 +77,7 @@
logLabeledSuccess("apphosting", `Your backend is now deployed at:\n\thttps://${backend.uri}`);
} else {
logLabeledWarning("apphosting", `Rollout for backend ${backendIds[i]} failed.`);
logLabeledError("apphosting", res.reason);

Check warning on line 80 in src/deploy/apphosting/release.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
}
}
rolloutsSpinner.stop();
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";
import * as tmp from "tmp";
import { FirebaseError } from "../../error";
import { AppHostingSingle } from "../../firebaseConfig";
import * as fsAsync from "../../fsAsync";

export async function createTarArchive(

Check warning on line 10 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
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);

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

View workflow job for this annotation

GitHub Actions / unit (22)

Expected space or tab after '//' in comment

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

View workflow job for this annotation

GitHub Actions / unit (24)

Expected space or tab after '//' in comment

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

View workflow job for this annotation

GitHub Actions / lint (20)

Expected space or tab after '//' in comment
//ignore.push(...gitIgnorePatterns);

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

View workflow job for this annotation

GitHub Actions / unit (22)

Expected space or tab after '//' in comment

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

View workflow job for this annotation

GitHub Actions / unit (24)

Expected space or tab after '//' in comment

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

View workflow job for this annotation

GitHub Actions / lint (20)

Expected space or tab after '//' in comment
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);


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

View workflow job for this annotation

GitHub Actions / unit (22)

Delete `⏎`

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

View workflow job for this annotation

GitHub Actions / unit (24)

Delete `⏎`

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

View workflow job for this annotation

GitHub Actions / lint (20)

Delete `⏎`
// `tar` returns a `TypeError` if `allFiles` is empty. Let's check a feww things.
try {
fs.statSync(rootDir);
} catch (err: any) {

Check warning on line 35 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err.code === "ENOENT") {

Check warning on line 36 in src/deploy/apphosting/util.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .code on an `any` value
throw new FirebaseError(`Could not read directory "${rootDir}"`);
}
throw err;
}
if (!allFiles.length) {
throw new FirebaseError(

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

View workflow job for this annotation

GitHub Actions / unit (22)

Replace `⏎······`Cannot·create·a·tar·archive·with·0·files·from·directory·"${rootDir}"`,⏎····` with ``Cannot·create·a·tar·archive·with·0·files·from·directory·"${rootDir}"``

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

View workflow job for this annotation

GitHub Actions / unit (24)

Replace `⏎······`Cannot·create·a·tar·archive·with·0·files·from·directory·"${rootDir}"`,⏎····` with ``Cannot·create·a·tar·archive·with·0·files·from·directory·"${rootDir}"``

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

View workflow job for this annotation

GitHub Actions / lint (20)

Replace `⏎······`Cannot·create·a·tar·archive·with·0·files·from·directory·"${rootDir}"`,⏎····` with ``Cannot·create·a·tar·archive·with·0·files·from·directory·"${rootDir}"``
`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

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

View workflow job for this annotation

GitHub Actions / unit (22)

Insert `;`

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

View workflow job for this annotation

GitHub Actions / unit (24)

Insert `;`

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

View workflow job for this annotation

GitHub Actions / lint (20)

Insert `;`
}

/**
* 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 { 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 @@
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 @@
name: string;
mode?: string;
codebase?: Codebase;
runtime?: Runtime;
servingLocality: ServingLocality;
labels: Record<string, string>;
createTime: string;
Expand Down Expand Up @@ -283,7 +288,7 @@
done: boolean;
// oneof result
error?: Status;
response?: any;

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

View workflow job for this annotation

GitHub Actions / lint (20)

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

Expand Down
9 changes: 5 additions & 4 deletions src/gcp/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,17 @@
object: string;
generation: string | null;
}> {
if (path.extname(source.file) !== ".zip") {
throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
}
// if (path.extname(source.file) !== ".zip") {
//throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);

Check failure on line 269 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (22)

Expected space or tab after '//' in comment

Check failure on line 269 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / unit (24)

Expected space or tab after '//' in comment

Check failure on line 269 in src/gcp/storage.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Expected space or tab after '//' in comment
//}
const localAPIClient = new Client({ urlPrefix: storageOrigin() });
const location = `/${bucketName}/${path.basename(source.file)}`;
const res = await localAPIClient.request({
method: "PUT",
path: location,
headers: {
"Content-Type": "application/zip",
//"Content-Type": "application/zip",
"Content-Type": "application/octet-stream",
"x-goog-content-length-range": "0,123289600",
},
body: source.stream,
Expand Down
Loading