Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a development and staging environments for Google Cloud Functions

I am working on a project that has a dev environment and a staging environment, and thus each environment has its own servers, databases, and each environment should also have its own Pub/Subs and Cloud Functions.

I have a Cloud Function called jsonToCsv that exports a function with the same name jsonToCsv, I want to deploy the same code but under a different name i.e. jsonToCsv_staging, however, GCloud won't allow me to export a function with a name different from the Cloud Function's

ERROR: (gcloud.beta.functions.deploy) OperationError: code=3, 
message=Function load error: Node.js module defined by file index.js is 
expected to export function named jsonToCsv-staging

Coming from an AWS background, I thought there would be a way for me to call different versions of the Cloud Function (i.e. latest would be development and I'd be able to tag a version with staging and another one with production) but I couldn't find a way to do that.

The one way I can think of to get around this is to use the same function with the same name but different Pub/Subs or triggers that would pass environment variables. That wouldn't work if the developer wants to deploy some development code without affecting staging. What are your thoughts on this? What's the best practice in that scenario?

like image 485
Naguib Ihab Avatar asked Apr 10 '18 02:04

Naguib Ihab


People also ask

How do you create a GCP environment?

Create a service accountOpen your project in GCP and use the left-side menu to navigate to IAM & Admin > Service Accounts. Click Create Service Account. Complete the Service account details fields and click Create and Continue. In the Grant this service account access to project section, select the Owner role.

Which command can you use to create the function inside Google cloud?

The gCloud SDK is a set of tools that you can install locally that helps you manage various services on the Google Cloud Platform. Google Cloud Functions can be managed via the gcloud functions command.


1 Answers

The recommended way to isolate environments in Google Cloud Platform (and therefore also Firebase) is to create different projects for each environment.

Environment multi-tenancy in GCP projects is kind of a bad idea, as it opens you up to relatively easy corruption of your production data and code to the daily workings of your development practices.

like image 100
Doug Stevenson Avatar answered Sep 20 '22 00:09

Doug Stevenson