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 release bundles deletion locally and remotely #2452

Merged
merged 5 commits into from
Mar 17, 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
20 changes: 20 additions & 0 deletions docs/lifecycle/deletelocal/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package deletelocal

var Usage = []string{"rbdell [command options] <release bundle name> <release bundle version>",
"rbdell [command options] <release bundle name> <release bundle version> <environment>"}

func GetDescription() string {
return "Delete all release bundle promotions to an environment or delete a release bundle locally altogether."
}

func GetArguments() string {
return ` release bundle name
Name of the Release Bundle to delete locally.

release bundle version
Version of the Release Bundle to delete locally.

environment
If provided, all promotions to this environment are deleted.
Otherwise, the release bundle is deleted locally with all its promotions.`
}
15 changes: 15 additions & 0 deletions docs/lifecycle/deleteremote/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package deleteremote

var Usage = []string{"rbdelr [command options] <release bundle name> <release bundle version>"}

func GetDescription() string {
return "Delete a release bundle remotely."
}

func GetArguments() string {
return ` release bundle name
Name of the Release Bundle to delete remotely.

release bundle version
Version of the Release Bundle to delete remotely.`
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240218115031-cc5c8b521695
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20240225133759-6d962fb2a10a

// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240218093454-1c352a93c23d
replace github.com/jfrog/jfrog-client-go => github.com/RobiNino/jfrog-client-go v0.0.0-20240225133441-cd1999c6fa5d

// replace github.com/jfrog/jfrog-cli-security => github.com/jfrog/jfrog-cli-security v1.0.2-0.20240215122147-517c589b5ada

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231220102935-c8776c613ad8
replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240222124058-bd9687a8666e

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
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-cli-core/v2 v2.0.0-20240225133759-6d962fb2a10a h1:SqbBcGkufU2X4oYyNOshe6iefk0L/2TtsrkOzGTqRvA=
github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20240225133759-6d962fb2a10a/go.mod h1:FeMVBhzeTy++U+K1njJMgQm/5SYsKi+J5Q5T5plo5q4=
github.com/RobiNino/jfrog-client-go v0.0.0-20240225133441-cd1999c6fa5d h1:HFpWj5aRjWNnWLOtCSh/mcjspuIAZqdQvPNxhVvnT6E=
github.com/RobiNino/jfrog-client-go v0.0.0-20240225133441-cd1999c6fa5d/go.mod h1:jcZYTyo9H4GtZ6eAYIfKm1ulxeTbshcBBA+YUbWlHNc=
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 @@ -121,18 +125,14 @@ github.com/jedib0t/go-pretty/v6 v6.5.4 h1:gOGo0613MoqUcf0xCj+h/V3sHDaZasfv152G6/
github.com/jedib0t/go-pretty/v6 v6.5.4/go.mod h1:5LQIxa52oJ/DlDSLv0HEkWOFMDGoWkJb9ss5KqPpJBg=
github.com/jfrog/archiver/v3 v3.6.0 h1:OVZ50vudkIQmKMgA8mmFF9S0gA47lcag22N13iV3F1w=
github.com/jfrog/archiver/v3 v3.6.0/go.mod h1:fCAof46C3rAXgZurS8kNRNdSVMKBbZs+bNNhPYxLldI=
github.com/jfrog/build-info-go v1.9.23 h1:+TwUIBEJwRvz9skR8xBfY5ti8Vl4Z6iMCkFbkclnEN0=
github.com/jfrog/build-info-go v1.9.23/go.mod h1:QHcKuesY4MrBVBuEwwBz4uIsX6mwYuMEDV09ng4AvAU=
github.com/jfrog/build-info-go v1.8.9-0.20240222124058-bd9687a8666e h1:NzB2yvEojIhP5KIX9SeCqSljZmoiE98hBzXYvvi52D0=
github.com/jfrog/build-info-go v1.8.9-0.20240222124058-bd9687a8666e/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-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY=
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-core/v2 v2.48.1 h1:rRqI82btSFKFStGd7uEiheeBAuEjrw+ZZbE1abaKUBU=
github.com/jfrog/jfrog-cli-core/v2 v2.48.1/go.mod h1:9aZHtR9x7s9VUa5AalOjJkxMMPSgxXgQ5hdU3vzMwcs=
github.com/jfrog/jfrog-cli-security v1.0.3 h1:TUfPmMEavLZzxvHJSzuXg1m9OQolGL/atE8cRbuPvls=
github.com/jfrog/jfrog-cli-security v1.0.3/go.mod h1:NHmNHYlF6g4QSDyTQ3yUM57+WXZQfqskc2C1Mxj/FQY=
github.com/jfrog/jfrog-client-go v1.37.1 h1:BqIWGPajC5vhUo5dcQ9KEJr0EVANr/O4cfEqRYvzvRg=
github.com/jfrog/jfrog-client-go v1.37.1/go.mod h1:y+zeO0LeT2uHoHs4/fXHrm5dfF02bg6Dw3cNJxgJ5LY=
github.com/jszwec/csvutil v1.10.0 h1:upMDUxhQKqZ5ZDCs/wy+8Kib8rZR8I8lOR34yJkdqhI=
github.com/jszwec/csvutil v1.10.0/go.mod h1:/E4ONrmGkwmWsk9ae9jpXnv9QT8pLHEPcCirMFhxG9I=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down
92 changes: 90 additions & 2 deletions lifecycle/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli/docs/common"
rbCreate "github.com/jfrog/jfrog-cli/docs/lifecycle/create"
rbDeleteLocal "github.com/jfrog/jfrog-cli/docs/lifecycle/deletelocal"
rbDeleteRemote "github.com/jfrog/jfrog-cli/docs/lifecycle/deleteremote"
rbDistribute "github.com/jfrog/jfrog-cli/docs/lifecycle/distribute"
rbPromote "github.com/jfrog/jfrog-cli/docs/lifecycle/promote"
"github.com/jfrog/jfrog-cli/utils/cliutils"
Expand Down Expand Up @@ -59,6 +61,30 @@ func GetCommands() []cli.Command {
Category: lcCategory,
Action: distribute,
},
{
Name: "release-bundle-delete-local",
Aliases: []string{"rbdell"},
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleDeleteLocal),
Usage: rbDeleteLocal.GetDescription(),
HelpName: coreCommon.CreateUsage("rbdell", rbDeleteLocal.GetDescription(), rbDeleteLocal.Usage),
UsageText: rbDeleteLocal.GetArguments(),
ArgsUsage: common.CreateEnvVars(),
BashComplete: coreCommon.CreateBashCompletionFunc(),
Category: lcCategory,
Action: deleteLocal,
},
{
Name: "release-bundle-delete-remote",
Aliases: []string{"rbdelr"},
Flags: cliutils.GetCommandFlags(cliutils.ReleaseBundleDeleteRemote),
Usage: rbDeleteRemote.GetDescription(),
HelpName: coreCommon.CreateUsage("rbdelr", rbDeleteRemote.GetDescription(), rbDeleteRemote.Usage),
UsageText: rbDeleteRemote.GetArguments(),
ArgsUsage: common.CreateEnvVars(),
BashComplete: coreCommon.CreateBashCompletionFunc(),
Category: lcCategory,
Action: deleteRemote,
},
})
}

