java - 使用私有依赖项部署 Cloud Function
问题描述
这是我的第一个问题,所以我会尽力使它变得更好。
我的团队使用一些通用类(使用 maven 来管理依赖项)部署了多个 Java Cloud Functions (GCP)。现在这些类在每个函数中都是重复的,并且必须在每次代码编辑时到处更新。每个 Cloud Functions 都是从源代码部署的。为了避免重复这些类,我将它们打包在一个 jar 中,一切都在本地运行良好。--source
我将此 jar 添加为每个 Cloud Function pom 文件中的本地依赖项,并尝试通过构建具有所有依赖项的 jar 并在gcloud deploy
. 这会导致似乎是 jar 上传的超时错误。
错误跟踪:
DEBUG: Starting new HTTPS connection (1): storage.googleapis.com:443
DEBUG: Caught socket error, retrying: ('Connection aborted.', timeout('The write operation timed out',))
到目前为止我尝试了什么:
- 设置更高的部署超时,
gcloud config set app/cloud_build_timeout 10000
但这似乎不适用于上传步骤,因为它总是在几分钟后失败。 - 将我的本地依赖项上传到私有 nexus 存储库以像以前一样从源代码部署我的功能,但是当我运行时由于 Wagon 错误而拉取失败
mvn package
并且我也没有找到任何解决方案:WagonTransporterFactory: Unsupported transport protocol
详细错误:
[ERROR] Failed to execute goal on project get-content: Could not resolve dependencies for project project:cf:jar:1.0: Failed to collect dependencies at project:pipeline:jar:0.0.1: Failed to read artifact descriptor for project:pipeline:jar:0.0.1: Could not transfer artifact project:pipeline:pom:0.0.1 from/to project-nexus (XXX): Cannot access XXX with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access XXX using the registered transporter factories: WagonTransporterFactory: Unsupported transport protocol -> [Help 1]
我相信这只是因为我的 jar 依赖项太大而无法上传,因为我实际上首先错误地部署了没有依赖关系的 jar(部署成功,但在执行期间缺少类定义)。我的问题是如何使用一个本地/私有依赖项部署我的云功能?
笔记 :
- 我无法将我的依赖项上传到公共 Maven 存储库
- 每个云函数还依赖于公共 maven 依赖项,这些依赖项似乎太大而无法打包在单个 jar 中进行部署
解决方案
我通过从 Maven 切换到 Gradle 解决了这个问题。问题是 Maven 将存储库身份验证参数存储在~/.m2/settings.xml
Google Build 在构建我的 Cloud Function 以进行部署时无法访问的本地文件中。在这个问题之后,我直接切换到 Gradle 以在gradle.build
文件中提供身份验证。
推荐阅读
- javascript - 如何将现有 cookie 与 selenium 和 Python 一起使用以登录
- jquery - 使用 URL 哈希触发现有 jquery
- python - 从不同长度的元组列表的字典中创建 Pandas DataFrame
- android - Android 实时数据观察者不会在片段中删除
- c - 练习 1-8。编写一个程序来计算空格、制表符和换行符
- flutter - 更改 myLocationButton 的颜色——谷歌地图
- java - 关于 if(m==c)m=c 的 JRE 规范;及其意义
- php - 刷新后 PHP 会话在我的服务器中不起作用
- python - 如何改进和修复简单的python评分算法
- css-selectors - 如何选择 DIV 中的元素?