Use per-project customized values.yaml file in auto devops .gitlab-ci.yml template
What does this MR do?
I want to share with you my solution for the issue #56961 (moved)
It allows to specify custom values.yaml
file per project / group / environment, this would allow to create re-usable framework specific helm charts when using Auto Deploy.
I think it can answer to both options proposed by @DylanGriffith https://gitlab.com/gitlab-org/gitlab-ce/issues/56961#note_136191131
Here, a bit of documentation to explain what you can do...
Set additional Helm chart values in a CI variable
Go to your GitLab project's Settings > CI/CD, then expand the section called Environment variables.
You can set your additional Helm chart values in a CI variable, like this:
Variable | Value |
---|---|
AUTO_DEPLOY_VALUES_YAML | postgresql: enabled: true image: tag: $${POSTGRES_VERSION:-9.6} postgresqlUsername: $$POSTGRES_USER postgresqlPassword: $$POSTGRES_PASSWORD postgresqlDatabase: $$POSTGRES_DB |
You are able to use other variables inside your variable definition (but you should escape them with $$).
Or for a specific environment (this takes precedence over the AUTO_DEPLOY_VALUES_YAML
):
Variable | Value |
---|---|
<ENVIRONMENT>_AUTO_DEPLOY_VALUES_YAML | postgresql: enabled: true image: tag: 11 postgresqlUsername: $$POSTGRES_USER postgresqlPassword: $$POSTGRES_PASSWORD postgresqlDatabase: $$POSTGRES_DB |
Customize additional Helm chart values file path
By default, your additional Helm chart values can be stored (or will be generated if AUTO_DEPLOY_VALUES_YAML
is present) in the chart/auto_deploy_values.yaml
path of your project.
If for some reason you want to change it.
Go to your GitLab project's Settings > CI / CD, then expand the section called Environment variables, and add CI variable like this:
Variable | Value |
---|---|
AUTO_DEPLOY_VALUES_PATH | chart/auto_deploy_values.yaml |
Or for a specific environment (this takes precedence over the AUTO_DEPLOY_VALUES_PATH
):
Variable | Value |
---|---|
<ENVIRONMENT>_AUTO_DEPLOY_VALUES_PATH | chart/auto_deploy_values.yaml |
Overwrite Helm chart default values file path
Set the CI variable AUTO_DEPLOY_VALUES_PATH
with this value: chart/values.yaml
.
Be careful, it'll overwrite the values.yaml
file of your chart, so you need to provide all default values.
Go to your GitLab project's Settings > CI / CD, then expand the section called Environment variables.
And set the whole values.yaml
content inside the AUTO_DEPLOY_VALUES_YAML
CI variable.
Or <ENVIRONMENT>_AUTO_DEPLOY_VALUES_YAML
for a specific environment.
This takes precedence over AUTO_DEPLOY_VALUES_YAML
.
Add environment variables that are used as values by the Helm chart
Any variable prefixed with AUTO_DEPLOY_ENV_
will be used as values by the Helm chart.
Go to your GitLab project's Settings > CI / CD, then expand the section called Environment variables, and add CI variable like this:
Variable | Value |
---|---|
AUTO_DEPLOY_ENV_<YOUR_KEY> | your_value |
Or for a specific environment (this takes precedence over the AUTO_DEPLOY_ENV_<YOUR_KEY>
):
Variable | Value |
---|---|
<ENVIRONMENT>_AUTO_DEPLOY_ENV_<YOUR_KEY> | your_value |
Create a CI Variable, ensuring the key is prefixed with AUTO_DEPLOY_ENV_
For example, you can create a variable with key AUTO_DEPLOY_ENV_POSTGRES_VERSION
and/or a PRODUCTION_AUTO_DEPLOY_ENV_POSTGRES_VERSION
key.
AUTO_DEPLOY_VALUES_YAML
CI variable
If you don't set the In your Git repository, you can add a chart/auto_deploy_values_template.yaml
file and add your additional values content, like this:
postgresql:
enabled: true
image:
tag: 9.6
postgresqlUsername: $POSTGRES_USER
postgresqlPassword: $POSTGRES_PASSWORD
postgresqlDatabase: $POSTGRES_DB
foo: ${BAR:-my_default_value}
Overwrite Helm chart template file path for customized values
By default, Auto Deploy will use the template file, for additional Helm chart values, stored in the chart/auto_deploy_values_template.yaml
path of your project.
If for some reason you want to change it.
Go to your GitLab project's Settings > CI / CD, then expand the section called Environment variables, and add CI variable like this:
Variable | Value |
---|---|
AUTO_DEPLOY_VALUES_TEMPLATE_PATH | chart/auto_deploy_values_template.yaml |
Or for a specific environment (this takes precedence over the AUTO_DEPLOY_VALUES_TEMPLATE_PATH
):
Variable | Value |
---|---|
<ENVIRONMENT>_AUTO_DEPLOY_VALUES_TEMPLATE_PATH | chart/auto_deploy_values_template.yaml |
What are the relevant issue numbers?
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated via this MR -
Documentation reviewed by technical writer or follow-up review issue created -
Tests added for this feature/bug -
Tested in all supported browsers -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the database guides -
Link to e2e tests MR added if this MR has Requires e2e tests label. See the Test Planning Process. -
Security reports checked/validated by reviewer