【问题标题】:Using two CloudBuild images in one step一步使用两个 CloudBuild 映像
【发布时间】:2020-11-28 21:29:48
【问题描述】:

我遇到了一个问题,我需要在同一个 CloudBuild“步骤”中同时运行 Java+Android 和 NodeJS。

我目前的情况是我正在尝试在 Google CloudBuild 中构建一个 react-native 项目。这样做的问题是,在使用 .gradlew 为 Android 捆绑时,会调用一个节点脚本。

我尝试使用这样的 CloudBuild 步骤配置:

{
    "name": "gcr.io/$PROJECT_ID/android:29",
    "args": ["./gradlew", "bundleProductionRelease"]
}

但这导致了这个错误:

Cannot run program "node": error=2, No such file or directory

当然,这是有道理的,因为这个容器没有理由安装 NodeJS。

我的问题是如何同时使用 NodeJS 和 Android 容器映像运行此脚本?

【问题讨论】:

    标签: android node.js react-native google-cloud-build


    【解决方案1】:

    首先,在 Cloud Build 上,每一步只能运行 1 个容器。在这里,您的问题不是运行 2 个容器,而是希望在同一个容器中嵌入 2 个应用程序。

    对于这 2 个解决方案:

    1. 你找到了一个容器,里面装了所有你想要的东西
    2. 您使用基础容器并自行在其上安装缺少的应用程序
    • 或者,在安装后按原样使用它
    • 或者您可以创建一个构建管道,从安装缺失部件的基础上塑造您自己的容器(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 安装

    【讨论】:

      猜你喜欢
      • 2021-10-25
      • 2021-08-19
      • 2021-07-17
      • 1970-01-01
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      相关资源
      最近更新 更多