From cf1a7319a1f717984df35e454acad1a64cd79095 Mon Sep 17 00:00:00 2001 From: Rutvij Mehta Date: Mon, 25 Sep 2023 11:39:12 -0700 Subject: [PATCH] Define constants --- convert/harness/yaml/const.go | 14 +++++++++++++- convert/rio/convert.go | 26 +++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/convert/harness/yaml/const.go b/convert/harness/yaml/const.go index 6801c94d..99dbdc54 100644 --- a/convert/harness/yaml/const.go +++ b/convert/harness/yaml/const.go @@ -14,6 +14,10 @@ package yaml +const ( + DefaultDockerConnector = "account.harnessImage" +) + type WhenStatus string const ( @@ -85,7 +89,7 @@ type Shell string const ( ShellNone Shell = "None" ShellBash = "Bash" - ShellPosix = "Shell" + ShellPosix = "Sh" ShellPowershell = "Powershell" ) @@ -97,3 +101,11 @@ const ( ImagePullIfNotPresent = "IfNotPresent" ImagePullNever = "Never" ) + +type InfraOs string + +const ( + InfraOsLinux = "Linux" + InfraOsMac = "MacOS" + InfraOsWindows = "Windows" +) diff --git a/convert/rio/convert.go b/convert/rio/convert.go index 0ba62445..ac3d2bb0 100644 --- a/convert/rio/convert.go +++ b/convert/rio/convert.go @@ -58,7 +58,7 @@ func New(options ...Option) *Converter { // set default kubernetes OS if d.kubeOs == "" { - d.kubeOs = "Linux" + d.kubeOs = harness.InfraOsLinux } // set the runtime to kubernetes if the kubernetes @@ -69,7 +69,7 @@ func New(options ...Option) *Converter { // set default docker connector if d.dockerhubConn == "" { - d.dockerhubConn = "account.harnessImage" + d.dockerhubConn = harness.DefaultDockerConnector } return d @@ -118,7 +118,7 @@ func (d *Converter) convertRunStep(p rio.Pipeline) harness.StepRun { command += fmt.Sprintf("%s\n", s) } step.Command = command - step.Shell = "Sh" + step.Shell = harness.ShellPosix step.ConnRef = d.dockerhubConn step.Image = p.Machine.BaseImage return *step @@ -147,10 +147,10 @@ func (d *Converter) convertExecution(p rio.Pipeline) harness.Execution { if len(p.Build.Steps) != 0 { steps := harness.Steps{ Step: &harness.Step{ - Name: "run", - ID: "run", + Name: "Build", + ID: "Build", Spec: d.convertRunStep(p), - Type: "Run", + Type: harness.StepTypeRun, }, } executionSteps = append(executionSteps, &steps) @@ -171,10 +171,10 @@ func (d *Converter) convertExecution(p rio.Pipeline) harness.Execution { for _, dStep := range dockerSteps { steps := harness.Steps{ Step: &harness.Step{ - Name: fmt.Sprintf("docker_build_and_push_%d", dockerStepCounter), - ID: fmt.Sprintf("docker_build_and_push_%d", dockerStepCounter), + Name: fmt.Sprintf("BuildAndPush_%d", dockerStepCounter), + ID: fmt.Sprintf("BuildAndPush_%d", dockerStepCounter), Spec: &dStep, - Type: "BuildAndPushDockerRegistry", + Type: harness.StepTypeBuildAndPushDockerRegistry, }, } executionSteps = append(executionSteps, &steps) @@ -192,7 +192,7 @@ func (d *Converter) convertCIStage(p rio.Pipeline) harness.StageCI { } if d.kubeEnabled { infra := harness.Infrastructure{ - Type: "KubernetesDirect", + Type: harness.InfraTypeKubernetesDirect, Spec: &harness.InfraSpec{ Namespace: d.kubeNamespace, Conn: d.kubeConnector, @@ -205,7 +205,7 @@ func (d *Converter) convertCIStage(p rio.Pipeline) harness.StageCI { return stage } -func convertNameToID(name string) string { +func (d *Converter) convertNameToID(name string) string { ID := strings.ReplaceAll(name, " ", "_") ID = strings.ReplaceAll(ID, "-", "_") return ID @@ -219,9 +219,9 @@ func (d *Converter) convert(ctx *context) ([]byte, error) { stage := harness.Stages{ Stage: &harness.Stage{ Name: p.Name, - ID: convertNameToID(p.Name), + ID: d.convertNameToID(p.Name), Spec: d.convertCIStage(p), - Type: "CI", + Type: harness.StageTypeCI, }, } pipeline.Stages = append(pipeline.Stages, &stage)