From f98af08fe6bf513f4a13ae93635a98b2de400683 Mon Sep 17 00:00:00 2001 From: Melvin Zottola Date: Tue, 10 Oct 2023 14:17:48 +0200 Subject: [PATCH] feat: Add image-name to lifecycle & cronjob update (#208) --- cmd/cronjob.go | 7 +++++-- cmd/cronjob_update.go | 30 +++++++++++++++++++----------- cmd/lifecycle.go | 7 +++++-- cmd/lifecycle_update.go | 30 +++++++++++++++++++----------- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/cmd/cronjob.go b/cmd/cronjob.go index bc61604e..8112938e 100644 --- a/cmd/cronjob.go +++ b/cmd/cronjob.go @@ -2,10 +2,12 @@ package cmd import ( "context" - "github.com/qovery/qovery-cli/utils" + "os" + "github.com/qovery/qovery-client-go" "github.com/spf13/cobra" - "os" + + "github.com/qovery/qovery-cli/utils" ) var cronjobName string @@ -13,6 +15,7 @@ var cronjobNames string var cronjobCommitId string var cronjobBranch string var cronjobTag string +var cronjobImageName string var targetCronjobName string diff --git a/cmd/cronjob_update.go b/cmd/cronjob_update.go index 5c33731d..a1cae96f 100644 --- a/cmd/cronjob_update.go +++ b/cmd/cronjob_update.go @@ -2,13 +2,15 @@ package cmd import ( "fmt" + "io" + "os" + "github.com/pkg/errors" "github.com/pterm/pterm" - "github.com/qovery/qovery-cli/utils" "github.com/spf13/cobra" "golang.org/x/net/context" - "io" - "os" + + "github.com/qovery/qovery-cli/utils" ) var cronjobUpdateCmd = &cobra.Command{ @@ -24,14 +26,14 @@ var cronjobUpdateCmd = &cobra.Command{ panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - if cronjobTag != "" && cronjobBranch != "" { - utils.PrintlnError(fmt.Errorf("you can't use --tag and --branch at the same time")) + if (cronjobTag != "" || cronjobImageName != "") && cronjobBranch != "" { + utils.PrintlnError(fmt.Errorf("you can't use --tag or --image-name with --branch at the same time")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - if cronjobTag == "" && cronjobBranch == "" { - utils.PrintlnError(fmt.Errorf("you must use --tag or --branch")) + if cronjobTag == "" && cronjobImageName == "" && cronjobBranch == "" { + utils.PrintlnError(fmt.Errorf("you must use --tag or --image-name or --branch")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } @@ -65,14 +67,14 @@ var cronjobUpdateCmd = &cobra.Command{ docker := cronjob.Source.Docker.Get() image := cronjob.Source.Image.Get() - if docker != nil && cronjobTag != "" { - utils.PrintlnError(fmt.Errorf("you can't use --tag with a cronjob targetting a Dockerfile. Use --branch instead")) + if docker != nil && (cronjobTag != "" || cronjobImageName != "") { + utils.PrintlnError(fmt.Errorf("you can't use --tag or --image-name with a cronjob targetting a Dockerfile. Use --branch instead")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } if image != nil && cronjobBranch != "" { - utils.PrintlnError(fmt.Errorf("you can't use --branch with a cronjob targetting an image. Use --tag instead")) + utils.PrintlnError(fmt.Errorf("you can't use --branch with a cronjob targetting an image. Use --tag and/or --image-name instead")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } @@ -83,7 +85,12 @@ var cronjobUpdateCmd = &cobra.Command{ req.Source.Docker.Get().GitRepository.Branch = &cronjobBranch req.Source.Image.Set(nil) } else { - req.Source.Image.Get().Tag = &cronjobTag + if cronjobTag != "" { + req.Source.Image.Get().Tag = &cronjobTag + } + if cronjobImageName != "" { + req.Source.Image.Get().ImageName = &cronjobImageName + } req.Source.Docker.Set(nil) } @@ -108,4 +115,5 @@ func init() { cronjobUpdateCmd.Flags().StringVarP(&cronjobName, "cronjob", "n", "", "Cronjob Name") cronjobUpdateCmd.Flags().StringVarP(&cronjobBranch, "branch", "b", "", "Cronjob Branch") cronjobUpdateCmd.Flags().StringVarP(&cronjobTag, "tag", "t", "", "Cronjob Tag") + cronjobUpdateCmd.Flags().StringVarP(&cronjobImageName, "image-name", "", "", "Cronjob Image Name") } diff --git a/cmd/lifecycle.go b/cmd/lifecycle.go index dd4e9a23..6a95708e 100644 --- a/cmd/lifecycle.go +++ b/cmd/lifecycle.go @@ -2,16 +2,19 @@ package cmd import ( "context" - "github.com/qovery/qovery-cli/utils" + "os" + "github.com/qovery/qovery-client-go" "github.com/spf13/cobra" - "os" + + "github.com/qovery/qovery-cli/utils" ) var lifecycleName string var lifecycleNames string var lifecycleCommitId string var lifecycleTag string +var lifecycleImageName string var lifecycleBranch string var targetLifecycleName string diff --git a/cmd/lifecycle_update.go b/cmd/lifecycle_update.go index 3f3e378f..0b77fe04 100644 --- a/cmd/lifecycle_update.go +++ b/cmd/lifecycle_update.go @@ -2,13 +2,15 @@ package cmd import ( "fmt" + "io" + "os" + "github.com/pkg/errors" "github.com/pterm/pterm" - "github.com/qovery/qovery-cli/utils" "github.com/spf13/cobra" "golang.org/x/net/context" - "io" - "os" + + "github.com/qovery/qovery-cli/utils" ) var lifecycleUpdateCmd = &cobra.Command{ @@ -24,14 +26,14 @@ var lifecycleUpdateCmd = &cobra.Command{ panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - if lifecycleTag != "" && lifecycleBranch != "" { - utils.PrintlnError(fmt.Errorf("you can't use --tag and --branch at the same time")) + if (lifecycleTag != "" || lifecycleImageName != "") && lifecycleBranch != "" { + utils.PrintlnError(fmt.Errorf("you can't use --tag or --image-name with --branch at the same time")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } - if lifecycleTag == "" && lifecycleBranch == "" { - utils.PrintlnError(fmt.Errorf("you must use --tag or --branch")) + if lifecycleTag == "" && lifecycleImageName == "" && lifecycleBranch == "" { + utils.PrintlnError(fmt.Errorf("you must use --tag or --image-name or --branch")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } @@ -65,14 +67,14 @@ var lifecycleUpdateCmd = &cobra.Command{ docker := lifecycle.Source.Docker.Get() image := lifecycle.Source.Image.Get() - if docker != nil && lifecycleTag != "" { - utils.PrintlnError(fmt.Errorf("you can't use --tag with a lifecycle targetting a Dockerfile. Use --branch instead")) + if docker != nil && (lifecycleTag != "" || lifecycleImageName != "") { + utils.PrintlnError(fmt.Errorf("you can't use --tag or --image-name with a lifecycle targetting a Dockerfile. Use --branch instead")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } if image != nil && lifecycleBranch != "" { - utils.PrintlnError(fmt.Errorf("you can't use --branch with a lifecycle targetting an image. Use --tag instead")) + utils.PrintlnError(fmt.Errorf("you can't use --branch with a lifecycle targetting an image. Use --tag and/or --image-name instead")) os.Exit(1) panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011 } @@ -83,7 +85,12 @@ var lifecycleUpdateCmd = &cobra.Command{ req.Source.Docker.Get().GitRepository.Branch = &lifecycleBranch req.Source.Image.Set(nil) } else { - req.Source.Image.Get().Tag = &lifecycleTag + if lifecycleTag != "" { + req.Source.Image.Get().Tag = &lifecycleTag + } + if lifecycleImageName != "" { + req.Source.Image.Get().ImageName = &lifecycleImageName + } req.Source.Docker.Set(nil) } @@ -108,4 +115,5 @@ func init() { lifecycleUpdateCmd.Flags().StringVarP(&lifecycleName, "lifecycle", "n", "", "Lifecycle Name") lifecycleUpdateCmd.Flags().StringVarP(&lifecycleBranch, "branch", "b", "", "Lifecycle Branch") lifecycleUpdateCmd.Flags().StringVarP(&lifecycleTag, "tag", "t", "", "Lifecycle Tag") + lifecycleUpdateCmd.Flags().StringVarP(&lifecycleImageName, "image-name", "", "", "Lifecycle Image Name") }