Skip to content

Commit

Permalink
fix: SkipCiBuildCachePushPull code incorporated with minor refac in h…
Browse files Browse the repository at this point in the history
…andle runtime params validation (#5712)

* SkipCiBuildCachePushPull code incorporated with minor refac in handle runtime params validation

* minor refactor

* minor refactor
  • Loading branch information
prakash100198 authored Aug 22, 2024
1 parent 8de88d7 commit 378c2d9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions env_gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
| SCOPED_VARIABLE_HANDLE_PRIMITIVES | false | |
| SCOPED_VARIABLE_NAME_REGEX | ^[a-zA-Z][a-zA-Z0-9_-]{0,62}[a-zA-Z0-9]$ | |
| SHOW_DOCKER_BUILD_ARGS | true | |
| SKIP_CI_JOB_BUILD_CACHE_PUSH_PULL | false | |
| SKIP_CREATING_ECR_REPO | false | |
| SOCKET_DISCONNECT_DELAY_SECONDS | 5 | |
| SOCKET_HEARTBEAT_SECONDS | 25 | |
Expand Down
30 changes: 20 additions & 10 deletions pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,33 @@ func (impl *CiServiceImpl) GetCiMaterials(pipelineId int, ciMaterials []*pipelin
}
}

func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error) {
impl.Logger.Debug("ci pipeline manual trigger")
ciMaterials, err := impl.GetCiMaterials(trigger.PipelineId, trigger.CiMaterials)
if err != nil {
return 0, err
}

func (impl *CiServiceImpl) handleRuntimeParamsValidations(trigger types.Trigger, ciMaterials []*pipelineConfig.CiPipelineMaterial) error {
// checking if user has given run time parameters for externalCiArtifact, if given then sending git material to Ci-Runner
externalCiArtifact, exists := trigger.ExtraEnvironmentVariables["externalCiArtifact"]
externalCiArtifact, exists := trigger.ExtraEnvironmentVariables[CiPipeline.ExtraEnvVarExternalCiArtifactKey]
// validate externalCiArtifact as docker image
if exists {
if !strings.Contains(externalCiArtifact, ":") {
impl.Logger.Errorw("validation error", "externalCiArtifact", externalCiArtifact)
return 0, fmt.Errorf("invalid image name given in externalCiArtifact")
return fmt.Errorf("invalid image name given in externalCiArtifact")
}
}
if trigger.PipelineType == string(CiPipeline.CI_JOB) && len(ciMaterials) != 0 && !exists && externalCiArtifact == "" {
ciMaterials = []*pipelineConfig.CiPipelineMaterial{ciMaterials[0]}
ciMaterials[0].GitMaterial = nil
ciMaterials[0].GitMaterialId = 0
}
return nil
}

func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error) {
impl.Logger.Debug("ci pipeline manual trigger")
ciMaterials, err := impl.GetCiMaterials(trigger.PipelineId, trigger.CiMaterials)
if err != nil {
return 0, err
}
err = impl.handleRuntimeParamsValidations(trigger, ciMaterials)
if err != nil {
return 0, err
}
ciPipelineScripts, err := impl.ciPipelineRepository.FindCiScriptsByCiPipelineId(trigger.PipelineId)
if err != nil && !util.IsErrNoRows(err) {
return 0, err
Expand Down Expand Up @@ -741,6 +747,10 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
if pipeline.App.AppType == helper.Job {
workflowRequest.AppName = pipeline.App.DisplayName
}
if trigger.PipelineType == string(CiPipeline.CI_JOB) {
workflowRequest.IgnoreDockerCachePush = impl.config.SkipCiJobBuildCachePushPull
workflowRequest.IgnoreDockerCachePull = impl.config.SkipCiJobBuildCachePushPull
}
if dockerRegistry != nil {

workflowRequest.DockerRegistryId = dockerRegistry.Id
Expand Down
5 changes: 5 additions & 0 deletions pkg/pipeline/bean/CiPipeline/CiBuildConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ func (pType PipelineType) IsValidPipelineType() bool {
return false
}
}

const (
ExtraEnvVarExternalCiArtifactKey = "externalCiArtifact"
ExtraEnvVarImageDigestKey = "imageDigest"
)
1 change: 1 addition & 0 deletions pkg/pipeline/types/CiCdConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type CiCdConfig struct {
ImageScanRetryDelay int `env:"IMAGE_SCAN_RETRY_DELAY" envDefault:"5"`
ShowDockerBuildCmdInLogs bool `env:"SHOW_DOCKER_BUILD_ARGS" envDefault:"true"`
IgnoreCmCsInCiJob bool `env:"IGNORE_CM_CS_IN_CI_JOB" envDefault:"false"`
SkipCiJobBuildCachePushPull bool `env:"SKIP_CI_JOB_BUILD_CACHE_PUSH_PULL" envDefault:"false"`
// from CdConfig
CdLimitCpu string `env:"CD_LIMIT_CI_CPU" envDefault:"0.5"`
CdLimitMem string `env:"CD_LIMIT_CI_MEM" envDefault:"3G"`
Expand Down

0 comments on commit 378c2d9

Please sign in to comment.