Skip to content

Commit f94d19c

Browse files
committed
Merge branch 'develop' into notifier-refac
# Conflicts: # env_gen.json
2 parents 8b9f6d0 + 8e3952a commit f94d19c

File tree

13 files changed

+77
-18
lines changed

13 files changed

+77
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
.env
55
/cmd/external-app/devtron-ea
66
devtron
7+
8+
.qodo

api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"golang.org/x/exp/maps"
3131
"io"
3232
"net/http"
33+
"regexp"
3334
"strconv"
3435
"strings"
3536

@@ -1479,10 +1480,12 @@ func (handler *PipelineConfigRestHandlerImpl) ValidateGitMaterialUrl(gitProvider
14791480
return false, err
14801481
}
14811482
if gitProvider.AuthMode == constants.AUTH_MODE_SSH {
1482-
hasPrefixResult := strings.HasPrefix(url, SSH_URL_PREFIX)
1483+
// this regex is used to generic ssh providers like gogs where format is <user>@<host>:<org>/<repo>.git
1484+
var scpLikeSSHRegex = regexp.MustCompile(`^[\w-]+@[\w.-]+:[\w./-]+\.git$`)
1485+
hasPrefixResult := strings.HasPrefix(url, SSH_URL_PREFIX) || scpLikeSSHRegex.MatchString(url)
14831486
return hasPrefixResult, nil
14841487
}
1485-
hasPrefixResult := strings.HasPrefix(url, HTTPS_URL_PREFIX)
1488+
hasPrefixResult := strings.HasPrefix(url, HTTPS_URL_PREFIX) || strings.HasPrefix(url, HTTP_URL_PREFIX)
14861489
return hasPrefixResult, nil
14871490
}
14881491

api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
repository2 "github.com/devtron-labs/devtron/pkg/cluster/environment/repository"
3232
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics"
3333
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef"
34-
"github.com/devtron-labs/devtron/pkg/pipeline/draftAwareConfigService"
3534
validator2 "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/validator"
35+
"github.com/devtron-labs/devtron/pkg/pipeline/draftAwareConfigService"
3636
security2 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning"
3737
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/read"
3838
read3 "github.com/devtron-labs/devtron/pkg/team/read"
@@ -225,6 +225,7 @@ const (
225225
devtron = "DEVTRON"
226226
SSH_URL_PREFIX = "git@"
227227
HTTPS_URL_PREFIX = "https://"
228+
HTTP_URL_PREFIX = "http://"
228229
argoWFLogIdentifier = "argo=true"
229230
)
230231

