0

In my app, I have the following:

  • app.yaml
  • cloudbuild.yaml

I use the above for the first time to deploy the default service.

  • app.qa.yaml

  • cloudbuild_qa.yaml

  • app.staging.yaml

  • cloudbuild_staging.yaml

  • app.prod.yaml

  • cloudbuild_prod.yaml

They all reside at the root of the app.

For instance, the cloudbuild_qa.yaml is as follows:

steps:
  - name: node:14.0.0
    entrypoint: npm
    args: ['install']
  - name: node:14.0.0
    entrypoint: npm
    args: ['run', 'prod']
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['beta', 'app', 'deploy', '--project', '$PROJECT_ID', '-q', '$_GAE_PROMOTE', '--version', '$_GAE_VERSION', '--appyaml', 'app.qa.yaml']
timeout: '3600s'

The Cloud Build works well, however, it's not respecting the app.qa.yaml instead, it always takes the default app.yaml.

Services to deploy:

descriptor: [/workspace/app.yaml]
source: [/workspace]
target project: [test-project]
target service: [default]
target version: [qa]
target url: [https://test-project.uc.r.appspot.com]

Any idea what's happening? Do you know how to use the correct app.yaml file in such a case?

Bill
  • 2,026
  • 9
  • 55
  • 99
  • I tried to reproduce the issue and it works fine for me when the files are in root directory and when I explicitly mention the cloudbuild.yaml file that I want to deploy in the command as shown below: gcloud builds submit --config cloudbuild_qa.yaml But if I try to give gcloud builds submit command then it considers the default cloudbuild.yaml file and not the cloudbuild_qa.yaml. – Zeenath S N Jun 10 '21 at 15:05
  • So my question is where are your files now and are you using the right command and from where are you running the cloud build - through console or command line.? And I have found this stackoverflow thread[1] that you can look into, which might help you in solving your issue. [1] https://stackoverflow.com/questions/51861870/github-cloud-build-integration-with-multiple-cloudbuild-yamls-in-monorepo – Zeenath S N Jun 10 '21 at 15:06

2 Answers2

2

Remove the '--appyaml', in the attribute list.

However, I'm not sure that is a good practice to have a deployment file different from an environment to another one. When you update something at a place, you could forget to update the same thing in the other files.

Did you think to replace placeholders in the files? or to use substitution variables in the Cloud Build?

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Yes indeed. I am using substitution variables. To try to handle the issue in this thread, I tried something else, to copy the app.yaml into the root folder of the app. However, it seems the file is copied, but not picked up by cloud build. You can look here for the other thread: https://groups.google.com/g/google-appengine/c/gpDH9AK2WyA – Bill Jun 09 '21 at 13:10
  • In summary, I removed the app.yaml from the root folder. I moved cloudbuild.yaml inside /ci/cloudbuild.yaml. I added a step to copy the app.yaml from a cloud bucket. – Bill Jun 09 '21 at 13:13
0

In our build we are using:

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy', '--appyaml=app-qa.yaml', '--no-promote', '--version=${_TAG_VERSION}']

FYI:

I've notice you are building your applications using the node builder but you could add the script gcp-build in your package.json because the script gcloud app deploy should look for scripts named gcp-build and execute them before deploying

{
"scripts": {
    ...
    "build": "tsc",
    "start": "node -r ./tsconfig-paths-dist.js dist/index.js",
    "gcp-build": "npm run build"
  },
}

Reference: https://cloud.google.com/appengine/docs/standard/nodejs/running-custom-build-step