Skip to content

Commit

Permalink
parsing variables on local images build for deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciojs committed Feb 29, 2024
1 parent 9b31f94 commit 2c92225
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion services/cloud/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"kool-dev/kool/core/environment"
"kool-dev/kool/core/shell"
"kool-dev/kool/services/cloud/api"
"os"
"path/filepath"
"strings"

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

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

Expand Down Expand Up @@ -124,3 +125,23 @@ func parseBuild(build interface{}) (config *DeployConfigBuild, err error) {
err = yaml.Unmarshal(b, config)
return
}

func parseDeployEnvs(i interface{}, env interface{}) string {
// workaround to allow for escaping $ with a double $$
_ = os.Setenv("$", "$")

var value = os.ExpandEnv(fmt.Sprintf("%s", i))

if strings.Contains(value, "{{") && strings.Contains(value, "}}") {
// we have something to replace!
if recs, ok := env.(map[string]interface{}); ok {
for k, v := range recs {
if strings.Contains(value, "{{"+k+"}}") {
value = strings.ReplaceAll(value, "{{"+k+"}}", fmt.Sprintf("%v", v))
}
}
}
}

return value
}

0 comments on commit 2c92225

Please sign in to comment.