From 577841c0b0edb726a3f4cccc71d1546e588bf870 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Wed, 18 Oct 2023 19:17:04 +0200 Subject: [PATCH 1/3] Added rerun command --- cmd/rerunPipelineJob.go | 77 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 cmd/rerunPipelineJob.go diff --git a/cmd/rerunPipelineJob.go b/cmd/rerunPipelineJob.go new file mode 100644 index 0000000..0fd02ff --- /dev/null +++ b/cmd/rerunPipelineJob.go @@ -0,0 +1,77 @@ +// Copyright © 2023 +// +// 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/pipeline_job" + "github.com/equinor/radix-cli/pkg/client" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +// rerunCmd represents the rerun command +var rerunCmd = &cobra.Command{ + Use: "rerun", + Short: "Rerun Radix pipeline job", + Long: `Rerun failed of stopped Radix pipeline job . + + Example: + # Get logs for a pipeline job + rx rerun --application radix-test --job radix-pipeline-20230323185013-ehvnz +`, + + RunE: func(cmd *cobra.Command, args []string) error { + appName, err := getAppNameFromConfigOrFromParameter(cmd, "application") + if err != nil { + return err + } + + if appName == nil || *appName == "" { + return errors.New("application name is required") + } + + jobName, _ := cmd.Flags().GetString("job") + + if jobName == "" { + return errors.New("`job` is required") + } + + cmd.SilenceUsage = true + + apiClient, err := client.GetForCommand(cmd) + if err != nil { + return err + } + + params := pipeline_job.NewRerunApplicationJobParams() + params.AppName = *appName + params.JobName = jobName + + job, err := apiClient.PipelineJob.RerunApplicationJob(¶ms, nil) + log.Info(job) // TODO + return err + }, +} + +func init() { + rootCmd.AddCommand(rerunCmd) + rerunCmd.Flags().StringP("application", "a", "", "Name of the application for the job") + rerunCmd.Flags().StringP("job", "j", "", "The job to get logs for") + rerunCmd.Flags().StringP("user", "u", "", "The user who triggered the deploy") + rerunCmd.Flags().BoolP("follow", "f", false, "Follow deploy") + setContextSpecificPersistentFlags(rerunCmd) +} From d344db491d458a377a4fd004291eb5f0a467ba81 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Thu, 19 Oct 2023 13:38:24 +0200 Subject: [PATCH 2/3] Added rerun pipeline-job command --- cmd/createJob.go | 7 +++-- ...unPipelineJob.go => restartPipelineJob.go} | 28 ++++++++----------- .../pipeline_job/pipeline_job_client.go | 2 +- .../rerun_application_job_responses.go | 14 +++++----- generated-client/models/job.go | 9 +++++- generated-client/models/job_summary.go | 15 +++++++++- 6 files changed, 46 insertions(+), 29 deletions(-) rename cmd/{rerunPipelineJob.go => restartPipelineJob.go} (64%) diff --git a/cmd/createJob.go b/cmd/createJob.go index 9e8ef1b..5728a8f 100644 --- a/cmd/createJob.go +++ b/cmd/createJob.go @@ -22,9 +22,10 @@ import ( // createJobCmd represents the triggering of pipeline command var createJobCmd = &cobra.Command{ - Use: "job", - Short: "Create job command", - Long: `Will be the main command for triggering pipelines.`, + Use: "pipeline-job", + Aliases: []string{"job"}, + Short: "Create job command", + Long: `Will be the main command for triggering pipelines.`, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("please specify the pipeline you want to create") }, diff --git a/cmd/rerunPipelineJob.go b/cmd/restartPipelineJob.go similarity index 64% rename from cmd/rerunPipelineJob.go rename to cmd/restartPipelineJob.go index 0fd02ff..08ec629 100644 --- a/cmd/rerunPipelineJob.go +++ b/cmd/restartPipelineJob.go @@ -19,19 +19,18 @@ import ( "github.com/equinor/radix-cli/generated-client/client/pipeline_job" "github.com/equinor/radix-cli/pkg/client" - log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) -// rerunCmd represents the rerun command -var rerunCmd = &cobra.Command{ - Use: "rerun", - Short: "Rerun Radix pipeline job", - Long: `Rerun failed of stopped Radix pipeline job . +// restartPipelineJobCmd represents the rerun command +var restartPipelineJobCmd = &cobra.Command{ + Use: "pipeline-job", + Aliases: []string{"job"}, + Short: "Restart Radix pipeline job", + Long: `Restart failed of stopped Radix pipeline job. Example: - # Get logs for a pipeline job - rx rerun --application radix-test --job radix-pipeline-20230323185013-ehvnz + rx restart pipeline-job --application radix-test --job radix-pipeline-20230323185013-ehvnz `, RunE: func(cmd *cobra.Command, args []string) error { @@ -61,17 +60,14 @@ var rerunCmd = &cobra.Command{ params.AppName = *appName params.JobName = jobName - job, err := apiClient.PipelineJob.RerunApplicationJob(¶ms, nil) - log.Info(job) // TODO + _, err = apiClient.PipelineJob.RerunApplicationJob(params, nil) return err }, } func init() { - rootCmd.AddCommand(rerunCmd) - rerunCmd.Flags().StringP("application", "a", "", "Name of the application for the job") - rerunCmd.Flags().StringP("job", "j", "", "The job to get logs for") - rerunCmd.Flags().StringP("user", "u", "", "The user who triggered the deploy") - rerunCmd.Flags().BoolP("follow", "f", false, "Follow deploy") - setContextSpecificPersistentFlags(rerunCmd) + restartCmd.AddCommand(restartPipelineJobCmd) + restartPipelineJobCmd.Flags().StringP("application", "a", "", "Name of the application for the job") + restartPipelineJobCmd.Flags().StringP("job", "j", "", "The job to restart") + setContextSpecificPersistentFlags(restartPipelineJobCmd) } diff --git a/generated-client/client/pipeline_job/pipeline_job_client.go b/generated-client/client/pipeline_job/pipeline_job_client.go index 7d1bc9b..eca722b 100644 --- a/generated-client/client/pipeline_job/pipeline_job_client.go +++ b/generated-client/client/pipeline_job/pipeline_job_client.go @@ -417,7 +417,7 @@ func (a *Client) RerunApplicationJob(params *RerunApplicationJobParams, authInfo op := &runtime.ClientOperation{ ID: "rerunApplicationJob", Method: "POST", - PathPattern: "/applications/{appName}/jobs/{jobName}/restart", + PathPattern: "/applications/{appName}/jobs/{jobName}/rerun", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http", "https"}, diff --git a/generated-client/client/pipeline_job/rerun_application_job_responses.go b/generated-client/client/pipeline_job/rerun_application_job_responses.go index 4022987..cfbf564 100644 --- a/generated-client/client/pipeline_job/rerun_application_job_responses.go +++ b/generated-client/client/pipeline_job/rerun_application_job_responses.go @@ -39,7 +39,7 @@ func (o *RerunApplicationJobReader) ReadResponse(response runtime.ClientResponse } return nil, result default: - return nil, runtime.NewAPIError("[POST /applications/{appName}/jobs/{jobName}/restart] rerunApplicationJob", response, response.Code()) + return nil, runtime.NewAPIError("[POST /applications/{appName}/jobs/{jobName}/rerun] rerunApplicationJob", response, response.Code()) } } @@ -87,11 +87,11 @@ func (o *RerunApplicationJobNoContent) Code() int { } func (o *RerunApplicationJobNoContent) Error() string { - return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/restart][%d] rerunApplicationJobNoContent ", 204) + return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/rerun][%d] rerunApplicationJobNoContent ", 204) } func (o *RerunApplicationJobNoContent) String() string { - return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/restart][%d] rerunApplicationJobNoContent ", 204) + return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/rerun][%d] rerunApplicationJobNoContent ", 204) } func (o *RerunApplicationJobNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { @@ -143,11 +143,11 @@ func (o *RerunApplicationJobUnauthorized) Code() int { } func (o *RerunApplicationJobUnauthorized) Error() string { - return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/restart][%d] rerunApplicationJobUnauthorized ", 401) + return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/rerun][%d] rerunApplicationJobUnauthorized ", 401) } func (o *RerunApplicationJobUnauthorized) String() string { - return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/restart][%d] rerunApplicationJobUnauthorized ", 401) + return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/rerun][%d] rerunApplicationJobUnauthorized ", 401) } func (o *RerunApplicationJobUnauthorized) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { @@ -199,11 +199,11 @@ func (o *RerunApplicationJobNotFound) Code() int { } func (o *RerunApplicationJobNotFound) Error() string { - return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/restart][%d] rerunApplicationJobNotFound ", 404) + return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/rerun][%d] rerunApplicationJobNotFound ", 404) } func (o *RerunApplicationJobNotFound) String() string { - return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/restart][%d] rerunApplicationJobNotFound ", 404) + return fmt.Sprintf("[POST /applications/{appName}/jobs/{jobName}/rerun][%d] rerunApplicationJobNotFound ", 404) } func (o *RerunApplicationJobNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { diff --git a/generated-client/models/job.go b/generated-client/models/job.go index 93832c0..808e776 100644 --- a/generated-client/models/job.go +++ b/generated-client/models/job.go @@ -21,7 +21,7 @@ import ( // swagger:model Job type Job struct { - // Branch branch to build from + // Branch to build from // Example: master Branch string `json:"branch,omitempty"` @@ -45,6 +45,10 @@ type Job struct { // Example: 2006-01-02T15:04:05Z Ended string `json:"ended,omitempty"` + // Image tags names for components - if empty will use default logic + // Example: component1: tag1,component2: tag2 + ImageTagNames map[string]string `json:"imageTagNames,omitempty"` + // Name of the job // Example: radix-pipeline-20181029135644-algpv-6hznh Name string `json:"name,omitempty"` @@ -58,6 +62,9 @@ type Job struct { // Example: component-6hznh PromotedDeploymentName string `json:"promotedDeploymentName,omitempty"` + // RadixDeployment name, which is promoted + PromotedFromDeployment string `json:"promotedFromDeployment,omitempty"` + // PromotedFromEnvironment the name of the environment that was promoted from // Example: dev PromotedFromEnvironment string `json:"promotedFromEnvironment,omitempty"` diff --git a/generated-client/models/job_summary.go b/generated-client/models/job_summary.go index 7643348..f4ef220 100644 --- a/generated-client/models/job_summary.go +++ b/generated-client/models/job_summary.go @@ -24,7 +24,7 @@ type JobSummary struct { // Example: radix-pipeline-20181029135644-algpv-6hznh AppName string `json:"appName,omitempty"` - // Branch branch to build from + // Branch to build from // Example: master Branch string `json:"branch,omitempty"` @@ -44,6 +44,10 @@ type JobSummary struct { // Example: ["dev","qa"] Environments []string `json:"environments"` + // Image tags names for components - if empty will use default logic + // Example: component1: tag1,component2: tag2 + ImageTagNames map[string]string `json:"imageTagNames,omitempty"` + // Name of the job // Example: radix-pipeline-20181029135644-algpv-6hznh Name string `json:"name,omitempty"` @@ -53,6 +57,15 @@ type JobSummary struct { // Enum: [build-deploy build] Pipeline string `json:"pipeline,omitempty"` + // RadixDeployment name, which is promoted + PromotedFromDeployment string `json:"promotedFromDeployment,omitempty"` + + // Environment name, from which the Radix deployment is promoted + PromotedFromEnvironment string `json:"promotedFromEnvironment,omitempty"` + + // Environment name, to which the Radix deployment is promoted + PromotedToEnvironment string `json:"promotedToEnvironment,omitempty"` + // Started timestamp // Example: 2006-01-02T15:04:05Z Started string `json:"started,omitempty"` From fa852fa08b5d2c7bf33e2d9654381205c5e26a80 Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Thu, 19 Oct 2023 15:16:24 +0200 Subject: [PATCH 3/3] Cleanup --- Makefile | 7 ------- cmd/{createJob.go => createPipelineJob.go} | 2 +- cmd/{logsJob.go => logsPipelineJob.go} | 7 ++++--- 3 files changed, 5 insertions(+), 11 deletions(-) rename cmd/{createJob.go => createPipelineJob.go} (96%) rename cmd/{logsJob.go => logsPipelineJob.go} (96%) diff --git a/Makefile b/Makefile index c93e4f3..fff80ff 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,6 @@ RELEASE_NOTE ?= "First release" generate-client: swagger generate client -t ./generated-client -f https://api.radix.equinor.com/swaggerui/swagger.json -A radixapi -.PHONY: release -release: - git tag -a v$(VERSION) -m "$(RELEASE_NOTE)" - git push origin v$(VERSION) - git config --global credential.helper cache - goreleaser --rm-dist - .PHONY: push push: docker build . -t ghcr.io/equinor/radix/rx:latest diff --git a/cmd/createJob.go b/cmd/createPipelineJob.go similarity index 96% rename from cmd/createJob.go rename to cmd/createPipelineJob.go index 5728a8f..12d8ecc 100644 --- a/cmd/createJob.go +++ b/cmd/createPipelineJob.go @@ -24,7 +24,7 @@ import ( var createJobCmd = &cobra.Command{ Use: "pipeline-job", Aliases: []string{"job"}, - Short: "Create job command", + Short: "Create pipeline job command", Long: `Will be the main command for triggering pipelines.`, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("please specify the pipeline you want to create") diff --git a/cmd/logsJob.go b/cmd/logsPipelineJob.go similarity index 96% rename from cmd/logsJob.go rename to cmd/logsPipelineJob.go index 65d6944..10172bf 100644 --- a/cmd/logsJob.go +++ b/cmd/logsPipelineJob.go @@ -34,15 +34,16 @@ var completedJobStatuses = []string{"Succeeded", "Failed", "Stopped"} // logsJobCmd represents the logsJobCmd command var logsJobCmd = &cobra.Command{ - Use: "job", - Short: "Gets logs for a pipeline job", + Use: "pipeline-job", + Aliases: []string{"job"}, + Short: "Gets logs for a pipeline job", Long: `Gets and follows logs for a pipeline job. It may take few seconds to get the log. Example: # Get logs for a pipeline job - rx get logs job --application radix-test --job radix-pipeline-20230323185013-ehvnz + rx get logs pipeline-job --application radix-test --job radix-pipeline-20230323185013-ehvnz `, RunE: func(cmd *cobra.Command, args []string) error { appName, err := getAppNameFromConfigOrFromParameter(cmd, "application")