Skip to content

Commit

Permalink
Artifactory Release Lifecycle Management - Support distribution sync …
Browse files Browse the repository at this point in the history
…and project (#1140)
  • Loading branch information
RobiNino authored Mar 18, 2024
1 parent 662abef commit b785b7d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 25 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240317160615-e419c2a9e723
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

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +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.20240317160615-e419c2a9e723 h1:0N/fdI2PXLjdWZieh7ib+6gb87yw3x22V7t1YZJvWOA=
github.com/jfrog/jfrog-client-go v1.28.1-0.20240317160615-e419c2a9e723/go.mod h1:NB8tYFgkWtn+wHsKC+aYC75aLnS6yW81d8JAFTBxsi0=
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=
Expand Down
20 changes: 20 additions & 0 deletions lifecycle/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -48,3 +50,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()
}
60 changes: 38 additions & 22 deletions lifecycle/distribute.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b785b7d

Please sign in to comment.