user14176259
user14176259

Reputation:

Cloud build can't open requirements.txt

I want to setup a cloud build trigger so that each time I modify (commit and push) main.py, it execute test_mainpytest.py with pytest

I have a project that look like this :

My_Project\function_one\
                        main.py
                        deploy.yaml
                        requirements.txt
                        dir_pytest\
                                   test_mainpytest.py

My deploy.yaml contain thoose steps :

steps:
  - name: 'python'
    args: ['pip3', 'install', '-r', 'My_Project/function_one/requirements.txt', '--user']
  - name: 'python'
    args: ['python3', 'pytest', 'My_Project/function_one/dir_pytest/']

For the moment I just want to try to execute pytest using the trigger. When I execute the cloud build trigger, I get this error :

ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'My_Project/function_one/requirements.txt'

Also my project is saved in a google cloud repository.

Edit :

I tried to add dir in my step, so it currently look like this :

steps:
  - name: 'python'
    dir: 'MyProject/function_one/'
    args: ['pip3', 'install', '-r', 'My_Project/function_one/requirements.txt', '--user']
  - name: 'python'
    dir: 'MyProject/function_one/'
    args: ['python3', 'pytest', 'My_Project/function_one/dir_pytest/']

Yet I still get the error, (I also tried to put dir after args but it didn't change much

I also noticed; when executing the trigger in Cloud Build; thoose 2 lines :

Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/my_id_1234/r/My_Project

Should I use https://source.developers.google.com/p/my_id_1234/r/My_Project and add the path to my requirement.txt and my py_test directory ?

Upvotes: 1

Views: 1123

Answers (2)

Cloudkollektiv
Cloudkollektiv

Reputation: 14689

Could you show your whole cloudbuild.yaml? If you are using a build trigger, the repository is imported directly in /workspace. If you are doing a git clone, then your repository is inside a directory with the name of the repository. The difference is:

/workspace/my-repository/My_Project/function_one/requirements.txt

versus

/workspace/My_Project/function_one/requirements.txt

If nothing else works, you can do ls -R to show you the directory structure within the build. Add this as a first build step:

 - name: 'list recursively'
   args: ['ls', '-R']

Upvotes: 2

Daniel Ocando
Daniel Ocando

Reputation: 3764

Notice that Cloud Build uses a directory called /workspace as a working directory in order to persist the contents. You can add the dir field within your cloudbuild.yaml file in order for Cloud Build to find the requirements.txt file and then run the tests.

Upvotes: 0

Related Questions