env_gen.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/appStore/bean/bean.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ type ChartRepoSearch struct {
433433
ChartId int `json:"chartId"`
434434
ChartName string `json:"chartName"`
435435
ChartRepoId int `json:"chartRepoId"`
436+
DockerArtifactStoreId string `json:"DockerArtifactStoreId"`
436437
ChartRepoName string `json:"chartRepoName"`
437438
Version string `json:"version"`
438439
Deprecated bool `json:"deprecated"`

pkg/appStore/discover/repository/AppStoreApplicationVersionRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (impl *AppStoreApplicationVersionRepositoryImpl) SearchAppStoreChartByName(
273273
var chartRepos []*appStoreBean.ChartRepoSearch
274274
//for chart repos, created (derived through index.yaml) column of app_store_application_version is used for finding latest version and for oci repo id is used (because created is null)
275275
queryTemp := `select asv.id as app_store_application_version_id, asv.version, asv.deprecated, aps.id as chart_id,
276-
aps.name as chart_name, chr.id as chart_repo_id, chr.name as chart_repo_name
276+
aps.name as chart_name, chr.id as chart_repo_id, chr.name as chart_repo_name , das.id as docker_artifact_store_id
277277
from app_store_application_version asv
278278
inner join app_store aps on asv.app_store_id = aps.id
279279
left join chart_repo chr on aps.chart_repo_id = chr.id

pkg/appStore/discover/service/AppStoreService.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,10 @@ func (impl *AppStoreServiceImpl) SearchAppStoreChartByName(chartName string) ([]
130130
if err != nil && !util.IsErrNoRows(err) {
131131
return nil, err
132132
}
133+
for _, appStore := range appStoreApplications {
134+
if len(appStore.ChartRepoName) == 0 && len(appStore.DockerArtifactStoreId) != 0 {
135+
appStore.ChartRepoName = appStore.DockerArtifactStoreId
136+
}
137+
}
133138
return appStoreApplications, nil
134139
}

pkg/appStore/installedApp/service/AppStoreDeploymentService.go

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
openapi2 "github.com/devtron-labs/devtron/api/openapi/openapiClient"
3030
"github.com/devtron-labs/devtron/client/argocdServer"
3131
"github.com/devtron-labs/devtron/internal/sql/repository/app"
32+
repository2 "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
3233
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/timelineStatus"
3334
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow"
3435
"github.com/devtron-labs/devtron/internal/util"
@@ -90,6 +91,7 @@ type AppStoreDeploymentServiceImpl struct {
9091
deletePostProcessor DeletePostProcessor
9192
appStoreValidator AppStoreValidator
9293
deploymentConfigService common.DeploymentConfigService
94+
OCIRegistryConfigRepository repository2.OCIRegistryConfigRepository
9395
}
9496

9597
func NewAppStoreDeploymentServiceImpl(logger *zap.SugaredLogger,
@@ -109,7 +111,7 @@ func NewAppStoreDeploymentServiceImpl(logger *zap.SugaredLogger,
109111
gitOpsConfigReadService config.GitOpsConfigReadService, deletePostProcessor DeletePostProcessor,
110112
appStoreValidator AppStoreValidator,
111113
deploymentConfigService common.DeploymentConfigService,
112-
) *AppStoreDeploymentServiceImpl {
114+
OCIRegistryConfigRepository repository2.OCIRegistryConfigRepository) *AppStoreDeploymentServiceImpl {
113115

114116
return &AppStoreDeploymentServiceImpl{
115117
logger: logger,
@@ -130,6 +132,7 @@ func NewAppStoreDeploymentServiceImpl(logger *zap.SugaredLogger,
130132
deletePostProcessor: deletePostProcessor,
131133
appStoreValidator: appStoreValidator,
132134
deploymentConfigService: deploymentConfigService,
135+
OCIRegistryConfigRepository: OCIRegistryConfigRepository,
133136
}
134137
}
135138

@@ -951,7 +954,49 @@ func (impl *AppStoreDeploymentServiceImpl) linkHelmApplicationToChartStore(insta
951954
}
952955

953956
// STEP-2 update APP with chart info
954-
chartRepoInfo := appStoreAppVersion.AppStore.ChartRepo
957+
//TODO: below code is duplicated
958+
var IsOCIRepo bool
959+
var registryCredential *bean4.RegistryCredential
960+
var chartRepository *bean4.ChartRepository
961+
dockerRegistryId := appStoreAppVersion.AppStore.DockerArtifactStoreId
962+
if dockerRegistryId != "" {
963+
ociRegistryConfigs, err := impl.OCIRegistryConfigRepository.FindByDockerRegistryId(dockerRegistryId)
964+
if err != nil {
965+
impl.logger.Errorw("error in fetching oci registry config", "err", err)
966+
return nil, err
967+
}
968+
var ociRegistryConfig *repository2.OCIRegistryConfig
969+
for _, config := range ociRegistryConfigs {
970+
if config.RepositoryAction == repository2.STORAGE_ACTION_TYPE_PULL || config.RepositoryAction == repository2.STORAGE_ACTION_TYPE_PULL_AND_PUSH {
971+
ociRegistryConfig = config
972+
break
973+
}
974+
}
975+
IsOCIRepo = true
976+
registryCredential = &bean4.RegistryCredential{
977+
RegistryUrl: appStoreAppVersion.AppStore.DockerArtifactStore.RegistryURL,
978+
Username: appStoreAppVersion.AppStore.DockerArtifactStore.Username,
979+
Password: appStoreAppVersion.AppStore.DockerArtifactStore.Password,
980+
AwsRegion: appStoreAppVersion.AppStore.DockerArtifactStore.AWSRegion,
981+
AccessKey: appStoreAppVersion.AppStore.DockerArtifactStore.AWSAccessKeyId,
982+
SecretKey: appStoreAppVersion.AppStore.DockerArtifactStore.AWSSecretAccessKey,
983+
RegistryType: string(appStoreAppVersion.AppStore.DockerArtifactStore.RegistryType),
984+
RepoName: appStoreAppVersion.AppStore.Name,
985+
IsPublic: ociRegistryConfig.IsPublic,
986+
Connection: appStoreAppVersion.AppStore.DockerArtifactStore.Connection,
987+
RegistryName: appStoreAppVersion.AppStore.DockerArtifactStore.Id,
988+
RegistryCertificate: appStoreAppVersion.AppStore.DockerArtifactStore.Cert,
989+
}
990+
} else {
991+
chartRepository = &bean4.ChartRepository{
992+
Name: appStoreAppVersion.AppStore.ChartRepo.Name,
993+
Url: appStoreAppVersion.AppStore.ChartRepo.Url,
994+
Username: appStoreAppVersion.AppStore.ChartRepo.UserName,
995+
Password: appStoreAppVersion.AppStore.ChartRepo.Password,
996+
AllowInsecureConnection: appStoreAppVersion.AppStore.ChartRepo.AllowInsecureConnection,
997+
}
998+
}
999+
9551000
updateReleaseRequest := &bean3.UpdateApplicationWithChartInfoRequestDto{
9561001
InstallReleaseRequest: &bean4.InstallReleaseRequest{
9571002
ValuesYaml: installAppVersionRequest.ValuesOverrideYaml,
@@ -961,18 +1006,14 @@ func (impl *AppStoreDeploymentServiceImpl) linkHelmApplicationToChartStore(insta
9611006
ReleaseNamespace: installAppVersionRequest.Namespace,
9621007
ReleaseName: installAppVersionRequest.DisplayName,
9631008
},
1009+
RegistryCredential: registryCredential,
1010+
ChartRepository: chartRepository,
1011+
IsOCIRepo: IsOCIRepo,
1012+
InstallAppVersionHistoryId: 0,
9641013
},
9651014
SourceAppType: bean3.SOURCE_HELM_APP,
9661015
}
967-
if chartRepoInfo != nil {
968-
updateReleaseRequest.ChartRepository = &bean4.ChartRepository{
969-
Name: chartRepoInfo.Name,
970-
Url: chartRepoInfo.Url,
971-
Username: chartRepoInfo.UserName,
972-
Password: chartRepoInfo.Password,
973-
AllowInsecureConnection: chartRepoInfo.AllowInsecureConnection,
974-
}
975-
}
1016+
9761017
res, err := impl.helmAppService.UpdateApplicationWithChartInfo(ctx, installAppVersionRequest.ClusterId, updateReleaseRequest)
9771018
if err != nil {
9781019
return nil, err

pkg/notifier/WebhookNotificationService.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func (impl *WebhookNotificationServiceImpl) GetWebhookVariables() (map[string]be
109109
"devtronCiPipelineId": beans.DevtronCiPipelineId,
110110
"devtronCdPipelineId": beans.DevtronCdPipelineId,
111111
"devtronTriggeredByEmail": beans.DevtronTriggeredByEmail,
112+
"devtronPipelineType": beans.DevtronPipelineType,
113+
"devtronBuildGitCommitHash": beans.DevtronBuildGitCommitHash,
112114
"eventType": beans.EventType,
113115
}
114116

@@ -119,7 +121,7 @@ func (impl *WebhookNotificationServiceImpl) FetchAllWebhookNotificationConfig()
119121
var responseDto []*beans.WebhookConfigDto
120122
webhookConfigs, err := impl.webhookRepository.FindAll()
121123
if err != nil && !util.IsErrNoRows(err) {
122-
impl.logger.Errorw("cannot find all webhoook config", "err", err)
124+
impl.logger.Errorw("cannot find all webhook config", "err", err)
123125
return []*beans.WebhookConfigDto{}, err
124126
}
125127
for _, webhookConfig := range webhookConfigs {

pkg/notifier/beans/beans.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const (
2323
DevtronCiPipelineId WebhookVariable = "{{devtronCiPipelineId}}"
2424
DevtronCdPipelineId WebhookVariable = "{{devtronCdPipelineId}}"
2525
DevtronTriggeredByEmail WebhookVariable = "{{devtronTriggeredByEmail}}"
26+
DevtronBuildGitCommitHash WebhookVariable = "{{devtronBuildGitCommitHash}}"
27+
DevtronPipelineType WebhookVariable = "{{devtronPipelineType}}"
2628
EventType WebhookVariable = "{{eventType}}"
2729
)
2830

0 commit comments

Comments
 (0)