Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifactory Release Lifecycle Management - Support distribution sync and project #1140

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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.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

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
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 @@ -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()
}
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
RobiNino marked this conversation as resolved.
Show resolved Hide resolved
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
Loading