зеркало из https://github.com/docker/compose-cli.git
Коммит
8b76602054
|
@ -48,7 +48,7 @@ func exportCommand() *cobra.Command {
|
||||||
Use: "export",
|
Use: "export",
|
||||||
Short: "Export a context to a tar or kubeconfig file",
|
Short: "Export a context to a tar or kubeconfig file",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().Bool("kubeconfig", false, "Export as a kubeconfig file")
|
cmd.Flags().Bool("kubeconfig", false, "Export as a kubeconfig file")
|
||||||
|
@ -60,7 +60,7 @@ func importCommand() *cobra.Command {
|
||||||
Use: "import",
|
Use: "import",
|
||||||
Short: "Import a context from a tar or zip file",
|
Short: "Import a context from a tar or zip file",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return cmd
|
return cmd
|
||||||
|
|
|
@ -69,7 +69,7 @@ $ docker context create my-context --description "some description" --docker "ho
|
||||||
Use: "create CONTEXT",
|
Use: "create CONTEXT",
|
||||||
Short: "Create new context",
|
Short: "Create new context",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Long: longHelp,
|
Long: longHelp,
|
||||||
|
|
|
@ -27,7 +27,7 @@ func inspectCommand() *cobra.Command {
|
||||||
Use: "inspect",
|
Use: "inspect",
|
||||||
Short: "Display detailed information on one or more contexts",
|
Short: "Display detailed information on one or more contexts",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func listCommand() *cobra.Command {
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runList(cmd, opts)
|
return runList(opts)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only show context names")
|
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only show context names")
|
||||||
|
@ -62,14 +62,14 @@ func listCommand() *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runList(cmd *cobra.Command, opts lsOpts) error {
|
func runList(opts lsOpts) error {
|
||||||
err := opts.validate()
|
err := opts.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
format := strings.ToLower(strings.ReplaceAll(opts.format, " ", ""))
|
format := strings.ToLower(strings.ReplaceAll(opts.format, " ", ""))
|
||||||
if format != "" && format != formatter.JSON && format != formatter.PRETTY && format != formatter.TemplateLegacyJSON {
|
if format != "" && format != formatter.JSON && format != formatter.PRETTY && format != formatter.TemplateLegacyJSON {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ $ docker context update my-context --description "some description" --docker "ho
|
||||||
Short: "Update a context",
|
Short: "Update a context",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runUpdate(cmd, args[0])
|
return runUpdate(args[0])
|
||||||
},
|
},
|
||||||
Long: longHelp,
|
Long: longHelp,
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ $ docker context update my-context --description "some description" --docker "ho
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runUpdate(cmd *cobra.Command, name string) error {
|
func runUpdate(name string) error {
|
||||||
s := store.Instance()
|
s := store.Instance()
|
||||||
dockerContext, err := s.Get(name)
|
dockerContext, err := s.Get(name)
|
||||||
if err == nil && dockerContext != nil {
|
if err == nil && dockerContext != nil {
|
||||||
|
@ -80,6 +80,6 @@ func runUpdate(cmd *cobra.Command, name string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ func Command() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runLogin(cmd *cobra.Command, args []string) error {
|
func runLogin(cmd *cobra.Command, args []string) error {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,6 @@ func Command() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runLogout(cmd *cobra.Command, args []string) error {
|
func runLogout(cmd *cobra.Command, args []string) error {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ func getOutFromMoby(cmd *cobra.Command, args ...string) (string, error) {
|
||||||
// we don't want to fail on error, there is an error if the engine is not available but it displays client version info
|
// we don't want to fail on error, there is an error if the engine is not available but it displays client version info
|
||||||
// Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
|
// Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
|
||||||
if versionResult == nil {
|
if versionResult == nil {
|
||||||
mobycli.Exec(cmd.Root())
|
mobycli.Exec()
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
return string(versionResult), err
|
return string(versionResult), err
|
||||||
|
|
|
@ -191,7 +191,7 @@ func main() {
|
||||||
|
|
||||||
// --version should immediately be forwarded to the original cli
|
// --version should immediately be forwarded to the original cli
|
||||||
if opts.Version {
|
if opts.Version {
|
||||||
mobycli.Exec(root)
|
mobycli.Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Config == "" {
|
if opts.Config == "" {
|
||||||
|
@ -205,7 +205,7 @@ func main() {
|
||||||
|
|
||||||
s, err := store.New(configDir)
|
s, err := store.New(configDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mobycli.Exec(root)
|
mobycli.Exec()
|
||||||
}
|
}
|
||||||
store.WithContextStore(s)
|
store.WithContextStore(s)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ func ExecIfDefaultCtxType(ctx context.Context, root *cobra.Command) {
|
||||||
currentCtx, err := s.Get(currentContext)
|
currentCtx, err := s.Get(currentContext)
|
||||||
// Only run original docker command if the current context is not ours.
|
// Only run original docker command if the current context is not ours.
|
||||||
if err != nil || mustDelegateToMoby(currentCtx.Type()) {
|
if err != nil || mustDelegateToMoby(currentCtx.Type()) {
|
||||||
Exec(root)
|
Exec()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,10 +62,8 @@ func mustDelegateToMoby(ctxType string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exec delegates to com.docker.cli if on moby context
|
// Exec delegates to com.docker.cli if on moby context
|
||||||
func Exec(root *cobra.Command) {
|
func Exec() {
|
||||||
childExit := make(chan bool)
|
err := RunDocker(os.Args[1:]...)
|
||||||
err := RunDocker(childExit, os.Args[1:]...)
|
|
||||||
childExit <- true
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if exiterr, ok := err.(*exec.ExitError); ok {
|
if exiterr, ok := err.(*exec.ExitError); ok {
|
||||||
exitCode := exiterr.ExitCode()
|
exitCode := exiterr.ExitCode()
|
||||||
|
@ -91,7 +88,7 @@ func Exec(root *cobra.Command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunDocker runs a docker command, and forward signals to the shellout command (stops listening to signals when an event is sent to childExit)
|
// RunDocker runs a docker command, and forward signals to the shellout command (stops listening to signals when an event is sent to childExit)
|
||||||
func RunDocker(childExit chan bool, args ...string) error {
|
func RunDocker(args ...string) error {
|
||||||
execBinary, err := resolvepath.LookPath(ComDockerCli)
|
execBinary, err := resolvepath.LookPath(ComDockerCli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
execBinary = findBinary(ComDockerCli)
|
execBinary = findBinary(ComDockerCli)
|
||||||
|
@ -105,29 +102,6 @@ func RunDocker(childExit chan bool, args ...string) error {
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
signals := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(signals) // catch all signals
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case sig := <-signals:
|
|
||||||
if cmd.Process == nil {
|
|
||||||
continue // can happen if receiving signal before the process is actually started
|
|
||||||
}
|
|
||||||
// In go1.14+, the go runtime issues SIGURG as an interrupt to
|
|
||||||
// support preemptable system calls on Linux. Since we can't
|
|
||||||
// forward that along we'll check that here.
|
|
||||||
if isRuntimeSig(sig) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_ = cmd.Process.Signal(sig)
|
|
||||||
case <-childExit:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2020 Docker Compose CLI authors
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package mobycli
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func isRuntimeSig(s os.Signal) bool {
|
|
||||||
return s == unix.SIGURG
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2020 Docker Compose CLI authors
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package mobycli
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
func isRuntimeSig(s os.Signal) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче