diff --git a/README.md b/README.md index 95c6fdb..b8109c9 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ NOTE: If there is a change to the API, you make need to point to the API environ We are making releases available as github releases using [go-releaser](https://goreleaser.com/). The release process is controlled by the `.goreleaser.yml` file. To make a release: -1. Set the version number in the constant `version` in the file `cmd/version.go` +1. Set the version number in the constant `version` in the file `cmd/root.go`. The version will be shown with the command `rx --version` 2. Ensure there is no `dist` folder in the project (left from previous release) 3. Get the [personal access token](https://github.com/settings/tokens) - with access to repository and `write:packages` scope, and with enabled SSO for organisation (or create it) 4. Login to the docker repository with your user-name, using personal access token as a password (personal user=name/password authentication is or will be deprecated) diff --git a/cmd/promoteApplication.go b/cmd/promoteApplication.go new file mode 100644 index 0000000..ffc9e3a --- /dev/null +++ b/cmd/promoteApplication.go @@ -0,0 +1,86 @@ +// Copyright © 2022 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "errors" + + "github.com/equinor/radix-cli/generated-client/client/application" + "github.com/equinor/radix-cli/generated-client/models" + "github.com/equinor/radix-cli/pkg/client" + "github.com/spf13/cobra" +) + +const promoteApplicationEnabled = true + +// promoteApplicationCmd represents the buildApplication command +var promoteApplicationCmd = &cobra.Command{ + Use: "promote", + Short: "Will trigger promote of a Radix application", + Long: `Triggers promote of a Radix application deployment`, + RunE: func(cmd *cobra.Command, args []string) error { + appName, err := getAppNameFromConfigOrFromParameter(cmd, "application") + if err != nil { + return err + } + + deploymentName, _ := cmd.Flags().GetString("deployment") + fromEnvironment, _ := cmd.Flags().GetString("from-environment") + toEnvironment, _ := cmd.Flags().GetString("to-environment") + triggeredByUser, _ := cmd.Flags().GetString("user") + follow, _ := cmd.Flags().GetBool("follow") + + if appName == nil || *appName == "" || deploymentName == "" || fromEnvironment == "" || toEnvironment == "" { + return errors.New("application name, deployment name, from and to environments are required") + } + + apiClient, err := client.GetForCommand(cmd) + if err != nil { + return err + } + triggerPipelineParams := application.NewTriggerPipelinePromoteParams() + triggerPipelineParams.SetAppName(*appName) + triggerPipelineParams.SetPipelineParametersPromote(&models.PipelineParametersPromote{ + DeploymentName: deploymentName, + FromEnvironment: fromEnvironment, + ToEnvironment: toEnvironment, + TriggeredBy: triggeredByUser, + }) + + newJob, err := apiClient.Application.TriggerPipelinePromote(triggerPipelineParams, nil) + if err != nil { + return err + } + + jobName := newJob.GetPayload().Name + if follow { + getLogsJob(cmd, apiClient, *appName, jobName) + } + + return nil + }, +} + +func init() { + if promoteApplicationEnabled { + createJobCmd.AddCommand(promoteApplicationCmd) + promoteApplicationCmd.Flags().StringP("application", "a", "", "Name of the application to be promoted") + promoteApplicationCmd.Flags().StringP("deployment", "d", "", "Name of a deployment to be promoted") + promoteApplicationCmd.Flags().StringP("from-environment", "", "", "The deployment source environment") + promoteApplicationCmd.Flags().StringP("to-environment", "", "", "The deployment target environment") + promoteApplicationCmd.Flags().StringP("user", "u", "", "The user who triggered the promote pipeline job") + promoteApplicationCmd.Flags().BoolP("follow", "f", false, "Follow the promote pipeline job log") + } +} diff --git a/cmd/root.go b/cmd/root.go index 5a258f2..a8180d3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,7 +17,10 @@ import ( "github.com/spf13/cobra" ) -const radixCLIError = "Error: Radix CLI executed with error" +const ( + radixCLIError = "Error: Radix CLI executed with error" + version = "1.4.0" +) var rootLongHelp = strings.TrimSpace(` A command line interface which allows you to interact with the Radix platform through automation. @@ -25,9 +28,10 @@ A command line interface which allows you to interact with the Radix platform th // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "rx", - Short: "Command line interface for Radix platform", - Long: rootLongHelp, + Use: "rx", + Short: "Command line interface for Radix platform", + Long: rootLongHelp, + Version: version, } // Execute the top level command diff --git a/cmd/version.go b/cmd/version.go deleted file mode 100644 index 2e754bd..0000000 --- a/cmd/version.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright © 2022 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package cmd - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -const version = "1.3.0" - -// versionCmd represents the version command -var versionCmd = &cobra.Command{ - Use: "version", - Short: "Version number", - Long: `Print the version number of the Radix CLI.`, - RunE: func(cmd *cobra.Command, args []string) error { - fmt.Printf("Radix CLI version %s\n", version) - return nil - }, -} - -func init() { - rootCmd.AddCommand(versionCmd) -} diff --git a/go.mod b/go.mod index 35c48a3..bba2902 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/equinor/radix-cli go 1.18 require ( - github.com/equinor/radix-operator v1.29.1 + github.com/equinor/radix-operator v1.31.9 github.com/fatih/color v1.13.0 github.com/go-openapi/errors v0.20.3 github.com/go-openapi/runtime v0.24.1 @@ -11,7 +11,7 @@ require ( github.com/go-openapi/swag v0.22.3 github.com/go-openapi/validate v0.22.0 github.com/sirupsen/logrus v1.9.0 - github.com/spf13/cobra v1.5.0 + github.com/spf13/cobra v1.6.1 k8s.io/client-go v0.23.9 ) @@ -28,7 +28,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/equinor/radix-common v1.2.3 // indirect + github.com/equinor/radix-common v1.2.5 // indirect github.com/go-logr/logr v1.2.2 // indirect github.com/go-openapi/analysis v0.21.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect @@ -44,7 +44,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/googleapis/gnostic v0.5.5 // indirect github.com/imdario/mergo v0.3.13 // indirect - github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect diff --git a/go.sum b/go.sum index eea7f05..01d96b6 100644 --- a/go.sum +++ b/go.sum @@ -136,10 +136,10 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/equinor/radix-common v1.2.3 h1:EF8DpmTHOpIMiIxloPYpegZtsc0TUD7PWqfCAt7Kcq8= -github.com/equinor/radix-common v1.2.3/go.mod h1:0fEaqgUki0eF9xyoY3Ei9euB5dzSI4mk/5fk6ER3U/Q= -github.com/equinor/radix-operator v1.29.1 h1:x+E91vHuYhsZkRzwDj8ua9/MjKKbecf/TbUPE8G+KZ0= -github.com/equinor/radix-operator v1.29.1/go.mod h1:2dwnqpfdKLv7mjZ2IOe5irJT6Bc6DWYezNb5X6bNw9c= +github.com/equinor/radix-common v1.2.5 h1:HGVLK9Or6Je9ZdQ3Xe/buezHcpyVBgUwDP4Zb3uR3q4= +github.com/equinor/radix-common v1.2.5/go.mod h1:0fEaqgUki0eF9xyoY3Ei9euB5dzSI4mk/5fk6ER3U/Q= +github.com/equinor/radix-operator v1.31.9 h1:9XA0Uj+ApXUXr9lLic9M12RebIuRyjCi+YXeYJOTf4s= +github.com/equinor/radix-operator v1.31.9/go.mod h1:HHIHQgDFqowm1ZPOtbzxreCYc2Od7AEbA+YRjReziHY= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= @@ -356,8 +356,9 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1: github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= +github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= @@ -537,8 +538,8 @@ github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk= -github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= -github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= +github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= +github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=