Skip to content

Commit

Permalink
feat: Add image-name to lifecycle & cronjob update
Browse files Browse the repository at this point in the history
  • Loading branch information
mzottola committed Oct 10, 2023
1 parent 4d2899c commit dddcabe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
7 changes: 5 additions & 2 deletions cmd/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ 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
var cronjobNames string
var cronjobCommitId string
var cronjobBranch string
var cronjobTag string
var cronjobImageName string

var targetCronjobName string

Expand Down
30 changes: 19 additions & 11 deletions cmd/cronjob_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

Expand All @@ -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")
}
7 changes: 5 additions & 2 deletions cmd/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 19 additions & 11 deletions cmd/lifecycle_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

Expand All @@ -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")
}

0 comments on commit dddcabe

Please sign in to comment.