[英]How to update Helm Chart.yaml from command line
I'm looking to dynamically update my Chart.yaml
file specifically the version when I run a make helm build command.我希望动态更新我的Chart.yaml
文件,特别是运行 make helm build 命令时的版本。
For example Chart.yaml contains例如 Chart.yaml 包含
apiVersion: v1
appVersion "1.0"
description: A helm chart for so and so
name: my app
version: 0.2
I'm looking for a way to run make helm build version=0.3
and when that build is complete see the updated version number in that builds Chart.yaml
我正在寻找一种运行make helm build version=0.3
的方法,当构建完成时,请查看构建Chart.yaml
中的更新版本号
It's my understanding I can't pass variables to.yaml files so not sure if this is possible?据我了解,我无法将变量传递给 .yaml 文件,所以不确定这是否可能?
First of all your Chart.yaml
is not valid YAML, you need to insert a value separator ( :
) before "1.0"
on the second line. 首先你Chart.yaml
无效YAML,你需要插入值分隔符( :
前) "1.0"
在第二行。
Assuming your Makefile
looks like: 假设你的Makefile
看起来像:
helm:
python3 updateversion.py Chart.yaml ${version}
cat Chart.yaml
, ruamel.yaml
is installed for your Python3 and your updateversion.py
: , ruamel.yaml
安装了您的Python3和你updateversion.py
:
import sys
from pathlib import Path
import ruamel.yaml
yaml_file = Path(sys.argv[1])
yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
# uncomment and adapt next line in case defaults don't match your indentation
# yaml.indent(mapping=4, sequence=4, offset=2)
data = yaml.load(yaml_file)
version = sys.argv[2]
if isinstance(data['version'], float):
version = float(version)
data['version'] = version
yaml.dump(data, yaml_file)
you can run make helm version=0.3
to get output: 你可以运行make helm version=0.3
来获得输出:
apiVersion: v1
appVersion: "1.0"
description: A helm chart for so and so
name: my app
version: 0.3
The trick with testing value for version
being a float is necessary as 0.2
is a float when loading YAML, but 0.2.1
is a string. version
为float的测试值的技巧是必要的,因为0.2
是加载YAML时的浮点数,但0.2.1
是一个字符串。 And what you get from the commandline using sys.argv[2]
is always a string. 而使用sys.argv[2]
获得的内容总是一个字符串。
You can replace the cat Chart.yaml
line for the target helm
with whatever you need to run with the updated file. 您可以将目标helm
的cat Chart.yaml
行替换为您需要使用更新文件运行的任何内容。
--version
argument Helm package 有一个--version
参数Run helm package --version 1.2.3.helm/package_name
运行helm package --version 1.2.3.helm/package_name
Chart.yaml
, it creates a Chart archive file instead.这不会帮助您修改Chart.yaml
,而是创建一个图表存档文件。helm package --help
.有关更多信息,请查看helm package --help
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.