无服务器:将私有Python包用作依赖项

11

我有一个使用私有Git(在Github上)仓库的Python无服务器项目。

requirements.txt文件如下:

itsdangerous==0.24
boto3>=1.7
git+ssh://git@github.com/company/repo.git#egg=my_alias

该项目的配置主要如下所示

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

当我使用这个命令部署时:

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

我遇到了这个错误:

  Command "git clone -q ssh://git@github.com/company/repo.git /tmp/pip-install-a0_8bh5a/my_alias" failed with error code 128 in None

我做错了什么?我怀疑是我配置Github访问的SSH密钥方式或无服务器包的配置问题。


  1. 当使用ssh url从Github克隆时,您必须提供ssh密钥,因此如果需要ssh克隆,则必须将私钥放入容器中并设置ssh代理。
  2. 在容器中,ssh克隆到底是为什么必要的?您只是安装软件包而没有计划更改上游代码等,因此请使用https://github.com/company/repo.git#egg=my_alias替换要求url即可。
- hoefling
@hoefling,这就是 dockerSsh: true 的作用,它将密钥从外部映射到容器内部。M-T-A,你能否在你的部署命令中添加 --verbose 标志,并分享相应的输出结果? - Tarun Lalwani
你使用的 serverless-python-requirements 版本是什么? - Andrii Maletskyi
另外,您是在交互式 shell 运行 sls deploy ,还是通过某些构建系统运行?如果您在控制台中运行它,则可以使用 git+https 进行交互式身份验证。 - Andrii Maletskyi
2个回答

9

所以我解决这个问题的唯一方法是

  1. 配置SSH时不使用密码。 遵循此处的步骤here
  2. serverless.yml 中添加以下内容:
    custom:
      wsgi:
        app: app.app
        packRequirements: false
      pythonRequirements:
        dockerizePip: true
        dockerSsh: true
        dockerSshSymlink: ~/.ssh

请注意,我添加了dockerSshSymlink以报告我的本地机器上ssh文件的位置:~/.ssh

  1. requirements.txt中,我像这样添加了我的私有依赖项:

    git+ssh://git@github.com/my_comp/my_repo.git#egg=MyRepo

一切正常。


我尝试了相同的方法,但仍然出现了错误:Command errored out with exit status 128。这是什么原因? - Niels Hoogeveen

0

虽然不建议这样做,但你尝试过使用sudo sls deploy --aws-profile my_id --stage dev --region eu-west-1吗?

此错误也可能是由于使用了错误的密码或ssh密钥造成的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接