Skip to content

Commit

Permalink
update according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tianfeng92 committed Dec 1, 2023
1 parent aba4e5c commit 4d49404
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions internal/cmd/docker/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"time"

"github.com/saucelabs/saucectl/internal/credentials"
"github.com/saucelabs/saucectl/internal/http"
"github.com/saucelabs/saucectl/internal/region"
"github.com/spf13/cobra"
Expand All @@ -13,7 +12,6 @@ import (
var (
registryClient http.DockerRegistry
registryClientTimeout = 1 * time.Minute
registryPushTimeout = 1 * time.Minute
)

func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
Expand Down Expand Up @@ -43,7 +41,7 @@ func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
}

flags := cmd.PersistentFlags()
flags.StringVarP(&regio, "login-region", "r", "us-west-1", "The Sauce Labs region to login. Options: us-west-1, eu-central-1.")
flags.StringVarP(&regio, "region", "r", "us-west-1", "The Sauce Labs region to login. Options: us-west-1, eu-central-1.")

cmd.AddCommand(
PushCommand(),
Expand Down
12 changes: 9 additions & 3 deletions internal/cmd/docker/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"os"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
Expand All @@ -21,8 +22,10 @@ import (
)

func PushCommand() *cobra.Command {
var registryPushTimeout time.Duration

cmd := &cobra.Command{
Use: "push",
Use: "push <REPO> <IMAGE_NAME>",
Short: "Push a Docker image to the Sauce Labs Container Registry.",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -53,14 +56,17 @@ func PushCommand() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to fetch auth token: %v", err)
}
return pushDockerImage(image, auth.Username, auth.Password)
return pushDockerImage(image, auth.Username, auth.Password, registryPushTimeout)
},
}

flags := cmd.PersistentFlags()
flags.DurationVar(&registryPushTimeout, "registry-push-timeout", 1*time.Minute, "Set timeout for docker push. Default: 1 minute.")

return cmd
}

func pushDockerImage(imageName, username, password string) error {
func pushDockerImage(imageName, username, password string, registryPushTimeout time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), registryPushTimeout)
defer cancel()

Expand Down

0 comments on commit 4d49404

Please sign in to comment.