Skip to content

Conversation

@inlined
Copy link
Member

@inlined inlined commented Jun 17, 2021

Adds the firebase init workflow for Go functions. This is the first checkpoint I took in the hackathon. The next PR fleshes out the sample code and gitignore a bit as well as adds support for HTTP contract discovery. I'll try to get that one ready by tonight.

To try out the feature, run firebase --open-sesame golang

@inlined inlined requested a review from joehan June 17, 2021 22:16
@google-cla google-cla bot added the cla: yes Manual indication that this has passed CLA. label Jun 17, 2021
private readonly module: Module
) {}
validate(): Promise<void> {
// throw new FirebaseError("Cannot yet analyze Go source code");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this commented code or switch it to a logger.debug statement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to throwing

Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

cloudFunctions: [
{
apiVersion: 1,
id: "HelloWorld",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this function is in a demo state and you haven't fully implemented pulling some of these values from the Go code (unless it happens later?). I'm ok with leaving it like this for now, but a TODO comment would be helpful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to throwing. I no longer need this to help ensure the setup works (it doesn't create a viable project as written actually, but I'll fix that in the followup that finishes e2e go deployment)


/** Supported runtimes for new Cloud Functions. */
const RUNTIMES: string[] = ["nodejs10", "nodejs12", "nodejs14"];
const RUNTIMES: string[] = ["nodejs10", "nodejs12", "nodejs14", "go113"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will go113 show up in any error messages for users who haven't --open-sesamed? If so, we might want to move it to an EXPERIMENTAL_RUNTIMES type so that we can hide it a bit better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no print statements that use RUNTIMES, but I've created the second list as a defense in depth.

return;
}

// Go will refuse to overwrite an existing mod file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just copy go's behavior and error here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript and JavaScript do a prompt to overwrite and we do above here. That seems correct to me.

const extractArchive = unzipper.Extract({ path: config.path("functions/firebase-functions-go") });
await promisify(stream.pipeline)(download.body, extractArchive);

// Should this come later as "would you like to install dependencies" to mirror Node?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to just always go get instead of prompting like we do for node. If I was developing, I'd prefer that, and I asked a few other peeps who have developed in go which they would expect, and they agreed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Removed comment.

inlined added 6 commits June 21, 2021 10:55
This change adds support for `firebase --open-sesame golang`.

After running this command, `firebase init` will support Go 1.13
as a langauge for Cloud Functions.

Limitations:

1. .gitignore is empty
2. Customers cannot mix Node and Go code (WAI)
3. There is little validation being done of customer code
4. The actual deployed function params are hard coded; SDK incoming
@inlined inlined force-pushed the inlined.create-functions branch 2 times, most recently from 1b90501 to 6ea031c Compare June 21, 2021 20:08
@jthegedus
Copy link
Contributor

This is wicked 🤘

@inlined
Copy link
Member Author

inlined commented Jun 24, 2021

@jthegedus We decided to improve development velocity by developing in the open, but this is definitely not something we're hoping to advertise. Please don't share this broadly or we'll have to move development into a private repo. We'll keep you in mind when it's time to onboard alpha testers though!

Copy link
Contributor

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few nits!

}

// A module can be much more complicated than this, but this is all we need so far.
// for a full reference, see https://golang.org/doc/modules/gomod-ref
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// for a full reference, see https://golang.org/doc/modules/gomod-ref
// For a full reference, see https://golang.org/doc/modules/gomod-ref

}
}

return module;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this error on cases where module.module or module.version doesn't get defined?


constructor(
private readonly projectId: string,
private readonly sourceDirName: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love that we have both sourceDirName and sourceDir - its a bit unclear at first what each means, it seems like you can always infer sourceDirName from sourceDir.

Copy link
Member Author

@inlined inlined Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can derive sourceDirName from projectDir and sourceDir. I've removed sourceDirName from Go where it was unused and have made it derived in Node

@jthegedus
Copy link
Contributor

jthegedus commented Jun 24, 2021

@jthegedus We decided to improve development velocity by developing in the open, but this is definitely not something we're hoping to advertise. Please don't share this broadly or we'll have to move development into a private repo. We'll keep you in mind when it's time to onboard alpha testers though!

Yes of course! 🤐 Keep me in mind for FuncsV2 alpha please 🙏

@inlined
Copy link
Member Author

inlined commented Jun 25, 2021

@jthegedus I followed you on Twitter. DM me your email associated with your GCP projects and I'll see what I can do to get you onboarded when we're ready.

@inlined inlined merged commit 8064795 into master Jun 25, 2021
devpeerapong pushed a commit to devpeerapong/firebase-tools that referenced this pull request Dec 14, 2021
Basic create support

This change adds support for `firebase --open-sesame golang`.

After running this command, `firebase init` will support Go 1.13
as a langauge for Cloud Functions.

Limitations:

1. Customers cannot mix Node and Go code (WAI)
2. There is little validation being done of customer code
3. The actual deployed function params are hard coded; SDK incoming
@bkendall bkendall deleted the inlined.create-functions branch March 18, 2022 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Manual indication that this has passed CLA.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants