-1

I have run into a problem where I need to run both Java+Android and NodeJS in the same CloudBuild "step".

My current situation is that I'm trying to build a react-native project within Google CloudBuild. The problem with this is that while bundling for Android with .gradlew a node script is called.

I tried using a CloudBuild step config like this:

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

But this resulted in this error:

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

Of course, this makes sense, as there would be no reason for NodeJS to be installed by this container.

My question is how can I run this script using both the NodeJS and Android container images?

twiz
  • 9,041
  • 8
  • 52
  • 84

1 Answers1

2

Firstly, on Cloud Build, you can only run 1 container at each step. Here your problem isn't to run 2 containers, you want to have 2 applications embedded in the same container.

For this 2 solutions:

  1. You find a container with all what you want installed on it
  2. You use a base container and you install by yourselves the missing app on it
  • Either, just after the installation you use it as-is
  • Or you can create a build pipeline to shape your own container (custom-builder) from the base with the installations of missing part and store it in GCR. Then, for the build of your application, you can use directly this custom container

To install the missing part, you can do this

- 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
}

Note: you can find the correct installation for your base image here. I use the standard Linux Ubuntu installation in my example

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76