-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cloud Run No Build Initial MVP Implementation #9662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @brittanycho, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers the foundational implementation for 'no-build' Cloud Run functions, streamlining the deployment of applications by allowing direct execution without an explicit build phase. It involves significant updates to the core deployment logic, including new runtime delegates, expanded configuration options for Cloud Run services, and direct integration with the Cloud Run V2 API. The changes also lay the groundwork for new language support, starting with experimental Dart runtime capabilities, and refine the source packaging process to accommodate these new deployment paradigms. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the initial MVP for "Cloud Run No Build" support in Firebase Functions. This allows deploying pre-built container images to Cloud Run. The changes span across the deployment pipeline, from configuration parsing (functions.yaml), source packaging (.tar.gz), to the deployment logic (fabricator.ts) which now interacts with the Cloud Run v2 API. New types and runtime delegates are added to support this feature. The changes look solid and cover the necessary aspects for this new deployment platform. I have a few suggestions to improve code quality, including removing duplicated code, fixing a minor bug, and cleaning up some temporary code artifacts like empty JSDoc comments and unnecessary type assertions.
| async createRunService(endpoint: backend.Endpoint): Promise<void> { | ||
| const storageSource = this.sources[endpoint.codebase!]?.storage; | ||
| if (!storageSource) { | ||
| logger.debug("Precondition failed. Cannot create a Cloud Run function without storage"); | ||
| throw new Error("Precondition failed"); | ||
| } | ||
| const service: Omit<runV2.Service, runV2.ServiceOutputFields> = { | ||
| name: `projects/${endpoint.project}/locations/${endpoint.region}/services/${endpoint.id}`, | ||
| template: { | ||
| containers: [ | ||
| { | ||
| name: "worker", | ||
| image: "scratch", | ||
| command: endpoint.command, | ||
| args: endpoint.args, | ||
| baseImageUri: endpoint.baseImageUri, | ||
| sourceCode: { | ||
| cloudStorageSource: { | ||
| bucket: storageSource.bucket, | ||
| object: storageSource.object, | ||
| generation: storageSource.generation ? String(storageSource.generation) : undefined, | ||
| }, | ||
| }, | ||
| resources: { | ||
| limits: { | ||
| cpu: String(endpoint.cpu || 1), | ||
| memory: `${endpoint.availableMemoryMb || 256}Mi`, | ||
| }, | ||
| cpuIdle: true, | ||
| startupCpuBoost: true, | ||
| }, | ||
| }, | ||
| ], | ||
| maxInstanceRequestConcurrency: endpoint.concurrency || 80, | ||
| scaling: { | ||
| minInstanceCount: endpoint.minInstances || 0, | ||
| maxInstanceCount: endpoint.maxInstances || 100, | ||
| }, | ||
| }, | ||
| client: "cli-firebase", | ||
| labels: { ...endpoint.labels, "goog-managed-by": "firebase-functions" }, | ||
| annotations: {}, | ||
| }; | ||
|
|
||
| await this.executor | ||
| .run(async () => { | ||
| const op = await runV2.createService( | ||
| endpoint.project, | ||
| endpoint.region, | ||
| endpoint.id, | ||
| service, | ||
| ); | ||
| endpoint.uri = op.uri; | ||
| endpoint.runServiceId = endpoint.id; | ||
| }) | ||
| .catch(rethrowAs(endpoint, "create")); | ||
|
|
||
| await this.setInvoker(endpoint); | ||
| } | ||
|
|
||
| async updateRunService(update: planner.EndpointUpdate): Promise<void> { | ||
| const endpoint = update.endpoint; | ||
| const storageSource = this.sources[endpoint.codebase!]?.storage; | ||
| if (!storageSource) { | ||
| logger.debug("Precondition failed. Cannot update a Cloud Run function without storage"); | ||
| throw new Error("Precondition failed"); | ||
| } | ||
|
|
||
| const service: Omit<runV2.Service, runV2.ServiceOutputFields> = { | ||
| name: `projects/${endpoint.project}/locations/${endpoint.region}/services/${endpoint.id}`, | ||
| template: { | ||
| containers: [ | ||
| { | ||
| name: "worker", | ||
| image: "scratch", | ||
| command: endpoint.command, | ||
| args: endpoint.args, | ||
| baseImageUri: endpoint.baseImageUri, | ||
| sourceCode: { | ||
| cloudStorageSource: { | ||
| bucket: storageSource.bucket, | ||
| object: storageSource.object, | ||
| generation: storageSource.generation ? String(storageSource.generation) : undefined, | ||
| }, | ||
| }, | ||
| resources: { | ||
| limits: { | ||
| cpu: String(endpoint.cpu || 1), | ||
| memory: `${endpoint.availableMemoryMb || 256}Mi`, | ||
| }, | ||
| cpuIdle: true, | ||
| startupCpuBoost: true, | ||
| }, | ||
| }, | ||
| ], | ||
| maxInstanceRequestConcurrency: endpoint.concurrency || 80, | ||
| scaling: { | ||
| minInstanceCount: endpoint.minInstances || 0, | ||
| maxInstanceCount: endpoint.maxInstances || 100, | ||
| }, | ||
| }, | ||
| client: "cli-firebase", | ||
| labels: { ...endpoint.labels, "goog-managed-by": "firebase-functions" }, | ||
| annotations: {}, | ||
| }; | ||
|
|
||
| await this.executor | ||
| .run(async () => { | ||
| const op = await runV2.updateService(service); | ||
| endpoint.uri = op.uri; | ||
| endpoint.runServiceId = endpoint.id; | ||
| }) | ||
| .catch(rethrowAs(endpoint, "update")); | ||
|
|
||
| await this.setInvoker(endpoint); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The methods createRunService and updateRunService share a large block of code for constructing the service object. This duplication can be avoided by extracting the common logic into a private helper method. This will improve maintainability and reduce redundancy.
For example, you could create a helper method like this:
private _runServiceFromEndpoint(endpoint: backend.Endpoint, storageSource: gcfV2.StorageSource): Omit<runV2.Service, runV2.ServiceOutputFields> {
return {
name: `projects/${endpoint.project}/locations/${endpoint.region}/services/${endpoint.id}`,
template: {
containers: [
{
name: "worker",
image: "scratch",
command: endpoint.command,
args: endpoint.args,
baseImageUri: endpoint.baseImageUri,
sourceCode: {
cloudStorageSource: {
bucket: storageSource.bucket,
object: storageSource.object,
generation: storageSource.generation ? String(storageSource.generation) : undefined,
},
},
resources: {
limits: {
cpu: String(endpoint.cpu || 1),
memory: `${endpoint.availableMemoryMb || 256}Mi`,
},
cpuIdle: true,
startupCpuBoost: true,
},
},
],
maxInstanceRequestConcurrency: endpoint.concurrency || 80,
scaling: {
minInstanceCount: endpoint.minInstances || 0,
maxInstanceCount: endpoint.maxInstances || 100,
},
},
client: "cli-firebase",
labels: { ...endpoint.labels, "goog-managed-by": "firebase-functions" },
annotations: {},
};
}Then, createRunService and updateRunService can be simplified to use this helper.
| // @ts-ignore | ||
| const result = buildFromV1Alpha1(yaml, "danielylee-91", "us-west1", "dart"); | ||
| console.log("Result endpoints:", JSON.stringify(result.endpoints, null, 2)); | ||
|
|
||
| // @ts-ignore | ||
| const endpoint = (result.endpoints as any)["darttest"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of @ts-ignore and as any can be avoided here with proper typing. This will make the verification script cleaner and more type-safe.
| // @ts-ignore | |
| const result = buildFromV1Alpha1(yaml, "danielylee-91", "us-west1", "dart"); | |
| console.log("Result endpoints:", JSON.stringify(result.endpoints, null, 2)); | |
| // @ts-ignore | |
| const endpoint = (result.endpoints as any)["darttest"]; | |
| const result = buildFromV1Alpha1(yaml as unknown, "danielylee-91", "us-west1", "dart"); | |
| console.log("Result endpoints:", JSON.stringify(result.endpoints, null, 2)); | |
| const endpoint = result.endpoints["darttest"]; |
Cloud Run No Build Initial MVP Implementation