Skip to content

Commit

Permalink
Update runner to use params-file instead of multiple params arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeEvansLarah committed Dec 18, 2019
1 parent 58b5e79 commit cab75b2
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions pkg/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,18 @@ func Run() error {
cnabAction := config.cnabAction
cnabInstallationName := config.cnabInstallationName

cnabParams := getCnabParams()

credsPath, err := generateCredsFile(cnabInstallationName)
if err != nil {
log.Fatalf("generateCredsFile command failed with %s\n", err)
}

cmdParams := []string{cnabAction, cnabInstallationName, "-d", "azure", "--tag", cnabBundleTag, "--cred", credsPath}

for i := range cnabParams {
cmdParams = append(cmdParams, "--param")
cmdParams = append(cmdParams, strings.TrimPrefix(cnabParams[i], common.GetEnvironmentVariableNames().CnabParameterPrefix))
paramsPath, err := generateParamsFile(cnabInstallationName)
if err != nil {
log.Fatalf("generateParamsFile command failed with %s\n", err)
}

cmdParams := []string{cnabAction, cnabInstallationName, "-d", "azure", "--tag", cnabBundleTag, "--cred", credsPath, "--param-file", paramsPath}

cmd := exec.Command("porter", cmdParams...)
log.Println(cmd.String())
cmd.Stdout = os.Stdout
Expand Down Expand Up @@ -136,7 +134,7 @@ func generateCredsFile(cnabInstallationName string) (string, error) {
creds.Credentials = append(creds.Credentials, credentialStrategy)
}

credFileName := cnabInstallationName + ".yaml"
credFileName := cnabInstallationName + "-creds.yaml"
credPath := path.Join(tempDir, credFileName)

credData, _ := yaml.Marshal(creds)
Expand All @@ -148,6 +146,28 @@ func generateCredsFile(cnabInstallationName string) (string, error) {
return credPath, nil
}

func generateParamsFile(cnabInstallationName string) (string, error) {
tempDir, _ := ioutil.TempDir("", "cnabarmdriver")

cnabParams := getCnabParams()

paramsFileName := cnabInstallationName + "-params.txt"
paramsPath := path.Join(tempDir, paramsFileName)

var b strings.Builder
for i, p := range cnabParams {
p = strings.TrimPrefix(cnabParams[i], common.GetEnvironmentVariableNames().CnabParameterPrefix)
fmt.Fprintf(&b, "%s\n", p)
}
paramsData := b.String()

if err := ioutil.WriteFile(paramsPath, []byte(paramsData), 0644); err != nil {
return "", err
}

return paramsPath, nil
}

func getCnabParams() []string {
return getEnvVarsStartingWith(common.GetEnvironmentVariableNames().CnabParameterPrefix)
}
Expand Down

0 comments on commit cab75b2

Please sign in to comment.