1

hope this question helps others struggling to use GCP.

I am trying to automate deployments of my strapi app to Google App Engine using CloudBuild. This is my cloudbuild.yaml:

steps:
  - name: 'ubuntu'
    entrypoint: "bash"
    args:
      - "-c"
      - |
        rm -rf app.yaml
        touch app.yaml

        cat <<EOT >> app.yaml
        runtime: custom

        env: flex

        env_variables:
          HOST: '0.0.0.0'
          NODE_ENV: 'production'
          DATABASE_NAME: ${_DATABASE_NAME}
          DATABASE_USERNAME: ${_DATABASE_USERNAME}
          DATABASE_PASSWORD: ${_DATABASE_PASSWORD}
          INSTANCE_CONNECTION_NAME: ${_INSTANCE_CONNECTION_NAME}

        beta_settings:
          cloud_sql_instances: ${_CLOUD_SQL_INSTANCES}

        automatic_scaling:
          min_num_instances: 1
          max_num_instances: 2
        EOT

        cat app.yaml

  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: 'bash'
    args: ['-c', 'gcloud app deploy app.yaml --project ecomm-backoffice']

If I understand correctly how general CI/CD works, this file should create an app.yaml and then run gcloud app deploy app.yaml --project ecomm-backoffice command.

However, CloudBuild is creating nested recursive builds once i push my changes to github(triggers are enabled).

Can someone please help me with the right way of deploying strapi/nodejs to app engine using cloudbuild? I tried searching lot of solutions but haven't had any luck so far.

Omkar
  • 2,274
  • 6
  • 21
  • 34
  • Please include Cloud Build logs in your question so that we may better understand what's going on. Ostensibly, the configuration file appears to be ok. From memory, I don't see how you're providing values to your environment variables from a trigger but that's likely my poor recollection. Does `cat app.yaml` in the first step produce the expected output? How are you authenticating in the second (`cloud-sdk`) step? – DazWilkin Nov 23 '21 at 16:16
  • I am using cloudbuild with the trigger in the same project. Therefore authentication isn't required IIRC. Not sure what's the problem. Here's the pastebin for the cloudbuild logs for the commit triggered build: https://pastebin.com/66Px3SK0 – Omkar Nov 23 '21 at 16:32
  • It's unclear why the `ubuntu` step is not included in the logs. Thinking more about it, can you confirm that the `app.yaml` is persisted to `/workspace` and survives the step... Perhaps add an intermediate step using e.g. `busybox` that `cat /workspace/app.yaml`? I checked Google's docs and it does appear the the `cloud-sdk` container is authenticated by Cloud Build **but** I don't understand how this is happening and, without trying it myself, can't attest to it working. – DazWilkin Nov 23 '21 at 21:20
  • In general it is not the best approach to generate the app.yaml on fly and it is recommended to have in the same directory that your cloudbuild.yaml. To debug this issue I recommend you to create a app.yaml and see if your build is still failing, if it isn't we might know there is some problem on how the file created. – llompalles Nov 26 '21 at 15:04

0 Answers0