Skip to main content
Version: 4.x

Profiles: Replace

Configuration

name

The name option is mandatory and expects a string defining the name of the profile.

replace

The replace option expects an object with the following (optional) fields:

  • images which will replace the entire images section of the devspace.yaml
  • deployments which will replace the entire deployments section of the devspace.yaml
  • dev which will replace the entire dev section of the devspace.yaml
  • dependencies which will replace the entire dependencies section of the devspace.yaml
  • hooks which will replace the entire hooks section of the devspace.yaml

Example: Using Config Replace For Profile production

images:
backend:
image: john/devbackend
backend-debugger:
image: john/debugger
deployments:
- name: app-backend
helm:
componentChart: true
values:
containers:
- image: john/devbackend
- image: john/debugger
profiles:
- name: production
replace:
images:
backend:
image: john/prodbackend
patches:
- op: remove
path: deployments[0].helm.values.containers[1]

Explanation:

  • The above example defines 1 profile: production
  • When using the profile production, the config section images would be entirely replaced and additionally, 1 patch would be applied.
  • The resulting config used in-memory when the profile production is used would look like this:
# In-Memory Config After Applying Profile `production`
images:
backend:
image: john/prodbackend
deployments:
- name: app-backend
helm:
componentChart: true
values:
containers:
- image: john/prodbackend
Combine Replace & Patches

As shown in this example, it is possible to use replace and patch options in combination.

parent

The parent option is optional and expects the name of another profile which should be applied before this profile. The kind of profile inheritance that the parent option provides can help to reduce redundancy when multiple profiles need to change the config in a similar way.

Execution Order

A parent profile is applied before the profile that defines the parent. A parent profile can have a parent of its own.

Example: Defining a Parent Profile

images:
backend:
image: john/devbackend
backend-debugger:
image: john/debugger
deployments:
- name: backend
helm:
componentChart: true
values:
containers:
- image: john/devbackend
- image: john/debugger
profiles:
- name: production
parent: staging
patches:
- op: add
path: deployments.name=backend.helm.values.containers
value:
image: john/cache
- name: staging
replace:
images:
backend:
image: john/backendprod
patches:
- op: replace
path: deployments.name=backend.helm.values.container[0].image
value: john/backendprod
- op: remove
path: deployments.name=backend.helm.values.containers[1]

When the production profile is active, the replace and patches statements configured in staging would be applied first because of the parent: staging statement in line 16. After applying the staging profile, DevSpace would additionally apply the currently active production profile. In this example, the production profile is based on the staging profile and the only difference is that the production profile adds another container to the backend deployment which is using the image john/cache.

Useful Commands

devspace print -p [profile]

The following command is useful to verify that the profile modifies the config as intended:

devspace print -p my-profile

The above command would print the config after applying all profile patches and replace statements as well as after replacing all config variables.