Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

git - Cloud build step executing but not deploying function to Cloud functions?

I have just started using GCP and have few cloud functions working and the source code for these Cloud function are in Cloud source repository. The architecture is like, we have a mono repository and it has multiple folders in it with each folder having source code,dependencies and credentials for each cloud functions. As of now we are manually deploying but the source code in cloud function but recently we started to create a CI/CD pipeline using cloud build. I have created a trigger "push to master branch" and using cloudbuild.yaml as the config file. As of now my cloudbuild.yaml has just one step which is to figure out which subfolder has got the commit and deploy only that particular function not all the cloud functions. This is where am facing the issue , the step runs perfectly but no cloud function is deployed and when I check the logs I get the log which ill be pasting below with the yaml file content.

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
    - -c
    - |    
      for d in $(git diff --name-only --diff-filter=AMDR @~..@ | cut -d'/' -f 1);
      do
        echo $d;
        cd $d
        gcloud functions deploy $d --region=us-central1 --runtime=python37 --trigger-http  --source=/workspace/.git/
        cd ..
      done
    ```

LOGS -

 **starting build "2b5c5348-d946-41bb-87f7-fd98d7e2f2d9"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/littleone-150007/r/testRepForAnalytics
 * branch            677cf59b304d3b1b81488e48c1422cff9877824a -> FETCH_HEAD
HEAD is now at 677cf59 test
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
fatal: ambiguous argument '@~..@': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
PUSH
DONE
**

question from:https://stackoverflow.com/questions/65858307/cloud-build-step-executing-but-not-deploying-function-to-cloud-functions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you have an issue with @~..@. As you said, you have one function per directory and for that I suggest that you create one cloudbuild.yaml per function directory like:

steps:
  - name: "gcr.io/cloud-builders/gcloud"
    args:
      - functions
      - deploy
      - FUNCTION_NAME
      - --runtime=YOUR_RUNTIME
      - --trigger-http 
      - --region=europe-west1
      - --memory=128MB
    id: "deploying-a-function"
    dir: "FUNCTION_DIR"

Then create one trigger per function in cloud build while taking advantage of the include files filter feature to specify only the directory that you want to watch for. Like if the function in directry test then the filter should be test/**


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...