Expand Down Expand Up @@ -118,11 +144,11 @@ func promote(c *cli.Context) error {
return err
}

createCmd := lifecycle.NewReleaseBundlePromoteCommand().SetServerDetails(lcDetails).SetReleaseBundleName(c.Args().Get(0)).
promoteCmd := lifecycle.NewReleaseBundlePromoteCommand().SetServerDetails(lcDetails).SetReleaseBundleName(c.Args().Get(0)).
SetReleaseBundleVersion(c.Args().Get(1)).SetEnvironment(c.Args().Get(2)).SetSigningKeyName(c.String(cliutils.SigningKey)).
SetSync(c.Bool(cliutils.Sync)).SetReleaseBundleProject(cliutils.GetProject(c)).
SetIncludeReposPatterns(splitRepos(c, cliutils.IncludeRepos)).SetExcludeReposPatterns(splitRepos(c, cliutils.ExcludeRepos))
return commands.Exec(createCmd)
return commands.Exec(promoteCmd)
}

func distribute(c *cli.Context) error {
Expand Down Expand Up @@ -150,6 +176,68 @@ func distribute(c *cli.Context) error {
return commands.Exec(distributeCmd)
}

func deleteLocal(c *cli.Context) error {
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
return err
}

if c.NArg() != 2 && c.NArg() != 3 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}

