2016-06-08 13:47:46 -04:00
|
|
|
package stack
|
|
|
|
|
2016-11-08 12:05:23 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/docker/docker/cli/command/bundlefile"
|
2017-03-09 13:23:45 -05:00
|
|
|
"github.com/pkg/errors"
|
2016-11-08 12:05:23 -05:00
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
2016-06-08 13:47:46 -04:00
|
|
|
|
2016-11-02 14:57:40 -04:00
|
|
|
func addComposefileFlag(opt *string, flags *pflag.FlagSet) {
|
2016-11-24 16:11:38 -05:00
|
|
|
flags.StringVarP(opt, "compose-file", "c", "", "Path to a Compose file")
|
2017-01-16 11:57:26 -05:00
|
|
|
flags.SetAnnotation("compose-file", "version", []string{"1.25"})
|
2016-11-02 14:57:40 -04:00
|
|
|
}
|
|
|
|
|
2016-11-08 12:05:23 -05:00
|
|
|
func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
|
|
|
|
flags.StringVar(opt, "bundle-file", "", "Path to a Distributed Application Bundle file")
|
2016-11-21 15:30:25 -05:00
|
|
|
flags.SetAnnotation("bundle-file", "experimental", nil)
|
2016-11-08 12:05:23 -05:00
|
|
|
}
|
|
|
|
|
2016-07-15 16:17:03 -04:00
|
|
|
func addRegistryAuthFlag(opt *bool, flags *pflag.FlagSet) {
|
2016-07-22 04:38:56 -04:00
|
|
|
flags.BoolVar(opt, "with-registry-auth", false, "Send registry authentication details to Swarm agents")
|
2016-07-15 16:17:03 -04:00
|
|
|
}
|
2016-11-08 12:05:23 -05:00
|
|
|
|
|
|
|
func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
|
|
|
|
defaultPath := fmt.Sprintf("%s.dab", namespace)
|
|
|
|
|
|
|
|
if path == "" {
|
|
|
|
path = defaultPath
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
2017-03-09 13:23:45 -05:00
|
|
|
return nil, errors.Errorf(
|
2016-11-08 12:05:23 -05:00
|
|
|
"Bundle %s not found. Specify the path with --file",
|
|
|
|
path)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
|
|
|
|
reader, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer reader.Close()
|
|
|
|
|
|
|
|
bundle, err := bundlefile.LoadFile(reader)
|
|
|
|
if err != nil {
|
2017-03-09 13:23:45 -05:00
|
|
|
return nil, errors.Errorf("Error reading %s: %v\n", path, err)
|
2016-11-08 12:05:23 -05:00
|
|
|
}
|
|
|
|
return bundle, err
|
|
|
|
}
|