gcloud functions deploy fails with .cloudignore file

1k views Asked by At

When deploying a simple hello_world app to Google Cloud Functions using gcloud, I get the following error message:

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: Build error details not available

It took me quite a while to figure out that this is due to my .cloudignore file:

.cloudignore

# Ignore everything
*

# Except these files:
!main.py
!requirements.txt

What seems to be the problem with this file? And what is a better way achieve what I want, i.e. ignore all files except main.py and requirements.txt?

Any hints are greatly appreciated!

2

There are 2 answers

0
El Yobo On

It seems that there's a bug with gcloud functions handling of .gitignore; gcloud app and gcloud meta list-files-for-upload don't suffer from the same problem, handling the ! rules correctly.

A workaround proposed in this answer to a similar question works for me, explicitly include the . directory e.g. add a rule like this.

!.
4
gso_gabriel On

The .gcloudignore file follows the same pattern as the .gitignore. Considering that, using only the *, could ended up being a recursively method that would ended up messing the other files that would be excepted.

Considering that, I would recommend you to give a try using the below configuration for your .gcloudignore file - this way, the slash should eliminate this undesired behavior:

# Ignore everything
/*

# Except these files:
!main.py
!requirements.txt

A reminder is that the file needs to be in the same directory that the main.py and requirements.txt file are, so the path works correctly. Otherwise, you will need to set the whole path in the .gcloudignore.

In these below posts from the Community - on specific regarding GCP and other on .gitignore - that might help you, since the syntax for both of them are the same and there are some other options and ideas on how to achieve it.

Let me know if the information helped you!