Merge pull request #3555 from thaJeztah/no_urlutils

cli/command/image: remove use of docker/docker/pkg/urlutil
This commit is contained in:
Sebastiaan van Stijn 2022-04-29 13:49:31 +02:00 committed by GitHub
commit 1a2daffc51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 23 deletions

View File

@ -2,15 +2,14 @@ package image
import ( import (
"context" "context"
"io"
"os" "os"
"strings"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
dockeropts "github.com/docker/cli/opts" dockeropts "github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/urlutil"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -50,37 +49,37 @@ func NewImportCommand(dockerCli command.Cli) *cobra.Command {
} }
func runImport(dockerCli command.Cli, options importOptions) error { func runImport(dockerCli command.Cli, options importOptions) error {
var ( var source types.ImageImportSource
in io.Reader switch {
srcName = options.source case options.source == "-":
) // import from STDIN
source = types.ImageImportSource{
if options.source == "-" { Source: dockerCli.In(),
in = dockerCli.In() SourceName: options.source,
} else if !urlutil.IsURL(options.source) { }
srcName = "-" case strings.HasPrefix(options.source, "https://"), strings.HasPrefix(options.source, "http://"):
// import from a remote source (handled by the daemon)
source = types.ImageImportSource{
SourceName: options.source,
}
default:
// import from a local file
file, err := os.Open(options.source) file, err := os.Open(options.source)
if err != nil { if err != nil {
return err return err
} }
defer file.Close() defer file.Close()
in = file source = types.ImageImportSource{
Source: file,
SourceName: "-",
}
} }
source := types.ImageImportSource{ responseBody, err := dockerCli.Client().ImageImport(context.Background(), source, options.reference, types.ImageImportOptions{
Source: in,
SourceName: srcName,
}
importOptions := types.ImageImportOptions{
Message: options.message, Message: options.message,
Changes: options.changes.GetAll(), Changes: options.changes.GetAll(),
Platform: options.platform, Platform: options.platform,
} })
clnt := dockerCli.Client()
responseBody, err := clnt.ImageImport(context.Background(), source, options.reference, importOptions)
if err != nil { if err != nil {
return err return err
} }