@@ -21,3 +21,97 @@ docker pull ghcr.io/clevyr/yampl
21
21
## Usage
22
22
23
23
[ View the help docs for usage information.] ( docs/yampl.md )
24
+
25
+ ## Templating
26
+
27
+
28
+
29
+ ### Functions
30
+
31
+ All [ Sprig functions] ( https://masterminds.github.io/sprig/ ) are available in templates, along with some extra functions:
32
+
33
+ ### ` repo `
34
+
35
+ Splits a Docker repo and tag into the repo component:
36
+ ``` gotemplate
37
+ repo "nginx:stable-alpine"
38
+ ```
39
+ The above produces ` nginx ` .
40
+
41
+ ### ` tag `
42
+
43
+ Splits a Docker repo and tag into the tag component:
44
+ ``` gotemplate
45
+ repo "nginx:stable-alpine"
46
+ ```
47
+ The above produces ` stable-alpine `
48
+
49
+ ### Variables
50
+
51
+ All variables passed in with the ` -v ` flag are available during templating.
52
+ For example, a variable given as ` -v tag=latest ` can be used as ` {{ .tag }} ` .
53
+
54
+ The previous value is always available via ` .Value ` (` .Val ` or ` .V ` if you're feeling lazy).
55
+
56
+ ### Example
57
+
58
+ Here is a simple Kubernetes nginx Deployment:
59
+
60
+ ``` yaml
61
+ apiVersion : apps/v1
62
+ kind : Deployment
63
+ metadata :
64
+ name : nginx-deployment
65
+ spec :
66
+ selector :
67
+ matchLabels :
68
+ app : nginx
69
+ template :
70
+ metadata :
71
+ labels :
72
+ app : nginx
73
+ spec :
74
+ containers :
75
+ - name : nginx
76
+ image : nginx:1.20.2 # yampl nginx:{{ .tag }}
77
+ ports :
78
+ - containerPort : 80
79
+ ` ` `
80
+
81
+ In this example, notice the yaml comment to the right of the ` image`.
82
+
83
+ If this file was called `nginx.yaml`, then we could replace the image tag by running the following :
84
+ ` ` ` shell
85
+ yampl -i nginx.yaml -v tag=1.21.6
86
+ ` ` `
87
+
88
+ The file would be updated in-place and would end up looking like :
89
+ ` ` ` yaml
90
+ apiVersion: apps/v1
91
+ kind: Deployment
92
+ metadata:
93
+ name: nginx-deployment
94
+ spec:
95
+ selector:
96
+ matchLabels:
97
+ app: nginx
98
+ template:
99
+ metadata:
100
+ labels:
101
+ app: nginx
102
+ spec:
103
+ containers:
104
+ - name: nginx
105
+ image: nginx:1.21.6 #yampl nginx:{{ .tag }}
106
+ ports:
107
+ - containerPort: 80
108
+ ` ` `
109
+
110
+ If I wanted to repeat myself even less, I could utilize the `repo` function to pull the existing repo through.
111
+ I could define the `image` template as :
112
+ ` ` ` yaml
113
+ image: nginx:1.21.6 #yampl {{ repo .Value }}:{{ .tag }}
114
+ ` ` `
115
+
116
+ This would generate the same output, but I didn't have to type `nginx` twice.
117
+ This becomes more useful when using custom Docker registries where repo names can get quite long.
0 commit comments