一步使用两个 CloudBuild 镜像
Using two CloudBuild images in one step
我 运行 遇到了一个问题,我需要 运行 在同一个 CloudBuild“步骤”中 Java+Android 和 NodeJS。
我目前的情况是,我正在尝试在 Google CloudBuild 中构建一个 react-native
项目。这样做的问题是,在将 Android 与 .gradlew
捆绑在一起时,会调用一个节点脚本。
我试过像这样使用 CloudBuild 步骤配置:
{
"name": "gcr.io/$PROJECT_ID/android:29",
"args": ["./gradlew", "bundleProductionRelease"]
}
但这导致了这个错误:
Cannot run program "node": error=2, No such file or directory
当然,这是有道理的,因为这个容器没有理由安装 NodeJS。
首先,在 Cloud Build 上,每一步只能 运行 1 个容器。这里你的问题不是运行 2个容器,你想在同一个容器中嵌入2个应用程序。
对于这 2 个解决方案:
- 你找到了一个容器,上面安装了你想要的所有东西
- 您使用基础容器并自行安装缺少的应用程序
- 要么,安装后你就可以使用它as-is
- 或者您可以创建一个构建管道来从基础上构建您自己的容器 (custom-builder),并安装缺少的部分并将其存储在 GCR 中。然后,对于您的应用程序的构建,您可以直接使用这个自定义容器
要安装缺少的部分,您可以这样做
- name: "gcr.io/$PROJECT_ID/android:29"
entrypoint: "bash"
args:
- "-c"
- |
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
node -v #optional, test the installed version
./gradlew bundleProductionRelease
}
注意:您可以为您的基本映像找到正确的安装 here。我在示例中使用标准 Linux Ubuntu 安装
我 运行 遇到了一个问题,我需要 运行 在同一个 CloudBuild“步骤”中 Java+Android 和 NodeJS。
我目前的情况是,我正在尝试在 Google CloudBuild 中构建一个 react-native
项目。这样做的问题是,在将 Android 与 .gradlew
捆绑在一起时,会调用一个节点脚本。
我试过像这样使用 CloudBuild 步骤配置:
{
"name": "gcr.io/$PROJECT_ID/android:29",
"args": ["./gradlew", "bundleProductionRelease"]
}
但这导致了这个错误:
Cannot run program "node": error=2, No such file or directory
当然,这是有道理的,因为这个容器没有理由安装 NodeJS。
首先,在 Cloud Build 上,每一步只能 运行 1 个容器。这里你的问题不是运行 2个容器,你想在同一个容器中嵌入2个应用程序。
对于这 2 个解决方案:
- 你找到了一个容器,上面安装了你想要的所有东西
- 您使用基础容器并自行安装缺少的应用程序
- 要么,安装后你就可以使用它as-is
- 或者您可以创建一个构建管道来从基础上构建您自己的容器 (custom-builder),并安装缺少的部分并将其存储在 GCR 中。然后,对于您的应用程序的构建,您可以直接使用这个自定义容器
要安装缺少的部分,您可以这样做
- name: "gcr.io/$PROJECT_ID/android:29"
entrypoint: "bash"
args:
- "-c"
- |
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
node -v #optional, test the installed version
./gradlew bundleProductionRelease
}
注意:您可以为您的基本映像找到正确的安装 here。我在示例中使用标准 Linux Ubuntu 安装