Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(werf): add application version param support #6439

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

drey
Copy link
Contributor

@drey drey commented Nov 24, 2024

Implements #6390

The current implementation scope:

  • Add applicationVersion global param support to werf.yml
  • Add applicationVersionFile global param support to werf.yml
  • Plain/text, JSON, YAML files can be used as applicationVersionFile params
  • Giterminism is enforced for applicationVersionFile param
  • Giterminism dev mode is supported for applicationVersionFile param
  • Handle corner case when both applicationVersion and applicationVersionFile params are set
  • applicationVersion value is available in nelm templates by using $.Values.werf.applicationVersion variable

Inline set application version by applicationVersion param

werf.yaml file content:

project: demo-app
configVersion: 1
applicationVersion: v0.0.1

---
image: backend
dockerfile: backend.Dockerfile

---
image: frontend
dockerfile: frontend.Dockerfile

Set application version by external JSON file

werf.yaml file content:

project: demo-app
configVersion: 1
applicationVersionFile: ./version.json

---
image: backend
dockerfile: backend.Dockerfile

---
image: frontend
dockerfile: frontend.Dockerfile

./version.json file content:

{
    "version": "v0.0.1"
}

Set application version by external YAML file

werf.yaml file content:

project: demo-app
configVersion: 1
applicationVersionFile: ./version.yaml

---
image: backend
dockerfile: backend.Dockerfile

---
image: frontend
dockerfile: frontend.Dockerfile

./version.yaml file content:

version: v0.0.1

Set application version by external plain/text file

werf.yaml file content:

project: demo-app
configVersion: 1
applicationVersionFile: ./version

---
image: backend
dockerfile: backend.Dockerfile

---
image: frontend
dockerfile: frontend.Dockerfile

./version file content:

v0.0.1

@alexey-igrychev
Copy link
Member

Hi! Thank you for your work and the proposed solution.

The feature looks useful overall, but there are a few points we need to discuss. For example, using $.Values.werf.applicationVersion feels a bit off from an API perspective. We need this value to be more directly available, for instance, through $.Chart, similar to other global parameters like project name or apiVersion.

We’ll take a pause and will get back to you soon with a proposal to improve your solution.

@ilya-lesikov
Copy link
Member

ilya-lesikov commented Dec 3, 2024

Thanks for you work! After discussion, we decided that the feature should be implemented this way:

# werf.yaml
deploy:
  helmChartConfig:
    appVersion: <app version goes here>

With Go templating capabilities of werf.yaml we can already do this:

    appVersion: {{ env "VERSION" }}

and this:

    appVersion: {{ (.Files.Get "version.yaml" | fromYaml).version }}

and probably this:

    appVersion: {{ (.Files.Get "version.json" | fromJson).version }}

so no need for appVersionFile directives.

This appVersion should override whatever in the appVersion of .helm/Chart.yaml (if anything) and then be exposed in a standard way through $.Chart.AppVersion, since this is standard Helm functionality, but not via $.Values.werf.... In Helm the $.Chart structure mirrors whatever is found in the Chart.yaml (more info). To implement this you might need to do some changes to https://github.com/werf/nelm and maybe https://github.com/werf/3p-helm too.

@drey
Copy link
Contributor Author

drey commented Dec 3, 2024

Hi Ilya, thank you for the feedback. I like the idea of using the integrated Go templating capabilities you mentioned. I will dive into nelm and implement the change requested.

@alexey-igrychev alexey-igrychev marked this pull request as draft December 3, 2024 18:04
@drey drey force-pushed the feat-werf-app-version branch from 2b08bdd to 1afe493 Compare December 3, 2024 21:26
@drey
Copy link
Contributor Author

drey commented Dec 3, 2024

Done.

PS I found a way to override parent's Chart.yaml appVersion without touching nelm and 3p-helm packages.

@drey drey marked this pull request as ready for review December 4, 2024 06:59
@ilya-lesikov
Copy link
Member

LGTM, thanks! Can you squash commits and sign them so that this will pass: https://github.com/werf/werf/pull/6439/checks?check_run_id=33876806421

@drey drey force-pushed the feat-werf-app-version branch from 1afe493 to 96a99b5 Compare December 4, 2024 09:27
@drey
Copy link
Contributor Author

drey commented Dec 4, 2024

Done

@ilya-lesikov ilya-lesikov merged commit cdfd488 into werf:main Dec 4, 2024
13 of 15 checks passed
@drey drey deleted the feat-werf-app-version branch December 4, 2024 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants