0

I have an NX monorepo and would like to deploy only those apps which had a change since the last commit.

My cloudbuild.yaml looks like this:

steps:
  - name: node:16-bullseye
    entrypoint: yarn
    args: ["install", "--frozen-lockfile"]

  - name: node:16-bullseye
    entrypoint: yarn
    args: ["nx", "affected", "-t", "build"]

  - name: "gcr.io/cloud-builders/gcloud"
    entrypoint: bash
    args: ["yarn", "nx", "affected", "-t", "deploy"]

The command yarn nx affected -t deploy calls the deploy scripts of the apps with changes. These are defined as:

    "deploy":{
      "executor": "nx:run-commands",
      "options": {
        "commands": [
          "cp ../../../apps/myapp/app.yaml .",
          "gcloud app deploy"
        ],
        "cwd": "dist/apps/myapp",
        "parallel": false
      }
    },

So in essence they will copy the app.yaml file and then run gcloud app deploy from the directory the app is built in.

The problem is I can't get an environment in cloudbuild where both gcloud and yarn are available. The above example gives me the error bash: yarn: No such file or directory

sev
  • 1,500
  • 17
  • 45
  • 1
    You can create your own Docker image custom builder. Inherit it from 'gcr.io/cloud-builders/gcloud', add yarn and use that in your build. Doc about creating builders: https://cloud.google.com/build/docs/configuring-builds/use-community-and-custom-builders#creating_a_custom_builder . Would that work for you? – mlablablab May 03 '23 at 07:08
  • This is a very interesting proposition - I will try this and let you know – sev May 04 '23 at 08:02

0 Answers0