Skip to content

Commit

Permalink
fix:Image tag not propagated in Rollback (#3897)
Browse files Browse the repository at this point in the history
* devtronContainerImageRepo varilable added

* bug fixed around image tags and comment
  • Loading branch information
adi6859 committed Sep 14, 2023
1 parent 3847dc2 commit cd1be97
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
21 changes: 20 additions & 1 deletion api/restHandler/app/DeploymentPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,13 +1336,32 @@ func (handler PipelineConfigRestHandlerImpl) GetArtifactsForRollback(w http.Resp
return
}
//rbac block ends here
//rbac for edit tags access
triggerAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionTrigger, object)

ciArtifactResponse, err := handler.pipelineBuilder.FetchArtifactForRollback(cdPipelineId, offset, limit)
ciArtifactResponse, err := handler.pipelineBuilder.FetchArtifactForRollback(cdPipelineId, app.Id, offset, limit)
if err != nil {
handler.Logger.Errorw("service err, GetArtifactsForRollback", "err", err, "cdPipelineId", cdPipelineId)
common.WriteJsonResp(w, err, "unable to fetch artifacts", http.StatusInternalServerError)
return
}
appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(app.Id)
if err != nil {
handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", app.Id)
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
return
}

ciArtifactResponse.AppReleaseTagNames = appTags

prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(cdPipelineId)
ciArtifactResponse.TagsEditable = prodEnvExists && triggerAccess
ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete
if err != nil {
handler.Logger.Errorw("service err, GetProdEnvByCdPipelineId", "err", err, "cdPipelineId", app.Id)
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusOK)
}

Expand Down
27 changes: 25 additions & 2 deletions pkg/pipeline/PipelineBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type PipelineBuilder interface {
/* CreateCdPipelines(cdPipelines bean.CdPipelines) (*bean.CdPipelines, error)*/
RetrieveArtifactsByCDPipeline(pipeline *pipelineConfig.Pipeline, stage bean2.WorkflowType) (*bean.CiArtifactResponse, error)
RetrieveParentDetails(pipelineId int) (parentId int, parentType bean2.WorkflowType, err error)
FetchArtifactForRollback(cdPipelineId, offset, limit int) (bean.CiArtifactResponse, error)
FetchArtifactForRollback(cdPipelineId, appId, offset, limit int) (bean.CiArtifactResponse, error)
FindAppsByTeamId(teamId int) ([]*AppBean, error)
FindAppsByTeamName(teamName string) ([]AppBean, error)
FindPipelineById(cdPipelineId int) (*pipelineConfig.Pipeline, error)
Expand Down Expand Up @@ -3734,7 +3734,7 @@ func (impl *PipelineBuilderImpl) BuildArtifactsForCIParent(cdPipelineId int, par
return ciArtifacts, nil
}

func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, offset, limit int) (bean.CiArtifactResponse, error) {
func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, appId, offset, limit int) (bean.CiArtifactResponse, error) {
var deployedCiArtifacts []bean.CiArtifactBean
var deployedCiArtifactsResponse bean.CiArtifactResponse

Expand All @@ -3755,6 +3755,14 @@ func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, offset,
for _, item := range users {
userEmails[item.Id] = item.EmailId
}

imageTagsDataMap, err := impl.imageTaggingService.GetTagsDataMapByAppId(appId)
if err != nil {
impl.logger.Errorw("error in getting image tagging data with appId", "err", err, "appId", appId)
return deployedCiArtifactsResponse, err
}
artifactIds := make([]int, 0)

for _, cdWfr := range cdWfrs {
ciArtifact := &repository.CiArtifact{}
if cdWfr.CdWorkflow != nil && cdWfr.CdWorkflow.CiArtifact != nil {
Expand All @@ -3777,6 +3785,21 @@ func (impl *PipelineBuilderImpl) FetchArtifactForRollback(cdPipelineId, offset,
WfrId: cdWfr.Id,
DeployedBy: userEmail,
})
artifactIds = append(artifactIds, ciArtifact.Id)
}
imageCommentsDataMap, err := impl.imageTaggingService.GetImageCommentsDataMapByArtifactIds(artifactIds)
if err != nil {
impl.logger.Errorw("error in getting GetImageCommentsDataMapByArtifactIds", "err", err, "appId", appId, "artifactIds", artifactIds)
return deployedCiArtifactsResponse, err
}

for i, _ := range deployedCiArtifacts {
if imageTaggingResp := imageTagsDataMap[deployedCiArtifacts[i].Id]; imageTaggingResp != nil {
deployedCiArtifacts[i].ImageReleaseTags = imageTaggingResp
}
if imageCommentResp := imageCommentsDataMap[deployedCiArtifacts[i].Id]; imageCommentResp != nil {
deployedCiArtifacts[i].ImageComment = imageCommentResp
}
}

deployedCiArtifactsResponse.CdPipelineId = cdPipelineId
Expand Down

0 comments on commit cd1be97

Please sign in to comment.