0

I have a situation where I want to deploy my whole index file through cloud build using cloudbuild.yaml file but didn't find any way to do so like in firebase we do like firebase deploy --only function:functionName or fileName (in which all functions exists), is there any way to do the same through cloud build.

I have pasted my index.js, main.js and cloudbuild.yaml file below. Please have a look and suggest over this.

// index.js


const fourthFunc = require('./main');
exports.fourthFunction = fourthFunc;

exports.firstFunc = functions.https.onCall((data, context)=>{
    try{
        return "first function"
    }catch(err){
        return err.message
    }
})

exports.secondFunc = functions.https.onCall((data, context)=>{
    try{
        return 'second function'
    }catch(err){
        return err.message;
    }
})

exports.thirdFunc = functions.https.onCall((data, context)=>{
    try{
        return 'third function'
    }catch(err){
        return err.message;
    }
})```


// main.js


```const functions = require("firebase-functions");

exports.fourthFunc = functions.https.onRequest((req, res)=>{
    try{
        return "fourth function"
    }catch(err){
        return err.message;
    }
})```

// cloudbuild.yaml 

```steps:
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  args:
  - gcloud
  - functions
  - deploy
  - firstFunc
  - --region=us-central1
  - --source=./functions
  - --trigger-http
  - --allow-unauthenticated
  - --runtime=nodejs16```
Rohit
  • 9
  • 2

1 Answers1

0

From this line

firebase deploy --only function:functionName or fileName (in which all functions exists)

I assume you want to deploy multiple cloud functions using cloud build. Cloud Build enables you to use any publicly available container image to execute your tasks. You can do this by specifying the image which will contain the functions details in a build step in the Cloud Build config file. In the cloud build you need to just instruct the pipeline to use gcloudwith those specific commands in order to deploy the functions you need, an example:

      args: ['functions ', 'deploy ', 'function1'] - 
      name: "gcr.io/cloud-builders/gcloud" 
      args: ['functions ', 'deploy ', 'function2']
      timeout: "xxxs"

You should check this example describing similar implementation for pipeline deployment
Here are a few Stackoverflow links where different workarounds are shared to deploy multiple functions through cloud build.

  1. Set Up Pipeline on gcp with cloud build

  2. Deploy multiple function using cloud build

  3. Deploy function from same repo

Vaidehi Jamankar
  • 1,232
  • 1
  • 2
  • 10