如何解决使用 Cloud Build 部署到 App Engine 时如何使用相对依赖项
我有一个完整的堆栈项目,其中包含一些常见模块,主要是类型定义。我想将它们保存在同一个存储库中,以保持应用程序的一致状态。但是,部署并没有像我期望的那样工作。在我的前两个构建步骤 yarn install 和 yarn build 中,我的相对依赖性没有明显问题。
然而,Gcloud 似乎没有找到它。在第 6 个构建步骤,它显示以下错误消息:
Already have image (with digest): eu.gcr.io/gae-runtimes/buildpacks/nodejs12/builder:nodejs12_20210308_12_21_0_RC00
=== Node.js - Yarn (google.nodejs.yarn@0.9.0) ===
--------------------------------------------------------------------------------
Running "bash -c command -v yarn || true"
/usr/bin/yarn
Done "bash -c command -v yarn || true" (53.639626ms)
DEBUG: Yarn is already installed,skipping installation.
--------------------------------------------------------------------------------
Running "node -v"
v12.21.0
Done "node -v" (35.463448ms)
DEBUG: Current dependency hash: "8d626f89a4d8d27dba2aab32f998ebdf2b45531f6abae7f55eabb00d85cff016"
DEBUG: Cache dependency hash: "e6c8baadd1eb6d1fd69fc3255ba5936ea43d709f6502d54719fdb17c9d9865af"
Installing application dependencies.
DEBUG: ***** CACHE MISS: "prod dependencies"
--------------------------------------------------------------------------------
Running "node -v"
v12.21.0
Done "node -v" (5.746529ms)
--------------------------------------------------------------------------------
Running "yarn install --non-interactive --frozen-lockfile (NODE_ENV=production)"
yarn install v1.22.4
[1/4] Resolving packages...
error Package "common" refers to a non-existing file '"/common"'.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Done "yarn install --non-interactive --frozen-lockfile (NODE_ENV=p..." (528.261919ms)
Failure: (ID: 98e389b6) yarn install v1.22.4
[1/4] Resolving packages...
error Package "common" refers to a non-existing file '"/common"'.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
--------------------------------------------------------------------------------
Running "mv -f /builder/outputs/output-5577006791947779410 /builder/outputs/output"
Done "mv -f /builder/outputs/output-5577006791947779410 /builder/o..." (15.651484ms)
ERROR: failed to build: exit status 1
文件夹结构:
client/
package.json
cloudbuild.json
common/
package.json
server/
package.json
cloudbuild.json
客户端/package.json
{
"name": "client","dependencies": {
"common": "file:../common"
}
}
客户端/cloudbuild.json
{
"steps": [
{
"name": "node","entrypoint": "yarn","args": ["--cwd","client","install"]
},{
"name": "node","dir": "client","args": ["run","build"]
},{
"name": "gcr.io/google.com/cloudsdktool/cloud-sdk","entrypoint": "bash","args": ["gcloud","app","deploy"]
}
],"timeout": "1600s"
}
我需要如何调整我的 cloudbuild 文件,以便构建器找到我的相对依赖项?
解决方法
您应该将所有内容(client
、server
和 common
)合并到一个 Cloud Build 配置中。
当您 gcloud build submit
时,源目录会转移到 Cloud Build 服务 (VM) 并放置在名为 /workspace
的目录中。如果您希望能够从 common
或 client
引用 server
,则必须将此目录作为其构建过程的一部分进行复制。为了节省能源,构建 common
一次然后构建 client
和 server
引用它很方便。
然后您就可以通过引用 client
来构建 server
和 common
,因为它也被转移了。
您可以从一个 Cloud Build 作业生成多个映像,因此您应该为 client
生成一个映像,为 server
生成一个。
文件夹结构:
cloudbuild.json
client/
package.json
common/
package.json
server/
package.json
或者,我对 Node.JS 包管理不太熟悉,您可以先 (Cloud) Build common
并使其可访问 client
和 {{1 }}。通常,这将通过一些(网络可访问的)私有包管理解决方案来实现,server
和 client
将在其构建过程中引用这些解决方案。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。