Building Google Cloud Platform Solutions
上QQ阅读APP看书,第一时间看更新

Application configuration files

On Google App Engine, the primary method of externalizing application configuration is through the use of the app.yaml configuration file. In addition to configuration properties that affect how App Engine deploys and manages services (for example, scaling and memory), the App Engine configuration file allows users to define environment variables, which will be made available to running applications. Environment variables are perhaps the most common method for externalizing configuration. Services built to pull configuration from environment variables will generally be more portable than other methods.

To configure environment variables on App Engine applications, include an env_variables block in your app.yaml :

env_variables:
VARIABLE_ONE: ‘some-value'
VARIABLE_TWO: ‘another-value'

Note that when deploying applications, users can specify which application configuration file to use. This makes it possible to store multiple configuration files within the same repository. A common approach for handling configurations across application lifecycles is to maintain separate configuration files, for example app-development.yaml, app-staging.yaml, and app-production.yaml, where each file contains environment variables that modify application behavior based on the lifecycle.

While defining environment variables in yaml configuration files is great for basic key-value pairs, storing these values in version control such as Git is generally a bad idea. A simple approach to this issue is to explicitly exclude configuration files from version control, and provide them at deployment time. This approach is generally secure, but has several drawbacks. For example, secrets files spread across multiple development machines are likely to become inconsistent over time, and machines holding these secrets may become compromised.

Many PaaS offerings provide some dynamic ways to provide applications environment variables outside of the deployment manifest, commonly through setting environment variables directly in the platform, by supporting configuration inheritance, or by passing values through or from the host machine. Unfortunately, App Engine does not offer a similar solution. This can make it somewhat difficult to externalize App Engine configurations in a portable manner.

Developers looking to provide environment variables at time of deployment may instead look to external templating solutions such as sed or Jsonnet. In this approach, an app.yaml template can be stored directly in version control, and any secrets or dynamic values can be substituted into the template before deployment. Outside of environment variables, Google Cloud offers many tools and services for managing application configuration and secrets.