Carl Patenaude Poulin
Carl Patenaude Poulin

Reputation: 6570

How to build TypeScript in Google Cloud Build when using Google Cloud Functions

I have TypeScript functions that I'm building locally and then submitting to Google Cloud Functions, at which point they go through Google Cloud Build. I'd like to have all my building done in a single place. Is there any way to compile TypeScript in Google Cloud Build when using Google Cloud Functions?

Upvotes: 2

Views: 556

Answers (1)

Carl Patenaude Poulin
Carl Patenaude Poulin

Reputation: 6570

Submitting code to Google Cloud Functions goes through one of the following HTTP calls, respectively for creating new functions and modifying existing functions:

POST https://cloudfunctions.googleapis.com/v1/{location}/functions
PATCH https://cloudfunctions.googleapis.com/v1/{function.name}

This triggers a build in Google Cloud Build using a hardcoded builder. Assuming a Yarn project, there is no extension point at any part of this process.

In particular, the builder runs NODE_ENV=production yarn install --non-interactive --frozen-lockfile (and does little else). Specifying NODE_ENV=production runs yarn install without lifecycle scripts, so you can't just define a prepare or postinstall script that compiles your TypeScript output. You need to build your code before you submit it to GCF.

Upvotes: 2

Related Questions