Skip to content

Commit

Permalink
Added command to create a promote pipeline job. Changed the version c… (
Browse files Browse the repository at this point in the history
#42)

* Added command to create a promote pipeline job. Changed the version command

* Update cmd/promoteApplication.go

Co-authored-by: Nils Gustav Stråbø <65334626+nilsgstrabo@users.noreply.github.com>

* Update cmd/promoteApplication.go

Co-authored-by: Nils Gustav Stråbø <65334626+nilsgstrabo@users.noreply.github.com>

* Update cmd/promoteApplication.go

Co-authored-by: Nils Gustav Stråbø <65334626+nilsgstrabo@users.noreply.github.com>

* Update cmd/promoteApplication.go

Co-authored-by: Nils Gustav Stråbø <65334626+nilsgstrabo@users.noreply.github.com>

* Update buildDeployApplication.go

* Create deployApplication.go

Co-authored-by: Nils Gustav Stråbø <65334626+nilsgstrabo@users.noreply.github.com>
  • Loading branch information
satr and nilsgstrabo authored Jan 12, 2023
1 parent 4131d49 commit 3b532f3
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
86 changes: 86 additions & 0 deletions cmd/promoteApplication.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
12 changes: 8 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ 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.
`)

// 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
Expand Down
38 changes: 0 additions & 38 deletions cmd/version.go

This file was deleted.

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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
github.com/go-openapi/strfmt v0.21.3
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
)

Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down

0 comments on commit 3b532f3

Please sign in to comment.