Skip to content

Commit c1fa369

Browse files
authored
Merge branch 'main' into v0.4.27-hotfix
2 parents a47aeb9 + 717d4ab commit c1fa369

File tree

14 files changed

+58
-49
lines changed

14 files changed

+58
-49
lines changed

api/appbean/AppDetail.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type DockerBuildConfig struct {
4343
GitCheckoutPath string `json:"gitCheckoutPath,omitempty" validate:"required"`
4444
DockerfileRelativePath string `json:"dockerfileRelativePath,omitempty" validate:"required"`
4545
Args map[string]string `json:"args,omitempty"`
46+
TargetPlatform string `json:"targetPlatform"`
4647
}
4748

4849
type DeploymentTemplate struct {

api/restHandler/CoreAppRestHandler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ func (handler CoreAppRestHandlerImpl) buildDockerConfig(appId int) (*appBean.Doc
497497
BuildConfig: &appBean.DockerBuildConfig{
498498
Args: ciConfig.DockerBuildConfig.Args,
499499
DockerfileRelativePath: ciConfig.DockerBuildConfig.DockerfilePath,
500+
TargetPlatform: ciConfig.DockerBuildConfig.TargetPlatform,
500501
GitCheckoutPath: gitMaterial.CheckoutPath,
501502
},
502503
}
@@ -1256,6 +1257,7 @@ func (handler CoreAppRestHandlerImpl) createDockerConfig(appId int, dockerConfig
12561257
GitMaterialId: gitMaterial.Id,
12571258
DockerfilePath: dockerConfig.BuildConfig.DockerfileRelativePath,
12581259
Args: dockerBuildArgs,
1260+
TargetPlatform: dockerConfig.BuildConfig.TargetPlatform,
12591261
}
12601262
createDockerConfigRequest.DockerBuildConfig = dockerBuildConfigRequest
12611263

internal/sql/repository/pipelineConfig/CiTemplateRepository.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type CiTemplate struct {
3333
DockerRegistryId string `sql:"docker_registry_id"` //foreign key of registry
3434
DockerRepository string `sql:"docker_repository"`
3535
DockerfilePath string `sql:"dockerfile_path"`
36-
Args string `sql:"args"` //json string format of map[string]string
36+
Args string `sql:"args"` //json string format of map[string]string
37+
TargetPlatform string `sql:"target_platform,notnull"`
3738
BeforeDockerBuild string `sql:"before_docker_build"` //json string format of []*Task
3839
AfterDockerBuild string `sql:"after_docker_build"` //json string format of []*Task
3940
TemplateName string `sql:"template_name"`

internal/util/ChartService.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ func (impl ChartTemplateServiceImpl) pushChartToGitRepo(gitOpsRepoName, referenc
264264
}
265265

266266
dir := filepath.Join(clonedDir, referenceTemplate, version)
267+
pushChartToGit := true
268+
267269
//if chart already exists don't overrides it by reference template
268270
if _, err := os.Stat(dir); os.IsNotExist(err) {
269271
err = os.MkdirAll(dir, os.ModePerm)
@@ -287,30 +289,37 @@ func (impl ChartTemplateServiceImpl) pushChartToGitRepo(gitOpsRepoName, referenc
287289
impl.logger.Errorw("error copying content in auto-healing", "err", err)
288290
return err
289291
}
292+
} else {
293+
// chart exists on git, hence not performing first commit
294+
pushChartToGit = false
290295
}
291296
}
292297

293-
userEmailId, userName := impl.GetUserEmailIdAndNameForGitOpsCommit(userId)
294-
commit, err := impl.gitFactory.gitService.CommitAndPushAllChanges(clonedDir, "first commit", userName, userEmailId)
295-
if err != nil {
296-
impl.logger.Errorw("error in pushing git", "err", err)
297-
impl.logger.Warn("re-trying, taking pull and then push again")
298-
err = impl.GitPull(clonedDir, repoUrl, gitOpsRepoName)
299-
if err != nil {
300-
return err
301-
}
302-
err = dirCopy.Copy(tempReferenceTemplateDir, dir)
303-
if err != nil {
304-
impl.logger.Errorw("error copying dir", "err", err)
305-
return err
306-
}
307-
commit, err = impl.gitFactory.gitService.CommitAndPushAllChanges(clonedDir, "first commit", userName, userEmailId)
298+
// if push needed, then only push
299+
if pushChartToGit {
300+
userEmailId, userName := impl.GetUserEmailIdAndNameForGitOpsCommit(userId)
301+
commit, err := impl.gitFactory.gitService.CommitAndPushAllChanges(clonedDir, "first commit", userName, userEmailId)
308302
if err != nil {
309303
impl.logger.Errorw("error in pushing git", "err", err)
310-
return err
304+
impl.logger.Warn("re-trying, taking pull and then push again")
305+
err = impl.GitPull(clonedDir, repoUrl, gitOpsRepoName)
306+
if err != nil {
307+
return err
308+
}
309+
err = dirCopy.Copy(tempReferenceTemplateDir, dir)
310+
if err != nil {
311+
impl.logger.Errorw("error copying dir", "err", err)
312+
return err
313+
}
314+
commit, err = impl.gitFactory.gitService.CommitAndPushAllChanges(clonedDir, "first commit", userName, userEmailId)
315+
if err != nil {
316+
impl.logger.Errorw("error in pushing git", "err", err)
317+
return err
318+
}
311319
}
320+
impl.logger.Debugw("template committed", "url", repoUrl, "commit", commit)
312321
}
313-
impl.logger.Debugw("template committed", "url", repoUrl, "commit", commit)
322+
314323
defer impl.CleanDir(clonedDir)
315324
return nil
316325
}

pkg/appClone/AppCloneService.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ func (impl *AppCloneServiceImpl) CreateCiTemplate(oldAppId, newAppId int, userId
276276
GitMaterialId: dockerfileGitMaterial,
277277
DockerfilePath: refCiConf.DockerBuildConfig.DockerfilePath,
278278
Args: refCiConf.DockerBuildConfig.Args,
279+
TargetPlatform: refCiConf.DockerBuildConfig.TargetPlatform,
279280
},
280281
DockerRegistryUrl: refCiConf.DockerRegistry,
281282
CiTemplateName: refCiConf.CiTemplateName,

pkg/bean/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type CiPipeline struct {
102102
AppWorkflowId int `json:"appWorkflowId,omitempty"`
103103
PreBuildStage *bean.PipelineStageDto `json:"preBuildStage,omitempty"`
104104
PostBuildStage *bean.PipelineStageDto `json:"postBuildStage,omitempty"`
105+
TargetPlatform string `json:"targetPlatform,omitempty"`
105106
}
106107

107108
type CiPipelineMin struct {
@@ -259,6 +260,7 @@ type DockerBuildConfig struct {
259260
GitMaterialId int `json:"gitMaterialId,omitempty" validate:"required"`
260261
DockerfilePath string `json:"dockerfileRelativePath,omitempty" validate:"required"`
261262
Args map[string]string `json:"args,omitempty"`
263+
TargetPlatform string `json:"targetPlatform"`
262264
//Name Tag DockerfilePath RepoUrl
263265
}
264266

pkg/notifier/NotificationConfigBuilder.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/devtron-labs/devtron/internal/sql/repository"
2323
"github.com/devtron-labs/devtron/util/event"
2424
"go.uber.org/zap"
25-
"strings"
2625
"time"
2726
)
2827

@@ -170,17 +169,7 @@ func (impl NotificationConfigBuilderImpl) buildNotificationSetting(notificationS
170169
}
171170

172171
func (impl NotificationConfigBuilderImpl) BuildNotificationSettingWithPipeline(teamId *int, envId *int, appId *int, pipelineId *int, pipelineType util.PipelineType, eventTypeId int, viewId int, providers []*Provider) (repository.NotificationSettings, error) {
173-
174-
for _, provider := range providers {
175-
if len(provider.Recipient) > 0 {
176-
if strings.Contains(provider.Recipient, "@") {
177-
provider.Destination = util.SES
178-
} else {
179-
provider.Destination = util.Slack
180-
}
181-
}
182-
}
183-
172+
184173
providersJson, err := json.Marshal(providers)
185174
if err != nil {
186175
impl.logger.Error(err)

pkg/notifier/NotificationConfigService.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
repository3 "github.com/devtron-labs/devtron/pkg/cluster/repository"
2424
repository2 "github.com/devtron-labs/devtron/pkg/team"
2525
repository4 "github.com/devtron-labs/devtron/pkg/user/repository"
26-
"strings"
2726
"time"
2827

2928
"github.com/devtron-labs/devtron/internal/sql/repository"
@@ -368,19 +367,21 @@ func (impl *NotificationConfigServiceImpl) BuildNotificationSettingsResponse(not
368367
var slackIds []*int
369368
var sesUserIds []int32
370369
var smtpUserIds []int32
371-
var directRecipients []string
370+
var providerConfigs []*ProvidersConfig
372371
for _, item := range config.Providers {
373-
if item.Destination == util.Slack {
374-
slackIds = append(slackIds, &item.ConfigId)
375-
} else if item.Destination == util.SES {
376-
sesUserIds = append(sesUserIds, int32(item.ConfigId))
377-
} else if item.Destination == util.SMTP {
378-
smtpUserIds = append(smtpUserIds, int32(item.ConfigId))
372+
// if item.ConfigId > 0 that means, user is of user repository, else user email is custom
373+
if item.ConfigId > 0 {
374+
if item.Destination == util.Slack {
375+
slackIds = append(slackIds, &item.ConfigId)
376+
} else if item.Destination == util.SES {
377+
sesUserIds = append(sesUserIds, int32(item.ConfigId))
378+
} else if item.Destination == util.SMTP {
379+
smtpUserIds = append(smtpUserIds, int32(item.ConfigId))
380+
}
379381
} else {
380-
directRecipients = append(directRecipients, item.Recipient)
382+
providerConfigs = append(providerConfigs, &ProvidersConfig{Dest: string(item.Destination), Recipient: item.Recipient})
381383
}
382384
}
383-
var providerConfigs []*ProvidersConfig
384385
if len(slackIds) > 0 {
385386
slackConfigs, err := impl.slackRepository.FindByIds(slackIds)
386387
if err != nil && err != pg.ErrNoRows {
@@ -412,13 +413,6 @@ func (impl *NotificationConfigServiceImpl) BuildNotificationSettingsResponse(not
412413
providerConfigs = append(providerConfigs, &ProvidersConfig{Id: int(item.Id), ConfigName: item.EmailId, Dest: string(util.SMTP)})
413414
}
414415
}
415-
for _, item := range directRecipients {
416-
if strings.Contains(item, "https://") {
417-
providerConfigs = append(providerConfigs, &ProvidersConfig{Dest: string(util.Slack), Recipient: item})
418-
} else {
419-
providerConfigs = append(providerConfigs, &ProvidersConfig{Dest: string(util.SES), Recipient: item})
420-
}
421-
}
422416
notificationSettingsResponse.ProvidersConfig = providerConfigs
423417
}
424418

pkg/pipeline/CiService.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig.
395395
DockerRegistryURL: pipeline.CiTemplate.DockerRegistry.RegistryURL,
396396
DockerRepository: pipeline.CiTemplate.DockerRepository,
397397
DockerBuildArgs: string(merged),
398+
DockerBuildTargetPlatform: pipeline.CiTemplate.TargetPlatform,
398399
DockerFileLocation: dockerfilePath,
399400
DockerUsername: pipeline.CiTemplate.DockerRegistry.Username,
400401
DockerPassword: pipeline.CiTemplate.DockerRegistry.Password,

pkg/pipeline/PipelineBuilder.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func (impl PipelineBuilderImpl) getCiTemplateVariables(appId int) (ciConfig *bea
398398
DockerRepository: template.DockerRepository,
399399
DockerRegistry: template.DockerRegistry.Id,
400400
DockerRegistryUrl: regHost,
401-
DockerBuildConfig: &bean.DockerBuildConfig{DockerfilePath: template.DockerfilePath, Args: dockerArgs, GitMaterialId: template.GitMaterialId},
401+
DockerBuildConfig: &bean.DockerBuildConfig{DockerfilePath: template.DockerfilePath, Args: dockerArgs, GitMaterialId: template.GitMaterialId, TargetPlatform: template.TargetPlatform},
402402
Version: template.Version,
403403
CiTemplateName: template.TemplateName,
404404
Materials: materials,
@@ -618,6 +618,7 @@ func (impl PipelineBuilderImpl) UpdateCiTemplate(updateRequest *bean.CiConfigReq
618618
DockerfilePath: originalCiConf.DockerBuildConfig.DockerfilePath,
619619
GitMaterialId: originalCiConf.DockerBuildConfig.GitMaterialId,
620620
Args: string(argByte),
621+
TargetPlatform: originalCiConf.DockerBuildConfig.TargetPlatform,
621622
BeforeDockerBuild: string(beforeByte),
622623
AfterDockerBuild: string(afterByte),
623624
Version: originalCiConf.Version,
@@ -697,6 +698,7 @@ func (impl PipelineBuilderImpl) CreateCiPipeline(createRequest *bean.CiConfigReq
697698
GitMaterialId: createRequest.DockerBuildConfig.GitMaterialId,
698699
DockerfilePath: createRequest.DockerBuildConfig.DockerfilePath,
699700
Args: string(argByte),
701+
TargetPlatform: createRequest.DockerBuildConfig.TargetPlatform,
700702
Active: true,
701703
TemplateName: createRequest.CiTemplateName,
702704
Version: createRequest.Version,

0 commit comments

Comments
 (0)