Skip to content
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8a7d822
Add custom tag
avdhesh-devtron Aug 24, 2023
127ad00
Refactor handle concurrency
avdhesh-devtron Aug 24, 2023
d5c6102
Refactor
avdhesh-devtron Aug 24, 2023
c559393
Update workflow when trigger failes due to tag conflict
avdhesh-devtron Aug 25, 2023
3dfde7a
Fix error
avdhesh-devtron Aug 25, 2023
2768ea5
temp
avdhesh-devtron Aug 25, 2023
e3da3b8
Build history failure case
avdhesh-devtron Aug 25, 2023
ae8b894
Merge branch 'custom-tag' of github.com:devtron-labs/devtron into ref…
avdhesh-devtron Aug 25, 2023
edd2d54
Custom tag logic extracted
avdhesh-devtron Aug 28, 2023
abd20e8
Fix build
avdhesh-devtron Aug 28, 2023
bd6b603
fix get query
avdhesh-devtron Aug 28, 2023
f97fac5
fix error handling
avdhesh-devtron Aug 28, 2023
9ebfbb5
fix iota value
avdhesh-devtron Aug 28, 2023
0818862
Fix errors
avdhesh-devtron Aug 28, 2023
ef9af2c
Return error when image path conflicts
avdhesh-devtron Aug 29, 2023
7c672de
Handle errors
avdhesh-devtron Aug 29, 2023
98cd350
Handle failed ci_workflow
avdhesh-devtron Aug 29, 2023
0b8efba
Handle failed ci_workflow
avdhesh-devtron Aug 29, 2023
47729b1
Remove unnecessary image path deactivation
avdhesh-devtron Aug 29, 2023
ec8510f
Fix migration
avdhesh-devtron Aug 29, 2023
a564454
Merge branch 'main' of github.com:devtron-labs/devtron into refactor-…
avdhesh-devtron Aug 29, 2023
bf99dce
Refactor
avdhesh-devtron Aug 29, 2023
720a99d
Refactor
avdhesh-devtron Aug 29, 2023
b841f29
Add validations
avdhesh-devtron Aug 29, 2023
c955e21
Remove regex check
avdhesh-devtron Aug 29, 2023
3ea5834
Fix error message
avdhesh-devtron Aug 29, 2023
8fde21d
Return bad request in case of trigger
avdhesh-devtron Aug 29, 2023
0f3c248
add validation
avdhesh-devtron Aug 30, 2023
06edac9
add validation
avdhesh-devtron Aug 30, 2023
df484ca
ad ci workflow id in status api
avdhesh-devtron Aug 30, 2023
786121b
add comments
avdhesh-devtron Aug 31, 2023
500a256
main merge
iamayushm Oct 4, 2023
1febd7d
custom image tag migration
iamayushm Oct 4, 2023
ec1dd53
sql script correction
iamayushm Oct 4, 2023
8f3a54b
fix: validation and sql script
iamayushm Oct 5, 2023
33ae161
fixing null value in custom tag
iamayushm Oct 5, 2023
558928c
Merge branch 'main' into refactor-tag-generation
iamayushm Oct 9, 2023
74f1c38
marking image tag unreserved on abort
iamayushm Oct 11, 2023
5ab08bb
main merge
iamayushm Oct 11, 2023
1252c91
main merge
iamayushm Oct 17, 2023
3a1f591
Merge branch 'main' into refactor-tag-generation
iamayushm Oct 23, 2023
15b3ba1
migration script fix
iamayushm Oct 23, 2023
2ff5cf8
fix get api
iamayushm Oct 23, 2023
badac18
tag validation updated
iamayushm Oct 23, 2023
849ebfe
wip: validaion using regex
iamayushm Oct 23, 2023
784b65a
fix validation
iamayushm Oct 23, 2023
fca223a
fixing error string
iamayushm Oct 23, 2023
8b39dbe
fix validation
iamayushm Oct 23, 2023
20f35c6
tag validation updated
iamayushm Oct 23, 2023
a3277dc
tag pattern modification
iamayushm Oct 23, 2023
5f1a6c7
wip: fix
iamayushm Oct 25, 2023
d89d12e
fixing regex
iamayushm Oct 25, 2023
5be2095
Merge branch 'main' into refactor-tag-generation
iamayushm Oct 25, 2023
b713e2d
pr review changes
iamayushm Oct 25, 2023
f8f8d8b
Merge branch 'main' into refactor-tag-generation
iamayushm Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import (
security2 "github.com/devtron-labs/devtron/internal/sql/repository/security"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/internal/util/ArgoUtil"
"github.com/devtron-labs/devtron/pkg"
"github.com/devtron-labs/devtron/pkg/app"
"github.com/devtron-labs/devtron/pkg/app/status"
"github.com/devtron-labs/devtron/pkg/appClone"
Expand Down Expand Up @@ -286,6 +287,12 @@ func InitializeApp() (*App, error) {
bulkAction.NewBulkUpdateServiceImpl,
wire.Bind(new(bulkAction.BulkUpdateService), new(*bulkAction.BulkUpdateServiceImpl)),

repository.NewImageTagRepository,
wire.Bind(new(repository.ImageTagRepository), new(*repository.ImageTagRepositoryImpl)),

pkg.NewCustomTagService,
wire.Bind(new(pkg.CustomTagService), new(*pkg.CustomTagServiceImpl)),

repository.NewGitProviderRepositoryImpl,
wire.Bind(new(repository.GitProviderRepository), new(*repository.GitProviderRepositoryImpl)),
pipeline.NewGitRegistryConfigImpl,
Expand Down
16 changes: 16 additions & 0 deletions api/bean/CustomTag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package bean

type CustomTag struct {
EntityKey int `json:"entityKey"`
EntityValue string `json:"entityValue"`
TagPattern string `json:"tagPattern"`
AutoIncreasingNumber int `json:"counterX"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be used better name for counterX

Metadata string `json:"metadata"`
}

type CustomTagErrorResponse struct {
ConflictingArtifactPath string `json:"conflictingLink"`
TagPattern string `json:"tagPattern"`
AutoIncreasingNumber int `json:"counterX"`
Message string `json:"message"`
}
7 changes: 7 additions & 0 deletions api/restHandler/app/BuildPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/internal/util"
"github.com/devtron-labs/devtron/pkg"
"github.com/devtron-labs/devtron/pkg/bean"
"github.com/devtron-labs/devtron/pkg/pipeline"
bean1 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
Expand Down Expand Up @@ -593,6 +594,11 @@ func (handler PipelineConfigRestHandlerImpl) TriggerCiPipeline(w http.ResponseWr
//RBAC ENDS
response := make(map[string]string)
resp, err := handler.ciHandler.HandleCIManual(ciTriggerRequest)
if errors.Is(err, pkg.ErrImagePathInUse) {
handler.Logger.Errorw("service err duplicate image tag, TriggerCiPipeline", "err", err, "payload", ciTriggerRequest)
common.WriteJsonResp(w, err, response, http.StatusConflict)
return
}
if err != nil {
handler.Logger.Errorw("service err, TriggerCiPipeline", "err", err, "payload", ciTriggerRequest)
common.WriteJsonResp(w, err, response, http.StatusInternalServerError)
Expand Down Expand Up @@ -1108,6 +1114,7 @@ func (handler PipelineConfigRestHandlerImpl) GetCIPipelineById(w http.ResponseWr
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
ciPipeline.DefaultTag = []string{"{git_hash}", "{ci_pipeline_id}", "{global_counter}"}
common.WriteJsonResp(w, err, ciPipeline, http.StatusOK)
}

Expand Down
107 changes: 107 additions & 0 deletions internal/sql/repository/CustomTagRepository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package repository

import (
"github.com/go-pg/pg"
"go.uber.org/zap"
)

type CustomTag struct {
tableName struct{} `sql:"custom_tag" pg:",discard_unknown_columns"`
Id int `sql:"id"`
EntityKey int `sql:"entity_key"`
EntityValue string `sql:"entity_value"`
TagPattern string `sql:"tag_pattern"`
AutoIncreasingNumber int `sql:"auto_increasing_number, notnull"`
Active bool `sql:"active"`
Metadata string `sql:"metadata"`
}

type ImagePathReservation struct {
tableName struct{} `sql:"image_path_reservation" pg:",discard_unknown_columns"`
Id int `sql:"id"`
ImagePath string `sql:"image_path"`
CustomTagId int `sql:"custom_tag_id"`
active bool `sql:"active"`
}

type ImageTagRepository interface {
GetConnection() *pg.DB
CreateImageTag(customTagData *CustomTag) error
FetchCustomTagData(entityType int, entityValue string) (*CustomTag, error)
IncrementAndFetchByEntityKeyAndValue(tx *pg.Tx, entityKey int, entityValue string) (*CustomTag, error)
FindByImagePath(tx *pg.Tx, path string) ([]*ImagePathReservation, error)
InsertImagePath(tx *pg.Tx, reservation *ImagePathReservation) error
UpdateImageTag(customTag *CustomTag) error
DeleteByEntityKeyAndValue(entityKey int, entityValue string) error
DeactivateImagePathReservation(id int) error
FetchActiveCustomTagData(entityKey int, entityValue string) (*CustomTag, error)
}

type ImageTagRepositoryImpl struct {
dbConnection *pg.DB
logger *zap.SugaredLogger
}

func NewImageTagRepository(dbConnection *pg.DB, logger *zap.SugaredLogger) *ImageTagRepositoryImpl {
return &ImageTagRepositoryImpl{dbConnection: dbConnection, logger: logger}
}

func (impl *ImageTagRepositoryImpl) GetConnection() *pg.DB {
return impl.dbConnection
}

func (impl *ImageTagRepositoryImpl) CreateImageTag(customTagData *CustomTag) error {
return impl.dbConnection.Insert(customTagData)
}

func (impl *ImageTagRepositoryImpl) UpdateImageTag(customTag *CustomTag) error {
return impl.dbConnection.Update(customTag)
}

func (impl *ImageTagRepositoryImpl) DeleteByEntityKeyAndValue(entityKey int, entityValue string) error {
query := `update custom_tag set active = false where entity_key = ? and entity_value = ?`
_, err := impl.dbConnection.Exec(query, entityKey, entityValue)
return err
}

func (impl *ImageTagRepositoryImpl) DeactivateImagePathReservation(id int) error {
query := `update image_path_reservation set active=? where id=?`
_, err := impl.dbConnection.Exec(query, false, id)
return err
}

func (impl *ImageTagRepositoryImpl) FetchCustomTagData(entityType int, entityValue string) (*CustomTag, error) {
var customTagData CustomTag
err := impl.dbConnection.Model(&customTagData).
Where("entity_key = ?", entityType).
Where("entity_value = ?", entityValue).Select()
return &customTagData, err
}

func (impl *ImageTagRepositoryImpl) FetchActiveCustomTagData(entityType int, entityValue string) (*CustomTag, error) {
var customTagData CustomTag
err := impl.dbConnection.Model(&customTagData).
Where("entity_key = ?", entityType).
Where("entity_value = ?", entityValue).
Where("active = ?", true).Select()
return &customTagData, err
}

func (impl *ImageTagRepositoryImpl) IncrementAndFetchByEntityKeyAndValue(tx *pg.Tx, entityKey int, entityValue string) (*CustomTag, error) {
var customTag CustomTag
query := `update custom_tag set auto_increasing_number=auto_increasing_number+1 where entity_key=? and entity_value=? and active = ? returning id, tag_pattern, auto_increasing_number, entity_key, entity_value`
_, err := tx.Query(&customTag, query, entityKey, entityValue, true)
return &customTag, err
}

func (impl *ImageTagRepositoryImpl) FindByImagePath(tx *pg.Tx, path string) ([]*ImagePathReservation, error) {
var imagePaths []*ImagePathReservation
err := tx.Model(&imagePaths).
Where("image_path = ?", path).
Where("active = ?", true).Select()
return imagePaths, err
}

func (impl *ImageTagRepositoryImpl) InsertImagePath(tx *pg.Tx, reservation *ImagePathReservation) error {
return tx.Insert(reservation)
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ func (impl AppWorkflowRepositoryImpl) FindWFAllMappingByWorkflowId(workflowId in

func (impl AppWorkflowRepositoryImpl) FindWFCIMappingByCIPipelineId(ciPipelineId int) ([]*AppWorkflowMapping, error) {
var appWorkflowsMapping []*AppWorkflowMapping

err := impl.dbConnection.Model(&appWorkflowsMapping).
Where("component_id = ?", ciPipelineId).
Where("type = ?", CIPIPELINE).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ type CiWorkflowStatus struct {
CiPipelineName string `json:"ciPipelineName,omitempty"`
CiStatus string `json:"ciStatus"`
StorageConfigured bool `json:"storageConfigured"`
CiWorkflowId int `json:"ciWorkflowId,omitempty"`
}

type AppDeploymentStatus struct {
Expand Down
82 changes: 42 additions & 40 deletions internal/sql/repository/pipelineConfig/CiWorkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,52 +53,54 @@ type CiWorkflowRepositoryImpl struct {
}

type CiWorkflow struct {
tableName struct{} `sql:"ci_workflow" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name"`
Status string `sql:"status"`
PodStatus string `sql:"pod_status"`
Message string `sql:"message"`
StartedOn time.Time `sql:"started_on"`
FinishedOn time.Time `sql:"finished_on"`
CiPipelineId int `sql:"ci_pipeline_id"`
Namespace string `sql:"namespace"`
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
LogLocation string `sql:"log_file_path"`
GitTriggers map[int]GitCommit `sql:"git_triggers"`
TriggeredBy int32 `sql:"triggered_by"`
CiArtifactLocation string `sql:"ci_artifact_location"`
PodName string `sql:"pod_name"`
CiBuildType string `sql:"ci_build_type"`
EnvironmentId int `sql:"environment_id"`
tableName struct{} `sql:"ci_workflow" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name"`
Status string `sql:"status"`
PodStatus string `sql:"pod_status"`
Message string `sql:"message"`
StartedOn time.Time `sql:"started_on"`
FinishedOn time.Time `sql:"finished_on"`
CiPipelineId int `sql:"ci_pipeline_id"`
Namespace string `sql:"namespace"`
BlobStorageEnabled bool `sql:"blob_storage_enabled,notnull"`
LogLocation string `sql:"log_file_path"`
GitTriggers map[int]GitCommit `sql:"git_triggers"`
TriggeredBy int32 `sql:"triggered_by"`
CiArtifactLocation string `sql:"ci_artifact_location"`
PodName string `sql:"pod_name"`
CiBuildType string `sql:"ci_build_type"`
EnvironmentId int `sql:"environment_id"`
ImagePathReservationId int `sql:"image_path_reservation_id"`
ReferenceCiWorkflowId int `sql:"ref_ci_workflow_id"`
ParentCiWorkFlowId int `sql:"parent_ci_workflow_id"`
CiPipeline *CiPipeline
}

type WorkflowWithArtifact struct {
Id int `json:"id"`
Name string `json:"name"`
PodName string `json:"podName"`
Status string `json:"status"`
PodStatus string `json:"pod_status"`
Message string `json:"message"`
StartedOn time.Time `json:"started_on"`
FinishedOn time.Time `json:"finished_on"`
CiPipelineId int `json:"ci_pipeline_id"`
Namespace string `json:"namespace"`
LogFilePath string `json:"log_file_path"`
GitTriggers map[int]GitCommit `json:"git_triggers"`
TriggeredBy int32 `json:"triggered_by"`
EmailId string `json:"email_id"`
Image string `json:"image"`
CiArtifactLocation string `json:"ci_artifact_location"`
CiArtifactId int `json:"ci_artifact_d"`
BlobStorageEnabled bool `json:"blobStorageEnabled"`
CiBuildType string `json:"ci_build_type"`
IsArtifactUploaded bool `json:"is_artifact_uploaded"`
EnvironmentId int `json:"environmentId"`
EnvironmentName string `json:"environmentName"`
Id int `json:"id"`
Name string `json:"name"`
PodName string `json:"podName"`
Status string `json:"status"`
PodStatus string `json:"pod_status"`
Message string `json:"message"`
StartedOn time.Time `json:"started_on"`
FinishedOn time.Time `json:"finished_on"`
CiPipelineId int `json:"ci_pipeline_id"`
Namespace string `json:"namespace"`
LogFilePath string `json:"log_file_path"`
GitTriggers map[int]GitCommit `json:"git_triggers"`
TriggeredBy int32 `json:"triggered_by"`
EmailId string `json:"email_id"`
Image string `json:"image"`
CiArtifactLocation string `json:"ci_artifact_location"`
CiArtifactId int `json:"ci_artifact_d"`
BlobStorageEnabled bool `json:"blobStorageEnabled"`
CiBuildType string `json:"ci_build_type"`
IsArtifactUploaded bool `json:"is_artifact_uploaded"`
EnvironmentId int `json:"environmentId"`
EnvironmentName string `json:"environmentName"`
ImagePathReservationId int `json:"image_path_reservation_id"`
RefCiWorkflowId int `json:"referenceCiWorkflowId"`
ParentCiWorkflowId int `json:"parent_ci_workflow_id"`
}
Expand Down
Loading