Skip to content

Commit

Permalink
Define constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rutvijmehta-harness committed Sep 25, 2023
1 parent 96e0636 commit cf1a731
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
14 changes: 13 additions & 1 deletion convert/harness/yaml/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

package yaml

const (
DefaultDockerConnector = "account.harnessImage"
)

type WhenStatus string

const (
Expand Down Expand Up @@ -85,7 +89,7 @@ type Shell string
const (
ShellNone Shell = "None"
ShellBash = "Bash"
ShellPosix = "Shell"
ShellPosix = "Sh"
ShellPowershell = "Powershell"
)

Expand All @@ -97,3 +101,11 @@ const (
ImagePullIfNotPresent = "IfNotPresent"
ImagePullNever = "Never"
)

type InfraOs string

const (
InfraOsLinux = "Linux"
InfraOsMac = "MacOS"
InfraOsWindows = "Windows"
)
26 changes: 13 additions & 13 deletions convert/rio/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit cf1a731

Please sign in to comment.