From ab50d0ae0c807b4705f80897d6cb175ff4e70772 Mon Sep 17 00:00:00 2001 From: Robi Nino Date: Mon, 26 Feb 2024 14:25:19 +0200 Subject: [PATCH 1/2] Support distribution sync and project --- go.mod | 2 +- go.sum | 4 +-- lifecycle/common.go | 20 ++++++++++++++ lifecycle/distribute.go | 60 ++++++++++++++++++++++++++--------------- 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index f80e75ea3..b2a4e77c0 100644 --- a/go.mod +++ b/go.mod @@ -96,7 +96,7 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect ) -replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240225150756-e5fed3788eca +replace github.com/jfrog/jfrog-client-go => github.com/RobiNino/jfrog-client-go v0.0.0-20240226122023-e36e50380b38 replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c diff --git a/go.sum b/go.sum index 7d2f662ec..dd837c310 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/RobiNino/jfrog-client-go v0.0.0-20240226122023-e36e50380b38 h1:U/ksXeIr5e9FuKfhjOGWdmLO+9o+QL/4+/ERqR1QXcU= +github.com/RobiNino/jfrog-client-go v0.0.0-20240226122023-e36e50380b38/go.mod h1:WhVrqiqhSNFwj58/RQIrJEd28PHH1LTD4eWE0vBXv1o= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= @@ -87,8 +89,6 @@ github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c h1:M1QiuCYGC github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c/go.mod h1:QHcKuesY4MrBVBuEwwBz4uIsX6mwYuMEDV09ng4AvAU= github.com/jfrog/gofrog v1.6.0 h1:jOwb37nHY2PnxePNFJ6e6279Pgkr3di05SbQQw47Mq8= github.com/jfrog/gofrog v1.6.0/go.mod h1:SZ1EPJUruxrVGndOzHd+LTiwWYKMlHqhKD+eu+v5Hqg= -github.com/jfrog/jfrog-client-go v1.28.1-0.20240225150756-e5fed3788eca h1:wgiw3iokmQ5uK+6+M50fyMQBsMJPQEbRYnwbAMUmPlI= -github.com/jfrog/jfrog-client-go v1.28.1-0.20240225150756-e5fed3788eca/go.mod h1:WhVrqiqhSNFwj58/RQIrJEd28PHH1LTD4eWE0vBXv1o= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= diff --git a/lifecycle/common.go b/lifecycle/common.go index e185cb578..c443ac055 100644 --- a/lifecycle/common.go +++ b/lifecycle/common.go @@ -2,10 +2,12 @@ package lifecycle import ( "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" + "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-client-go/lifecycle" "github.com/jfrog/jfrog-client-go/lifecycle/services" clientUtils "github.com/jfrog/jfrog-client-go/utils" + "github.com/jfrog/jfrog-client-go/utils/distribution" ) const minimalLifecycleArtifactoryVersion = "7.63.2" @@ -49,3 +51,21 @@ func validateArtifactoryVersionSupported(serverDetails *config.ServerDetails) er return clientUtils.ValidateMinimumVersion(clientUtils.Artifactory, versionStr, minimalLifecycleArtifactoryVersion) } + +// If distribution rules are empty, distribute to all edges. +func getAggregatedDistRules(distributionRules *spec.DistributionRules) (aggregatedRules []*distribution.DistributionCommonParams) { + if isDistributionRulesEmpty(distributionRules) { + aggregatedRules = append(aggregatedRules, &distribution.DistributionCommonParams{SiteName: "*"}) + } else { + for _, rules := range distributionRules.DistributionRules { + aggregatedRules = append(aggregatedRules, rules.ToDistributionCommonParams()) + } + } + return +} + +func isDistributionRulesEmpty(distributionRules *spec.DistributionRules) bool { + return distributionRules == nil || + len(distributionRules.DistributionRules) == 0 || + len(distributionRules.DistributionRules) == 1 && distributionRules.DistributionRules[0].IsEmpty() +} diff --git a/lifecycle/distribute.go b/lifecycle/distribute.go index 76a187330..76165ef56 100644 --- a/lifecycle/distribute.go +++ b/lifecycle/distribute.go @@ -1,21 +1,19 @@ package lifecycle import ( - "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils" "github.com/jfrog/jfrog-cli-core/v2/common/spec" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-client-go/lifecycle/services" - "github.com/jfrog/jfrog-client-go/utils/distribution" ) type ReleaseBundleDistributeCommand struct { - serverDetails *config.ServerDetails - distributeBundlesParams distribution.DistributionParams - distributionRules *spec.DistributionRules - dryRun bool - autoCreateRepo bool - pathMappingPattern string - pathMappingTarget string + releaseBundleCmd + distributionRules *spec.DistributionRules + dryRun bool + autoCreateRepo bool + pathMappingPattern string + pathMappingTarget string + maxWaitMinutes int } func NewReleaseBundleDistributeCommand() *ReleaseBundleDistributeCommand { @@ -27,8 +25,18 @@ func (rbd *ReleaseBundleDistributeCommand) SetServerDetails(serverDetails *confi return rbd } -func (rbd *ReleaseBundleDistributeCommand) SetDistributeBundleParams(params distribution.DistributionParams) *ReleaseBundleDistributeCommand { - rbd.distributeBundlesParams = params +func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleName(releaseBundleName string) *ReleaseBundleDistributeCommand { + rbd.releaseBundleName = releaseBundleName + return rbd +} + +func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleVersion(releaseBundleVersion string) *ReleaseBundleDistributeCommand { + rbd.releaseBundleVersion = releaseBundleVersion + return rbd +} + +func (rbd *ReleaseBundleDistributeCommand) SetReleaseBundleProject(rbProjectKey string) *ReleaseBundleDistributeCommand { + rbd.rbProjectKey = rbProjectKey return rbd } @@ -57,33 +65,41 @@ func (rbd *ReleaseBundleDistributeCommand) SetPathMappingTarget(pathMappingTarge return rbd } +func (rbd *ReleaseBundleDistributeCommand) SetSync(sync bool) *ReleaseBundleDistributeCommand { + rbd.sync = sync + return rbd +} + +func (rbd *ReleaseBundleDistributeCommand) SetMaxWaitMinutes(maxWaitMinutes int) *ReleaseBundleDistributeCommand { + rbd.maxWaitMinutes = maxWaitMinutes + return rbd +} + func (rbd *ReleaseBundleDistributeCommand) Run() error { if err := validateArtifactoryVersionSupported(rbd.serverDetails); err != nil { return err } - servicesManager, err := utils.CreateLifecycleServiceManager(rbd.serverDetails, rbd.dryRun) + servicesManager, rbDetails, _, err := rbd.getPrerequisites() if err != nil { return err } - for _, rule := range rbd.distributionRules.DistributionRules { - rbd.distributeBundlesParams.DistributionRules = append(rbd.distributeBundlesParams.DistributionRules, rule.ToDistributionCommonParams()) - } - pathMapping := services.PathMapping{ Pattern: rbd.pathMappingPattern, Target: rbd.pathMappingTarget, } - return servicesManager.DistributeReleaseBundle(services.ReleaseBundleDetails{ - ReleaseBundleName: rbd.distributeBundlesParams.Name, - ReleaseBundleVersion: rbd.distributeBundlesParams.Version, - }, services.DistributeReleaseBundleParams{ + distributeParams := services.DistributeReleaseBundleParams{ + Sync: rbd.sync, AutoCreateRepo: rbd.autoCreateRepo, - DistributionRules: rbd.distributeBundlesParams.DistributionRules, + MaxWaitMinutes: rbd.maxWaitMinutes, + DistributionRules: getAggregatedDistRules(rbd.distributionRules), PathMappings: []services.PathMapping{pathMapping}, - }) + ProjectKey: rbd.rbProjectKey, + } + + return servicesManager.DistributeReleaseBundle(rbDetails, distributeParams) } func (rbd *ReleaseBundleDistributeCommand) ServerDetails() (*config.ServerDetails, error) { From 586bd40d648d9b5610e5c7e2d6f259f4c7c4de9a Mon Sep 17 00:00:00 2001 From: Robi Nino Date: Mon, 18 Mar 2024 08:55:13 +0200 Subject: [PATCH 2/2] update go.mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 539e7b187..2d8febd38 100644 --- a/go.mod +++ b/go.mod @@ -96,7 +96,7 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect ) -replace github.com/jfrog/jfrog-client-go => github.com/RobiNino/jfrog-client-go v0.0.0-20240318060947-e3f338b51fae +replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240318065424-90669dbbcc54 replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c diff --git a/go.sum b/go.sum index 33b4ea32c..909812c3f 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,6 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= -github.com/RobiNino/jfrog-client-go v0.0.0-20240318060947-e3f338b51fae h1:puW3WzQP9ascA1dzocJZJmRInNdjYUwOH7fAXud0NsE= -github.com/RobiNino/jfrog-client-go v0.0.0-20240318060947-e3f338b51fae/go.mod h1:NB8tYFgkWtn+wHsKC+aYC75aLnS6yW81d8JAFTBxsi0= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= @@ -89,6 +87,8 @@ github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c h1:M1QiuCYGC github.com/jfrog/build-info-go v1.8.9-0.20240225113943-096bf22ca54c/go.mod h1:QHcKuesY4MrBVBuEwwBz4uIsX6mwYuMEDV09ng4AvAU= github.com/jfrog/gofrog v1.6.3 h1:F7He0+75HcgCe6SGTSHLFCBDxiE2Ja0tekvvcktW6wc= github.com/jfrog/gofrog v1.6.3/go.mod h1:SZ1EPJUruxrVGndOzHd+LTiwWYKMlHqhKD+eu+v5Hqg= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240318065424-90669dbbcc54 h1:FTrss/ffJPjTHOOhQ8P+8DrkGYkxcaHlxp12nOfeZJQ= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240318065424-90669dbbcc54/go.mod h1:NB8tYFgkWtn+wHsKC+aYC75aLnS6yW81d8JAFTBxsi0= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=