Skip to content

Commit

Permalink
feat: feature flag BuildxCacheModeMin and AsyncBuildxCacheExport (#5307)
Browse files Browse the repository at this point in the history
* feat: added flags

* chore: change envs to caps

* chore: rename Buildx to BuildxCacheFlags

---------

Co-authored-by: Gireesh Naidu <gireesh@devtron.ai>
Co-authored-by: Gireesh Naidu <111440205+gireesh-devtron@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 26, 2024
1 parent 91240a5 commit 2378cdf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions env_gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| APP_SYNC_JOB_RESOURCES_OBJ | | |
| ARGO_APP_MANUAL_SYNC_TIME | 3 | |
| ARGO_AUTO_SYNC_ENABLED | true | |
| ASYNC_BUILDX_CACHE_EXPORT | false | |
| ARGO_GIT_COMMIT_RETRY_COUNT_ON_CONFLICT | 3 | |
| ARGO_GIT_COMMIT_RETRY_DELAY_ON_CONFLICT | 1 | |
| ARGO_REPO_REGISTER_RETRY_COUNT | 3 | |
Expand All @@ -31,6 +32,7 @@
| BLOB_STORAGE_S3_ENDPOINT | | |
| BLOB_STORAGE_S3_ENDPOINT_INSECURE | false | |
| BLOB_STORAGE_S3_SECRET_KEY | | |
| BUILDX_CACHE_MODE_MIN | false | |
| BUILDX_CACHE_PATH | /var/lib/devtron/buildx | |
| BUILDX_K8S_DRIVER_OPTIONS | | |
| BUILDX_PROVENANCE_MODE | | |
Expand Down
15 changes: 14 additions & 1 deletion pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/caarlos0/env"
"github.com/devtron-labs/devtron/pkg/infraConfig"
"github.com/devtron-labs/devtron/pkg/pipeline/adapter"
"github.com/devtron-labs/devtron/pkg/pipeline/bean/CiPipeline"
Expand Down Expand Up @@ -63,6 +64,10 @@ type CiService interface {
TriggerCiPipeline(trigger types.Trigger) (int, error)
GetCiMaterials(pipelineId int, ciMaterials []*pipelineConfig.CiPipelineMaterial) ([]*pipelineConfig.CiPipelineMaterial, error)
}
type BuildxCacheFlags struct {
BuildxCacheModeMin bool `env:"BUILDX_CACHE_MODE_MIN" envDefault:"false"`
AsyncBuildxCacheExport bool `env:"ASYNC_BUILDX_CACHE_EXPORT" envDefault:"false"`
}

type CiServiceImpl struct {
Logger *zap.SugaredLogger
Expand All @@ -85,6 +90,7 @@ type CiServiceImpl struct {
globalPluginService plugin.GlobalPluginService
infraProvider infraProviders.InfraProvider
ciCdPipelineOrchestrator CiCdPipelineOrchestrator
buildxCacheFlags *BuildxCacheFlags
}

func NewCiServiceImpl(Logger *zap.SugaredLogger, workflowService WorkflowService,
Expand All @@ -102,6 +108,11 @@ func NewCiServiceImpl(Logger *zap.SugaredLogger, workflowService WorkflowService
infraProvider infraProviders.InfraProvider,
ciCdPipelineOrchestrator CiCdPipelineOrchestrator,
) *CiServiceImpl {
buildxCacheFlags := &BuildxCacheFlags{}
err := env.Parse(buildxCacheFlags)
if err != nil {
Logger.Infow("error occurred while parsing BuildxCacheFlags env,so setting BuildxCacheModeMin and AsyncBuildxCacheExport to default value", "err", err)
}
cis := &CiServiceImpl{
Logger: Logger,
workflowService: workflowService,
Expand All @@ -122,6 +133,7 @@ func NewCiServiceImpl(Logger *zap.SugaredLogger, workflowService WorkflowService
globalPluginService: globalPluginService,
infraProvider: infraProvider,
ciCdPipelineOrchestrator: ciCdPipelineOrchestrator,
buildxCacheFlags: buildxCacheFlags,
}
config, err := types.GetCiConfig()
if err != nil {
Expand Down Expand Up @@ -240,7 +252,8 @@ func (impl *CiServiceImpl) TriggerCiPipeline(trigger types.Trigger) (int, error)
return 0, err
}
workflowRequest.Scope = scope

workflowRequest.BuildxCacheModeMin = impl.buildxCacheFlags.BuildxCacheModeMin
workflowRequest.AsyncBuildxCacheExport = impl.buildxCacheFlags.AsyncBuildxCacheExport
if impl.config != nil && impl.config.BuildxK8sDriverOptions != "" {
err = impl.setBuildxK8sDriverData(workflowRequest)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipeline/types/Workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ type WorkflowRequest struct {
Env *repository.Environment
AppLabels map[string]string
Scope resourceQualifiers.Scope
BuildxCacheModeMin bool `json:"buildxCacheModeMin"`
AsyncBuildxCacheExport bool `json:"asyncBuildxCacheExport"`
}

func (workflowRequest *WorkflowRequest) updateExternalRunMetadata() {
Expand Down

0 comments on commit 2378cdf

Please sign in to comment.