问题
I'm using Google Cloud Build with cloudbuild.yaml
to download an app.yaml
file that includes environment variables for my Python
based app. The app.yaml
version used for the initial deployment does not contain the environment variables for security protection.
However, it seems this isn't working and the environment variables aren't being detected - as the app.yaml
does not seem to be overwritten.
The following is my cloudbuild.yaml
configuration:
steps:
- name: gcr.io/cloud-builders/gsutil
args:
[
"cp",
"gs://<path to bucket>/app.yaml",
"app.yaml",
]
I understand the entrypoint for an app on App Engine
is through app.yaml
but I thought that if cloudBuild.yaml
is included, this would be called first and then app.yaml
.
If this isn't correct how else can I append environment variables to my app.yaml file?
Thanks!
回答1:
When you run gcloud app deploy
, the deployment process won't take the cloudbuild.yaml
file into account and will deploy your app along with your unpopulated app.yaml
file.
To run a custom build step, you'll need to create a cloudbuild.yaml file as you did, define your custom build step and then add a build step to run the deploy command. That'd be something like this:
steps:
- name: gcr.io/cloud-builders/gsutil
args:
[
"cp",
"gs://<path to bucket>/app.yaml",
"app.yaml",
]
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy']
You'll then run the build by issuing the following command (in the same directory where you'd have run the gcloud app deploy
one):
gcloud builds submit --config cloudbuild.yaml .
This will:
- Upload the current directory to the Cloud Build instance
- run the gsutil command from within that directory on the CB instance to retrieve the
app.yaml
file populated with your environment variables - deploy your code to App Engine from the Cloud Build instance
来源:https://stackoverflow.com/questions/57455119/add-environment-variable-in-app-yaml-file-during-google-build