mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-29 17:05:46 +08:00
Merge pull request #1716 from distorhead/use-docker-cli-in-stream
build(cli): allow passing in-stream using command.Cli
This commit is contained in:
commit
9b7aada99b
@ -55,7 +55,7 @@ func defaultFilenames() []string {
|
|||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadLocalFiles(names []string) ([]File, error) {
|
func ReadLocalFiles(names []string, stdin io.Reader) ([]File, error) {
|
||||||
isDefault := false
|
isDefault := false
|
||||||
if len(names) == 0 {
|
if len(names) == 0 {
|
||||||
isDefault = true
|
isDefault = true
|
||||||
@ -67,7 +67,7 @@ func ReadLocalFiles(names []string) ([]File, error) {
|
|||||||
var dt []byte
|
var dt []byte
|
||||||
var err error
|
var err error
|
||||||
if n == "-" {
|
if n == "-" {
|
||||||
dt, err = io.ReadAll(os.Stdin)
|
dt, err = io.ReadAll(stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1398,7 +1398,7 @@ func TestReadLocalFilesDefault(t *testing.T) {
|
|||||||
for _, tf := range tt.filenames {
|
for _, tf := range tt.filenames {
|
||||||
require.NoError(t, os.WriteFile(tf, []byte(tf), 0644))
|
require.NoError(t, os.WriteFile(tf, []byte(tf), 0644))
|
||||||
}
|
}
|
||||||
files, err := ReadLocalFiles(nil)
|
files, err := ReadLocalFiles(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
require.Equal(t, len(tt.expected), len(files))
|
require.Equal(t, len(tt.expected), len(files))
|
||||||
|
@ -146,7 +146,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
|
|||||||
if url != "" {
|
if url != "" {
|
||||||
files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, in.files, printer)
|
files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, in.files, printer)
|
||||||
} else {
|
} else {
|
||||||
files, err = bake.ReadLocalFiles(in.files)
|
files, err = bake.ReadLocalFiles(in.files, dockerCli.In())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -312,7 +312,7 @@ func getImageID(resp map[string]string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runBasicBuild(ctx context.Context, dockerCli command.Cli, opts *controllerapi.BuildOptions, options buildOptions, printer *progress.Printer) (*client.SolveResponse, error) {
|
func runBasicBuild(ctx context.Context, dockerCli command.Cli, opts *controllerapi.BuildOptions, options buildOptions, printer *progress.Printer) (*client.SolveResponse, error) {
|
||||||
resp, res, err := cbuild.RunBuild(ctx, dockerCli, *opts, os.Stdin, printer, false)
|
resp, res, err := cbuild.RunBuild(ctx, dockerCli, *opts, dockerCli.In(), printer, false)
|
||||||
if res != nil {
|
if res != nil {
|
||||||
res.Done()
|
res.Done()
|
||||||
}
|
}
|
||||||
@ -346,7 +346,7 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro
|
|||||||
var retErr error
|
var retErr error
|
||||||
var resp *client.SolveResponse
|
var resp *client.SolveResponse
|
||||||
f := ioset.NewSingleForwarder()
|
f := ioset.NewSingleForwarder()
|
||||||
f.SetReader(os.Stdin)
|
f.SetReader(dockerCli.In())
|
||||||
if !options.noBuild {
|
if !options.noBuild {
|
||||||
pr, pw := io.Pipe()
|
pr, pw := io.Pipe()
|
||||||
f.SetWriter(pw, func() io.WriteCloser {
|
f.SetWriter(pw, func() io.WriteCloser {
|
||||||
|
@ -47,7 +47,7 @@ func debugShellCmd(dockerCli command.Cli) *cobra.Command {
|
|||||||
|
|
||||||
err = monitor.RunMonitor(ctx, "", nil, controllerapi.InvokeConfig{
|
err = monitor.RunMonitor(ctx, "", nil, controllerapi.InvokeConfig{
|
||||||
Tty: true,
|
Tty: true,
|
||||||
}, c, os.Stdin, os.Stdout, os.Stderr, printer)
|
}, c, dockerCli.In(), os.Stdout, os.Stderr, printer)
|
||||||
con.Reset()
|
con.Reset()
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
@ -19,7 +19,7 @@ func Disable(cmd *cobra.Command, args []string, toComplete string) ([]string, co
|
|||||||
|
|
||||||
func BakeTargets(files []string) ValidArgsFn {
|
func BakeTargets(files []string) ValidArgsFn {
|
||||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
f, err := bake.ReadLocalFiles(files)
|
f, err := bake.ReadLocalFiles(files, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cobra.ShellCompDirectiveError
|
return nil, cobra.ShellCompDirectiveError
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user