lcDetails, err := createLifecycleDetailsByFlags(c)
if err != nil {
return err
}

environment := ""
if c.NArg() == 3 {
environment = c.Args().Get(2)
}

deleteCmd := lifecycle.NewReleaseBundleDeleteCommand().
SetServerDetails(lcDetails).
SetReleaseBundleName(c.Args().Get(0)).
SetReleaseBundleVersion(c.Args().Get(1)).
SetEnvironment(environment).
SetQuiet(cliutils.GetQuietValue(c)).
SetReleaseBundleProject(cliutils.GetProject(c)).
SetSync(c.Bool(cliutils.Sync))
return commands.Exec(deleteCmd)
}

func deleteRemote(c *cli.Context) error {
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
return err
}

if c.NArg() != 2 {
return cliutils.WrongNumberOfArgumentsHandler(c)
}

lcDetails, err := createLifecycleDetailsByFlags(c)
if err != nil {
return err
}

distributionRules, maxWaitMinutes, _, err := distribution.InitReleaseBundleDistributeCmd(c)
if err != nil {
return err
}

deleteCmd := lifecycle.NewReleaseBundleRemoteDeleteCommand().
SetServerDetails(lcDetails).
SetReleaseBundleName(c.Args().Get(0)).
SetReleaseBundleVersion(c.Args().Get(1)).
SetDistributionRules(distributionRules).
SetDryRun(c.Bool("dry-run")).
SetMaxWaitMinutes(maxWaitMinutes).
SetQuiet(cliutils.GetQuietValue(c)).
SetReleaseBundleProject(cliutils.GetProject(c)).
SetSync(c.Bool(cliutils.Sync))
return commands.Exec(deleteCmd)
}

func validateDistributeCommand(c *cli.Context) error {
if err := distribution.ValidateReleaseBundleDistributeCmd(c); err != nil {
return err
Expand Down
20 changes: 17 additions & 3 deletions utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ const (
TransferInstall = "transfer-plugin-install"

// Lifecycle commands keys
ReleaseBundleCreate = "release-bundle-create"
ReleaseBundlePromote = "release-bundle-promote"
ReleaseBundleDistribute = "release-bundle-distribute"
ReleaseBundleCreate = "release-bundle-create"
ReleaseBundlePromote = "release-bundle-promote"
ReleaseBundleDistribute = "release-bundle-distribute"
ReleaseBundleDeleteLocal = "release-bundle-delete-local"
ReleaseBundleDeleteRemote = "release-bundle-delete-remote"

// Access Token Create commands keys
AccessTokenCreate = "access-token-create"
Expand Down Expand Up @@ -563,6 +565,7 @@ const (
// Unique lifecycle flags
lifecyclePrefix = "lc-"
lcUrl = lifecyclePrefix + url
lcQuiet = lifecyclePrefix + quiet
lcSync = lifecyclePrefix + Sync
lcProject = lifecyclePrefix + Project
Builds = "builds"
Expand Down Expand Up @@ -1618,6 +1621,10 @@ var flagsMap = map[string]cli.Flag{
Name: url,
Usage: "[Optional] JFrog platform URL.` `",
},
lcQuiet: cli.BoolFlag{
Name: quiet,
Usage: "[Default: $CI] Set to true to skip the delete confirmation message.` `",
},
lcSync: cli.BoolFlag{
Name: Sync,
Usage: "[Default: false] Set to true to run synchronously.` `",
Expand Down Expand Up @@ -2000,6 +2007,13 @@ var commandFlags = map[string][]string{
lcUrl, user, password, accessToken, serverId, lcDryRun, DistRules, site, city, countryCodes,
InsecureTls, CreateRepo, lcPathMappingPattern, lcPathMappingTarget,
},
ReleaseBundleDeleteLocal: {
lcUrl, user, password, accessToken, serverId, lcQuiet, lcSync, lcProject,
},
ReleaseBundleDeleteRemote: {
lcUrl, user, password, accessToken, serverId, lcQuiet, lcDryRun, DistRules, site, city, countryCodes,
lcSync, maxWaitMinutes, lcProject,
},
// Mission Control's commands
McConfig: {
mcUrl, mcAccessToken, mcInteractive,
Expand Down
Loading