首页 > 解决方案 > 在 Google Build 中使用 python 包

问题描述

在我requirements.txt尝试下载python-ldap==3.2.0. 但是,我需要这些依赖项。我应该如何使用 Google Build 下载这些?我尝试了以下但得到了错误:

Step #0 - "Dependency install": E: Unable to locate package libsasl2-dev
Step #0 - "Dependency install": E: Unable to locate package python-dev
Step #0 - "Dependency install": E: Unable to locate package libldap2-dev
Step #0 - "Dependency install": E: Unable to locate package libssl-dev
Step #0 - "Dependency install": Building dependency tree...
Step #0 - "Dependency install": Reading state information...
Finished Step #0 - "Dependency install"
2019/06/14 12:51:21 Step Step #0 - "Dependency install" finished
2019/06/14 12:51:21 status changed to "ERROR"
ERROR
ERROR: build step 0 "ubuntu" failed: exit status 100
2019/06/14 12:51:21 Error updating docker credentials: failed to update docker credentials: signal: killed
2019/06/14 12:51:21 Failed to delete homevol: exit status 1
2019/06/14 12:51:24 Build finished with ERROR status

cloudbuild.yaml

steps:
# Install Dependencies
- name: 'ubuntu'
  id: Dependency install
  args: ['apt-get', 'install',
         'libsasl2-dev', 'python-dev', 'libldap2-dev', 'libssl-dev']
# Install Python Dependencies
- name: 'python'
  id: Pip install
  args: ['pip3', 'install', '-r', 'requirements.txt', '--user']

然后我尝试了

- name: 'ubuntu'
  id: Dependency install
  args: ['apt-get', 'update', '&&', 'apt-get', 'install',
         'libsasl2-dev', 'python-dev', 'libldap2-dev', 'libssl-dev']

但这也失败了。

标签: pythongoogle-cloud-platformgoogle-cloud-build

解决方案


Google Cloud Functions receives only your source code and a requirements.txt file to indicate which python dependencies it uses.
The GCF manager internally and automatically install those dependencies on the python environment that will run you function, you install system libraries to the GCF environment, but you may use the ones that are available (here is the list). The library libldap2 that you require is not available. So you can open an issue on their issue tracker to ask for it.

Now, although it won't help you, the error on GC Build is happening because only the workspace (the starting working directory and everything inside it) is shared between steps. Each step starts a docker container with the image specified in the name parameter and with the workspace mounted.
A more obvious demonstration that system changes are not shared is that using Ubuntu in one step, CentOS in another and Alpine in yet another. System libraries for each of them are very different, so they are clearly not shared.


推荐阅读