Google Cloud Build - build.yaml & app.yaml in a sub directory not building correct source

1,453 views
Skip to first unread message

Alex Fox

unread,
May 29, 2020, 7:47:14 AM5/29/20
to Google App Engine
Hey,

I'm having trouble setting up my yaml files for google app engine. The configuration works correctly when my app.yaml file is in the root of the project but if it is within a subdirectory it does not build the correct source. I suspect I need to set the `dir:` option in the build config, but I have tried multiple variations and I can't get it to work.

Working file structure, deployed app is ~3mb in size.

```
src
deployment
└── staging
    └── build.yaml
app.staging.yaml


# build.yaml
steps:
- name: node:12
  entrypoint: yarn
- name: node:12
  entrypoint: yarn
  args: ['build']
  args: ["app", "deploy", "app.staging.yaml"]
timeout: "1800s"
```

Not working file structure, deployed app is ~1kb in size.

```
src
deployment
└── staging
    └── build.yaml
    └── app.yaml


# build.yaml
steps:
- name: node:12
  entrypoint: yarn
- name: node:12
  entrypoint: yarn
  args: ['build']
  args: ["app", "deploy", "deployment/staging/app.yaml"]
timeout: "1800s"
```

In both scenarios I am kicking off the deployment with:
`gcloud builds submit --config deployment/staging/build.yaml`

What should my `dir:` be set to in the build.yaml steps so that the build step knows to build from root? Is there any way to debug this locally without having to upload the source every time?

Thanks!
A

Olu

unread,
May 29, 2020, 9:29:28 AM5/29/20
to Google App Engine
Hello, Alex

Can you please provide the specific error obtained while using your second setup that is failing? This will provide more context. Yes, as indicated in this Stackoverflow link[1], it is necessary to specify the DIR in the Cloudbuild.yaml whenever you are trying to trigger your build configuration in a subdirectory. Additionally, with information available to me, I understand you cannot have the app.yaml and the cloudbuild.yaml in the same directory if you are deploying in a non-custom runtime 

Alex Fox

unread,
May 29, 2020, 3:46:48 PM5/29/20
to Google App Engine
Yes, I saw that SO issue but I couldn't work out what the correct dir: value should be.

In both cases the app deploy successfully but in the second case when accessing the url I receive a 500 error and the deployed code is only ~600 bytes which suggests to me it's deployed an empty folder or something like that.

This leads me to believe I need to specify the source for the build step, but if I am running the cloudbuild from within a subfolder how do I escape up the folder tree, e.g. ../../ ?

David (Cloud Platform Support)

unread,
Jun 1, 2020, 3:44:27 PM6/1/20
to Google App Engine
When you use the dir field in a build step, you are setting the working directory to its value and in this case, assuming your source files are not in that working directory and from what you have mentioned that it’s deploying empty, it’s not finding your source files and you can check this if you go to your deployed application versions, under “diagnose” right click on tools -> source and you will be able to see the files that were deployed.

Alex Fox

unread,
Jun 2, 2020, 8:21:15 AM6/2/20
to Google App Engine
But what if the build file is within a sub directory, how can you set the dir to be its parent?

David (Cloud Platform Support)

unread,
Jun 3, 2020, 2:40:16 PM6/3/20
to Google App Engine

Here is the official documentation of dir, not sure if you can escape up. However, it’s recommended to have the app.yaml in the same directory where the main is. Maybe if you could provide more information about what you are trying to accomplish with having this specific setup, there could be other different aproaches. For example, If you want is to deploy a stage and prod, you could just have one cloudbuild.yaml file at root specifying different deployments, and have a prod and a stage directory under it having the source files in each of their respective directory.

Reply all
Reply to author
Forward
0 new messages