Reputation: 2283
functions-framework
requirements.txt
: -e git+https://github.com/<repo>/<project>#egg=<project>
pip install -r requirements.txt
. And the package is successfully installed.import <pkg-name>
works and I am able to access all the functions.gcloud functions \
deploy <function-name> \
--trigger-http \
--entry-point <entry-function> \
--runtime python37 \
--project=<my-project>
As expected this gives an error because it does not have access to the private repo in git.
I created a Google Cloud Repository and linked it to the git repo, hoping that in some way I could specify that in the requirements.txt. Just do not know how.
I tried setting environment variables for username and password (not a good idea, I agree) in Google Cloud Function and specify them in the requirements.txt
as:
-e git+https://${AUTH_USER}:${AUTH_PASSWORD}@github.com/<repo>/<project>#egg=<project>
That too gave an error.
Any help or direction will be greatly appreciated.
Upvotes: 11
Views: 4549
Reputation: 597
Your Method 3 (Git install with username and password) does work. But do remember to add them as Build environment variables
rather than Run environment variables
, as pip install
happens during the build. If you have concerns using your personal credentials, you can get a deployment token instead (which is similar to personal credentials, with a username and password).
Upvotes: 3
Reputation: 2283
While @marian.viadoi was correct in the above comment viz. Google Cloud Function cannot access a private git repo, I have implemented a workaround and sharing just in case it is suitable. Here is what has been done:
python3 setup.py bdist_wheel
dist
folder of it.requirements.txt
I added the line: ./dist/xxxx.whl
to other dependencies required by the cloud functiongcloud deploy ..
This does not answer how to use a private repo in Google Functions (which is not possible), but the above steps ensure that a private package can be easily shared and updated amongst different cloud functions.
Upvotes: 10
Reputation: 8074
You can not access the private repo from cloud function. According to the official documentation:
" Using private dependencies
Dependencies are installed in a Cloud Build environment that does not provide access to SSH keys. Packages hosted in repositories that require SSH-based authentication must be vendored and uploaded alongside your project's code, as described in the previous section.
You can use the pip install command with the -t DIRECTORY flag to copy private dependencies into a local directory before deploying your app, as follows:
Copy your dependency into a local directory:
pip install -t DIRECTORY DEPENDENCY
Add an empty init.py file to the DIRECTORY directory to turn it into a module.
Import from this module to use your dependency:
import DIRECTORY.DEPENDENCY
"
Specifying dependencies in Python
Upvotes: 4