Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless: Using a private Python package as a dependency

I have a Python Serverless project that uses a private Git (on Github) repo.

Requirements.txt file looks like this:

itsdangerous==0.24
boto3>=1.7
git+ssh://[email protected]/company/repo.git#egg=my_alias

Configurations of the project mainly looks like this

plugins:
  - serverless-python-requirements
  - serverless-wsgi
custom:
  wsgi:
    app: app.app
    packRequirements: false
  pythonRequirements:
    dockerizePip: true
    dockerSsh: true

When I deploy using this command:

sls deploy --aws-profile my_id --stage dev --region eu-west-1

I get this error:

  Command "git clone -q ssh://[email protected]/company/repo.git /tmp/pip-install-a0_8bh5a/my_alias" failed with error code 128 in None

What am I doing wrong? I'm suspecting either the way I configured my SSH key for Github access or the configurations of the serverless package.

like image 805
Mohamed Taher Alrefaie Avatar asked May 22 '18 15:05

Mohamed Taher Alrefaie


People also ask

Is Python good for serverless?

With the growing popularity of Serverless Cloud Architecture, developers and organizations are creating and hosting applications that support this architecture. Python is the first choice for developing these applications as it is easy to use and houses huge library support.

How does a serverless package work?

Serverless will auto-detect and exclude development dependencies based on the runtime your service is using. This ensures that only the production relevant packages and modules are included in your zip file.


1 Answers

So the only way I managed to sort this issue was

  1. Configure the SSH WITH NO PASSPHRASE. Following steps here.
  2. In serverless.yml, I added the following:
    custom:
      wsgi:
        app: app.app
        packRequirements: false
      pythonRequirements:
        dockerizePip: true
        dockerSsh: true
        dockerSshSymlink: ~/.ssh

Notice I added dockerSshSymlink to report the location of the ssh files on my local machine; ~/.ssh.

  1. In requirements.txt, I added my private dependency like this:

    git+ssh://[email protected]/my_comp/my_repo.git#egg=MyRepo

All works.

like image 123
Mohamed Taher Alrefaie Avatar answered Oct 12 '22 19:10

Mohamed Taher Alrefaie