In order to provide environment-specific configurations, we introduced the environments
configuration, which allows you to override the default configuration specified on the LCP.json.
There are some specific rules that apply depending on the type of property that you're trying to override. This article will cover these specific use cases. But first, let's take a look at a basic use case of this feature.
Basic Behavior
Let's say we want to block the CI service to be deployed from all environments, except the infra
environment.
In this case, we can define deploy: false
as the default behavior and add deploy: true
only for that specific environment.
{
"id": "ci",
"memory": 8192,
"cpu": 4,
"deploy": false,
"environments": {
"infra": {
"deploy": true
}
}
}
JSON Object Behavior
Now let's imagine we want to allow the CDN to be enabled in all environments, but in the dev
environment we want it to be disabled.
In this case, we're dealing with loadBalancer
, which is a JSON object. For these types of properties, we adopt a merging behavior. Therefore, you can only specify what changed. That's why we don't need to declare the targetPort
once again.
{
"id": "webserver",
"memory": 512,
"cpu": 2,
"loadBalancer": {
"targetPort": 80,
"cdn": true
},
"environments": {
"dev": {
"loadBalancer": {
"cdn": false
}
}
}
}
The resulting loadBalancer
object would look like this on the dev
environment:
"loadBalancer": {
"targetPort": 80,
"cdn": false
}
JSON Array Behavior
Finally, let's say we want to have all ports closed, but open only one port externally available in the uat
environment.
In this case, we're dealing with ports
, which is a JSON array. For these types of properties, we adopt an override behavior. This means that we need to be explicit about what we want to change.
{
"id": "database",
"memory": 1024,
"cpu": 2,
"ports": [
{
"port": 3306,
"external": false
},
{
"port": 3000,
"external": false
}
],
"environments": {
"uat": {
"ports": [
{
"port": 3306,
"external": true
}
]
}
}
}
The resulting ports
array would look like this on the uat
environment:
"ports": [
{
"port": 3306,
"external": true
}
]