I'm using a GitHub Actions to deploy to a Google Cloud Function. The steps in my workflow include:
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
# Setup Python so we can install Pipenv and generate requirements.txt.
- name: "Setup Python"
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: "Install Pipenv"
run: |
pipenv requirements > requirements.txt
ls -la
cat requirements.txt
- name: "Generate requirements.txt"
run: pipenv requirements > requirements.txt
- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v0"
with:
workload_identity_provider: "..."
service_account: "..."
- id: "deploy"
uses: "google-github-actions/deploy-cloud-functions@v0"
with:
name: "my-function"
runtime: "python310"
Once I've generated the requirements.txt
file I want that to be deployed along with my application code (checked out in the step above). The requirements.txt
file gets generated during the build but it never gets deployed. (Confirmed by looking at the source in Cloud Functions).
How can I ensure this file is deployed along with my application code?
Update 1:
Here is the output after listing the contents of the directory after generating requirements.txt:
total 56
drwxr-xr-x 6 runner docker 4096 Sep 6 20:38 .
drwxr-xr-x 3 runner docker 4096 Sep 6 20:38 ..
-rw-r--r-- 1 runner docker 977 Sep 6 20:38 .env.example
-rw-r--r-- 1 runner docker 749 Sep 6 20:38 .gcloudignore
drwxr-xr-x 8 runner docker 4096 Sep 6 20:38 .git
drwxr-xr-x 3 runner docker 4096 Sep 6 20:38 .github
-rw-r--r-- 1 runner docker 120 Sep 6 20:38 .gitignore
-rw-r--r-- 1 runner docker 139 Sep 6 20:38 Pipfile
-rw-r--r-- 1 runner docker 454 Sep 6 20:38 Pipfile.lock
-rw-r--r-- 1 runner docker 1276 Sep 6 20:38 README.md
drwxr-xr-x 5 runner docker 4096 Sep 6 20:38 app
drwxr-xr-x 2 runner docker 4096 Sep 6 20:38 data
-rw-r--r-- 1 runner docker 2169 Sep 6 20:38 main.py
-rw-r--r-- 1 runner docker 27 Sep 6 20:38 requirements.txt
Update 2 : Showing the contents of requirements.txt
reveals it to only contain:
-i https://pypi.org/simple
No dependencies are included. This could well be the problem but I'm not yet sure why.
Update 3 : The error shown in the deploy stage of the workflow is:
ModuleNotFoundError: No module named 'aiohttp'
This is because there is no requirements.txt
file to install prior to running the function. aiohttp
just happens to be the first dependency listed in my source code.
As explained by @ianyoung, the problem was with the pip file. The requirements.txt was empty, the requirements file is a list of all of a project's dependencies. This includes the dependencies needed by the dependencies. It also contains the specific version of each dependency, specified with a double equals sign (==).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.