Skip to content

Commit 2c92225

Browse files
committed
parsing variables on local images build for deploy
1 parent 9b31f94 commit 2c92225

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

services/cloud/build.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"kool-dev/kool/core/environment"
99
"kool-dev/kool/core/shell"
1010
"kool-dev/kool/services/cloud/api"
11+
"os"
1112
"path/filepath"
1213
"strings"
1314

@@ -51,7 +52,7 @@ func BuildPushImageForDeploy(service string, config *DeployConfigService, deploy
5152

5253
if buildConfig.Args != nil {
5354
for k, v := range *buildConfig.Args {
54-
dockerBuild.AppendArgs("--build-arg", fmt.Sprintf("%s=%s", k, v))
55+
dockerBuild.AppendArgs("--build-arg", fmt.Sprintf("%s=%s", k, parseDeployEnvs(v, deploy.Deploy.Environment.Env)))
5556
}
5657
}
5758

@@ -124,3 +125,23 @@ func parseBuild(build interface{}) (config *DeployConfigBuild, err error) {
124125
err = yaml.Unmarshal(b, config)
125126
return
126127
}
128+
129+
func parseDeployEnvs(i interface{}, env interface{}) string {
130+
// workaround to allow for escaping $ with a double $$
131+
_ = os.Setenv("$", "$")
132+
133+
var value = os.ExpandEnv(fmt.Sprintf("%s", i))
134+
135+
if strings.Contains(value, "{{") && strings.Contains(value, "}}") {
136+
// we have something to replace!
137+
if recs, ok := env.(map[string]interface{}); ok {
138+
for k, v := range recs {
139+
if strings.Contains(value, "{{"+k+"}}") {
140+
value = strings.ReplaceAll(value, "{{"+k+"}}", fmt.Sprintf("%v", v))
141+
}
142+
}
143+
}
144+
}
145+
146+
return value
147+
}

0 commit comments

Comments
 (0)