Skip to content

Commit cfab5b4

Browse files
committed
Merge branch 'develop' of github.com:devtron-labs/devtron into copy-image-plugin-panic
2 parents 421df9e + cace927 commit cfab5b4

File tree

9 files changed

+151
-29
lines changed

9 files changed

+151
-29
lines changed

pkg/bean/app.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
2626
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/imageTagging"
2727
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
28+
"github.com/devtron-labs/devtron/pkg/bean/common"
2829
CiPipeline2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
2930
"github.com/devtron-labs/devtron/pkg/chartRepo/repository"
3031
bean3 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean"
@@ -61,6 +62,12 @@ type CreateAppDTO struct {
6162
DisplayName string `json:"-"` //not exposed to UI
6263
}
6364

65+
type WorkflowCacheConfig struct {
66+
Type common.WorkflowCacheConfigType `json:"type"`
67+
Value bool `json:"value"`
68+
GlobalValue bool `json:"globalValue"`
69+
}
70+
6471
type CreateMaterialDTO struct {
6572
Id int `json:"id,omitempty" validate:"number"`
6673
AppId int `json:"appId" validate:"number"`

pkg/bean/common/pipeline.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,9 @@ const (
9999
// SystemVariableScope is used to define the global variable scope.
100100
SystemVariableScope VariableStepScope = "SYSTEM"
101101
)
102+
103+
type WorkflowCacheConfigType string
104+
105+
const (
106+
WorkflowCacheConfigInherit WorkflowCacheConfigType = "INHERIT"
107+
)

pkg/pipeline/CiCdPipelineOrchestrator.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ import (
2727
"fmt"
2828
constants2 "github.com/devtron-labs/devtron/internal/sql/constants"
2929
attributesBean "github.com/devtron-labs/devtron/pkg/attributes/bean"
30+
common2 "github.com/devtron-labs/devtron/pkg/bean/common"
3031
repository6 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository"
3132
"github.com/devtron-labs/devtron/pkg/build/pipeline"
3233
bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
3334
repository2 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
3435
"github.com/devtron-labs/devtron/pkg/deployment/common"
3536
"github.com/devtron-labs/devtron/pkg/deployment/gitOps/config"
37+
constants3 "github.com/devtron-labs/devtron/pkg/pipeline/constants"
38+
util4 "github.com/devtron-labs/devtron/pkg/pipeline/util"
3639
"github.com/devtron-labs/devtron/pkg/plugin"
3740
"golang.org/x/exp/slices"
3841
"net/http"
@@ -110,6 +113,7 @@ type CiCdPipelineOrchestrator interface {
110113
GetSourceCiDownStreamInfo(ctx context.Context, sourceCIPipeline int, req *bean2.SourceCiDownStreamFilters) (pagination.PaginatedResponse[bean2.SourceCiDownStreamResponse], error)
111114
GetSourceCiPipelineForArtifact(ciPipeline pipelineConfig.CiPipeline) (*pipelineConfig.CiPipeline, error)
112115
GetGitCommitEnvVarDataForCICDStage(gitTriggers map[int]pipelineConfig.GitCommit) (map[string]string, *gitSensor.WebhookAndCiData, error)
116+
GetWorkflowCacheConfig(appType helper.AppType, pipelineType string, pipelineWorkflowCacheConfig common2.WorkflowCacheConfigType) bean.WorkflowCacheConfig
113117
}
114118

115119
type CiCdPipelineOrchestratorImpl struct {
@@ -142,6 +146,7 @@ type CiCdPipelineOrchestratorImpl struct {
142146
transactionManager sql.TransactionWrapper
143147
gitOpsConfigReadService config.GitOpsConfigReadService
144148
deploymentConfigService common.DeploymentConfigService
149+
workflowCacheConfig types.WorkflowCacheConfig
145150
}
146151

147152
func NewCiCdPipelineOrchestrator(
@@ -172,6 +177,10 @@ func NewCiCdPipelineOrchestrator(
172177
chartService chart.ChartService, transactionManager sql.TransactionWrapper,
173178
gitOpsConfigReadService config.GitOpsConfigReadService,
174179
deploymentConfigService common.DeploymentConfigService) *CiCdPipelineOrchestratorImpl {
180+
_, workflowCacheConfig, err := types.GetCiConfigWithWorkflowCacheConfig()
181+
if err != nil {
182+
logger.Errorw("Error in getting workflow cache config, continuing with default values", "err", err)
183+
}
175184
return &CiCdPipelineOrchestratorImpl{
176185
appRepository: pipelineGroupRepository,
177186
logger: logger,
@@ -202,6 +211,7 @@ func NewCiCdPipelineOrchestrator(
202211
transactionManager: transactionManager,
203212
gitOpsConfigReadService: gitOpsConfigReadService,
204213
deploymentConfigService: deploymentConfigService,
214+
workflowCacheConfig: workflowCacheConfig,
205215
}
206216
}
207217

@@ -2419,3 +2429,15 @@ func (impl *CiCdPipelineOrchestratorImpl) GetGitCommitEnvVarDataForCICDStage(git
24192429

24202430
return extraEnvVariables, webhookAndCiData, nil
24212431
}
2432+
2433+
func (impl *CiCdPipelineOrchestratorImpl) GetWorkflowCacheConfig(appType helper.AppType, pipelineType string, pipelineWorkflowCacheConfig common2.WorkflowCacheConfigType) bean.WorkflowCacheConfig {
2434+
if appType == helper.Job {
2435+
return util4.GetWorkflowCacheConfig(pipelineWorkflowCacheConfig, impl.workflowCacheConfig.IgnoreJob)
2436+
} else {
2437+
if pipelineType == string(constants3.CI_JOB) {
2438+
return util4.GetWorkflowCacheConfigWithBackwardCompatibility(pipelineWorkflowCacheConfig, impl.ciConfig.WorkflowCacheConfig, impl.workflowCacheConfig.IgnoreCIJob, impl.ciConfig.SkipCiJobBuildCachePushPull)
2439+
} else {
2440+
return util4.GetWorkflowCacheConfigWithBackwardCompatibility(pipelineWorkflowCacheConfig, impl.ciConfig.WorkflowCacheConfig, impl.workflowCacheConfig.IgnoreCI, impl.ciConfig.IgnoreDockerCacheForCI)
2441+
}
2442+
}
2443+
}

pkg/pipeline/CiService.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow"
2929
"github.com/devtron-labs/devtron/pkg/attributes"
3030
bean4 "github.com/devtron-labs/devtron/pkg/attributes/bean"
31+
"github.com/devtron-labs/devtron/pkg/bean/common"
3132
"github.com/devtron-labs/devtron/pkg/build/pipeline"
3233
bean6 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
3334
repository6 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
@@ -829,8 +830,6 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
829830
TriggerByAuthor: userEmailId,
830831
CiBuildConfig: ciBuildConfigBean,
831832
CiBuildDockerMtuValue: impl.config.CiRunnerDockerMTUValue,
832-
IgnoreDockerCachePush: impl.config.IgnoreDockerCacheForCI,
833-
IgnoreDockerCachePull: impl.config.IgnoreDockerCacheForCI,
834833
CacheInvalidate: trigger.InvalidateCache,
835834
SystemEnvironmentVariables: trigger.RuntimeParameters.GetSystemVariables(),
836835
EnableBuildContext: impl.config.EnableBuildContext,
@@ -852,12 +851,13 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
852851
if pipeline.App.AppType == helper.Job {
853852
workflowRequest.AppName = pipeline.App.DisplayName
854853
}
855-
if trigger.PipelineType == string(bean6.CI_JOB) {
856-
workflowRequest.IgnoreDockerCachePush = impl.config.SkipCiJobBuildCachePushPull
857-
workflowRequest.IgnoreDockerCachePull = impl.config.SkipCiJobBuildCachePushPull
858-
}
859-
if dockerRegistry != nil {
854+
//in oss, there is no pipeline level workflow cache config, so we pass inherit to get the app level config
855+
workflowCacheConfig := impl.ciCdPipelineOrchestrator.GetWorkflowCacheConfig(pipeline.App.AppType, trigger.PipelineType, common.WorkflowCacheConfigInherit)
856+
workflowRequest.IgnoreDockerCachePush = !workflowCacheConfig.Value
857+
workflowRequest.IgnoreDockerCachePull = !workflowCacheConfig.Value
858+
impl.Logger.Debugw("Ignore Cache values", "IgnoreDockerCachePush", workflowRequest.IgnoreDockerCachePush, "IgnoreDockerCachePull", workflowRequest.IgnoreDockerCachePull)
860859

860+
if dockerRegistry != nil {
861861
workflowRequest.DockerRegistryId = dockerRegistry.Id
862862
workflowRequest.DockerRegistryType = string(dockerRegistry.RegistryType)
863863
workflowRequest.DockerImageTag = dockerImageTag

pkg/pipeline/types/CiCdConfig.go

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,30 @@ type CancelWfRequestDto struct {
5454

5555
type CiCdConfig struct {
5656
// from ciConfig
57-
DefaultCacheBucket string `env:"DEFAULT_CACHE_BUCKET" envDefault:"ci-caching"`
58-
DefaultCacheBucketRegion string `env:"DEFAULT_CACHE_BUCKET_REGION" envDefault:"us-east-2"`
59-
CiLogsKeyPrefix string `env:"CI_LOGS_KEY_PREFIX" envDxefault:"my-artifacts"`
60-
CiDefaultImage string `env:"DEFAULT_CI_IMAGE" envDefault:"686244538589.dkr.ecr.us-east-2.amazonaws.com/cirunner:47"`
61-
CiDefaultNamespace string `env:"DEFAULT_NAMESPACE" envDefault:"devtron-ci"`
62-
CiDefaultBuildLogsBucket string `env:"DEFAULT_BUILD_LOGS_BUCKET" envDefault:"devtron-pro-ci-logs"`
63-
CiDefaultCdLogsBucketRegion string `env:"DEFAULT_CD_LOGS_BUCKET_REGION" envDefault:"us-east-2"`
64-
CiTaintKey string `env:"CI_NODE_TAINTS_KEY" envDefault:""`
65-
CiTaintValue string `env:"CI_NODE_TAINTS_VALUE" envDefault:""`
66-
CiNodeLabelSelector []string `env:"CI_NODE_LABEL_SELECTOR"`
67-
CacheLimit int64 `env:"CACHE_LIMIT" envDefault:"5000000000"` // TODO: Add to default db config also
68-
CiDefaultBuildLogsKeyPrefix string `env:"DEFAULT_BUILD_LOGS_KEY_PREFIX" envDefault:"arsenal-v1"`
69-
CiDefaultArtifactKeyPrefix string `env:"DEFAULT_ARTIFACT_KEY_LOCATION" envDefault:"arsenal-v1/ci-artifacts"`
70-
CiWorkflowServiceAccount string `env:"WORKFLOW_SERVICE_ACCOUNT" envDefault:"ci-runner"`
71-
ExternalCiApiSecret string `env:"EXTERNAL_CI_API_SECRET" envDefault:"devtroncd-secret"`
72-
ExternalCiWebhookUrl string `env:"EXTERNAL_CI_WEB_HOOK_URL" envDefault:""`
73-
ExternalCiPayload string `env:"EXTERNAL_CI_PAYLOAD" envDefault:"{\"ciProjectDetails\":[{\"gitRepository\":\"https://github.com/vikram1601/getting-started-nodejs.git\",\"checkoutPath\":\"./abc\",\"commitHash\":\"239077135f8cdeeccb7857e2851348f558cb53d3\",\"commitTime\":\"2022-10-30T20:00:00\",\"branch\":\"master\",\"message\":\"Update README.md\",\"author\":\"User Name \"}],\"dockerImage\":\"445808685819.dkr.ecr.us-east-2.amazonaws.com/orch:23907713-2\"}"`
74-
ImageScannerEndpoint string `env:"IMAGE_SCANNER_ENDPOINT" envDefault:"http://image-scanner-new-demo-devtroncd-service.devtroncd:80"`
75-
CiDefaultAddressPoolBaseCidr string `env:"CI_DEFAULT_ADDRESS_POOL_BASE_CIDR"`
76-
CiDefaultAddressPoolSize int `env:"CI_DEFAULT_ADDRESS_POOL_SIZE"`
77-
CiRunnerDockerMTUValue int `env:"CI_RUNNER_DOCKER_MTU_VALUE" envDefault:"-1"`
57+
DefaultCacheBucket string `env:"DEFAULT_CACHE_BUCKET" envDefault:"ci-caching"`
58+
DefaultCacheBucketRegion string `env:"DEFAULT_CACHE_BUCKET_REGION" envDefault:"us-east-2"`
59+
CiLogsKeyPrefix string `env:"CI_LOGS_KEY_PREFIX" envDxefault:"my-artifacts"`
60+
CiDefaultImage string `env:"DEFAULT_CI_IMAGE" envDefault:"686244538589.dkr.ecr.us-east-2.amazonaws.com/cirunner:47"`
61+
CiDefaultNamespace string `env:"DEFAULT_NAMESPACE" envDefault:"devtron-ci"`
62+
CiDefaultBuildLogsBucket string `env:"DEFAULT_BUILD_LOGS_BUCKET" envDefault:"devtron-pro-ci-logs"`
63+
CiDefaultCdLogsBucketRegion string `env:"DEFAULT_CD_LOGS_BUCKET_REGION" envDefault:"us-east-2"`
64+
CiTaintKey string `env:"CI_NODE_TAINTS_KEY" envDefault:""`
65+
CiTaintValue string `env:"CI_NODE_TAINTS_VALUE" envDefault:""`
66+
CiNodeLabelSelector []string `env:"CI_NODE_LABEL_SELECTOR"`
67+
CacheLimit int64 `env:"CACHE_LIMIT" envDefault:"5000000000"` // TODO: Add to default db config also
68+
CiDefaultBuildLogsKeyPrefix string `env:"DEFAULT_BUILD_LOGS_KEY_PREFIX" envDefault:"arsenal-v1"`
69+
CiDefaultArtifactKeyPrefix string `env:"DEFAULT_ARTIFACT_KEY_LOCATION" envDefault:"arsenal-v1/ci-artifacts"`
70+
CiWorkflowServiceAccount string `env:"WORKFLOW_SERVICE_ACCOUNT" envDefault:"ci-runner"`
71+
ExternalCiApiSecret string `env:"EXTERNAL_CI_API_SECRET" envDefault:"devtroncd-secret"`
72+
ExternalCiWebhookUrl string `env:"EXTERNAL_CI_WEB_HOOK_URL" envDefault:""`
73+
ExternalCiPayload string `env:"EXTERNAL_CI_PAYLOAD" envDefault:"{\"ciProjectDetails\":[{\"gitRepository\":\"https://github.com/vikram1601/getting-started-nodejs.git\",\"checkoutPath\":\"./abc\",\"commitHash\":\"239077135f8cdeeccb7857e2851348f558cb53d3\",\"commitTime\":\"2022-10-30T20:00:00\",\"branch\":\"master\",\"message\":\"Update README.md\",\"author\":\"User Name \"}],\"dockerImage\":\"445808685819.dkr.ecr.us-east-2.amazonaws.com/orch:23907713-2\"}"`
74+
ImageScannerEndpoint string `env:"IMAGE_SCANNER_ENDPOINT" envDefault:"http://image-scanner-new-demo-devtroncd-service.devtroncd:80"`
75+
CiDefaultAddressPoolBaseCidr string `env:"CI_DEFAULT_ADDRESS_POOL_BASE_CIDR"`
76+
CiDefaultAddressPoolSize int `env:"CI_DEFAULT_ADDRESS_POOL_SIZE"`
77+
CiRunnerDockerMTUValue int `env:"CI_RUNNER_DOCKER_MTU_VALUE" envDefault:"-1"`
78+
//Deprecated: use WorkflowCacheConfig instead
7879
IgnoreDockerCacheForCI bool `env:"CI_IGNORE_DOCKER_CACHE"`
80+
WorkflowCacheConfig string `env:"WORKFLOW_CACHE_CONFIG" envDefault:"{}"`
7981
VolumeMountsForCiJson string `env:"CI_VOLUME_MOUNTS_JSON"`
8082
BuildPvcCachePath string `env:"PRE_CI_CACHE_PATH" envDefault:"/devtroncd-cache"`
8183
DefaultPvcCachePath string `env:"DOCKER_BUILD_CACHE_PATH" envDefault:"/var/lib/docker"`
@@ -96,7 +98,8 @@ type CiCdConfig struct {
9698
ImageScanRetryDelay int `env:"IMAGE_SCAN_RETRY_DELAY" envDefault:"5"`
9799
ShowDockerBuildCmdInLogs bool `env:"SHOW_DOCKER_BUILD_ARGS" envDefault:"true"`
98100
IgnoreCmCsInCiJob bool `env:"IGNORE_CM_CS_IN_CI_JOB" envDefault:"false"`
99-
SkipCiJobBuildCachePushPull bool `env:"SKIP_CI_JOB_BUILD_CACHE_PUSH_PULL" envDefault:"false"`
101+
//Deprecated: use WorkflowCacheConfig instead
102+
SkipCiJobBuildCachePushPull bool `env:"SKIP_CI_JOB_BUILD_CACHE_PUSH_PULL" envDefault:"false"`
100103
// from CdConfig
101104
CdLimitCpu string `env:"CD_LIMIT_CI_CPU" envDefault:"0.5"`
102105
CdLimitMem string `env:"CD_LIMIT_CI_MEM" envDefault:"3G"`
@@ -194,6 +197,28 @@ func GetCiConfig() (*CiConfig, error) {
194197
ciConfig.Type = CiConfigType
195198
return &ciConfig, nil
196199
}
200+
201+
func GetCiConfigWithWorkflowCacheConfig() (*CiConfig, WorkflowCacheConfig, error) {
202+
ciConfig, err := GetCiConfig()
203+
if err != nil {
204+
return nil, WorkflowCacheConfig{}, err
205+
}
206+
workflowCacheConfig, err := getWorkflowCacheConfig(ciConfig.WorkflowCacheConfig)
207+
if err != nil {
208+
return nil, WorkflowCacheConfig{}, err
209+
}
210+
return ciConfig, workflowCacheConfig, nil
211+
}
212+
213+
func getWorkflowCacheConfig(workflowCacheConfigEnv string) (WorkflowCacheConfig, error) {
214+
workflowCacheConfig := WorkflowCacheConfig{}
215+
err := json.Unmarshal([]byte(workflowCacheConfigEnv), &workflowCacheConfig)
216+
if err != nil {
217+
return WorkflowCacheConfig{}, err
218+
}
219+
return workflowCacheConfig, nil
220+
}
221+
197222
func GetCdConfig() (*CdConfig, error) {
198223
ciCdConfig := &CiCdConfig{}
199224
err := env.Parse(ciCdConfig)
@@ -603,3 +628,9 @@ func DecodeSecretKey(secretKey string) string {
603628
}
604629
return string(decodedKey)
605630
}
631+
632+
type WorkflowCacheConfig struct {
633+
IgnoreCI bool `json:"ignoreCI"`
634+
IgnoreCIJob bool `json:"ignoreCIJob"`
635+
IgnoreJob bool `json:"ignoreJob"`
636+
}

pkg/pipeline/util/CiCdUtil.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
package util
22

33
import (
4+
"github.com/devtron-labs/devtron/pkg/bean"
5+
"github.com/devtron-labs/devtron/pkg/bean/common"
6+
"github.com/devtron-labs/devtron/util"
47
"github.com/devtron-labs/devtron/util/urlUtil"
58
)
69

710
func IsValidUrlSubPath(subPath string) bool {
811
url := "http://127.0.0.1:8080/" + subPath
912
return urlUtil.IsValidUrl(url)
1013
}
14+
15+
// in oss, only WorkflowCacheConfigInherit is supported
16+
func GetWorkflowCacheConfig(WorkflowCacheConfig common.WorkflowCacheConfigType, globalValue bool) bean.WorkflowCacheConfig {
17+
//explicitly return inherit here to handle empty case
18+
return bean.WorkflowCacheConfig{
19+
Type: common.WorkflowCacheConfigInherit,
20+
Value: !globalValue,
21+
GlobalValue: !globalValue,
22+
}
23+
}
24+
25+
// in oss, only WorkflowCacheConfigInherit is supported
26+
func GetWorkflowCacheConfigWithBackwardCompatibility(WorkflowCacheConfig common.WorkflowCacheConfigType, WorkflowCacheConfigEnv string, globalValue bool, oldGlobalValue bool) bean.WorkflowCacheConfig {
27+
isEmptyJson, _ := util.IsEmptyJSONForJsonString(WorkflowCacheConfigEnv)
28+
//TODO: error handling in next phase
29+
if isEmptyJson {
30+
//this means new global flag is not configured
31+
return bean.WorkflowCacheConfig{
32+
Type: common.WorkflowCacheConfigInherit,
33+
Value: !oldGlobalValue,
34+
GlobalValue: !oldGlobalValue,
35+
}
36+
} else {
37+
return bean.WorkflowCacheConfig{
38+
Type: common.WorkflowCacheConfigInherit,
39+
Value: !globalValue,
40+
GlobalValue: !globalValue,
41+
}
42+
}
43+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "public"."ci_pipeline" DROP COLUMN IF EXISTS "workflow_cache_config";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "public"."ci_pipeline" ADD COLUMN IF NOT EXISTS "workflow_cache_config" varchar(50);

util/JsonHelper.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package util
2+
3+
import "encoding/json"
4+
5+
// IsEmptyJSON checks if a given string represents an empty JSON object
6+
func IsEmptyJSONForJsonString(jsonStr string) (bool, error) {
7+
var data interface{}
8+
err := json.Unmarshal([]byte(jsonStr), &data)
9+
if err != nil {
10+
// If unmarshaling fails, it's not valid JSON
11+
return false, err
12+
}
13+
14+
// Check if data is an empty map
15+
if obj, ok := data.(map[string]interface{}); ok {
16+
return len(obj) == 0, nil
17+
}
18+
19+
// If not a JSON object, return false
20+
return false, nil
21+
}

0 commit comments

Comments
 (0)