2016-06-08 13:47:46 -04:00
|
|
|
// +build experimental
|
|
|
|
|
|
|
|
package stack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/client/bundlefile"
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
|
2016-07-19 12:32:44 -04:00
|
|
|
flags.StringVar(
|
2016-06-08 13:47:46 -04:00
|
|
|
opt,
|
2016-07-20 09:52:43 -04:00
|
|
|
"file", "",
|
2016-06-22 17:59:10 -04:00
|
|
|
"Path to a Distributed Application Bundle file (Default: STACK.dab)")
|
2016-06-08 13:47:46 -04: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-06-08 13:47:46 -04:00
|
|
|
func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
|
2016-06-22 17:59:10 -04:00
|
|
|
defaultPath := fmt.Sprintf("%s.dab", namespace)
|
2016-06-08 13:47:46 -04:00
|
|
|
|
|
|
|
if path == "" {
|
|
|
|
path = defaultPath
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
return nil, fmt.Errorf(
|
2016-07-20 09:52:43 -04:00
|
|
|
"Bundle %s not found. Specify the path with --file",
|
2016-06-08 13:47:46 -04:00
|
|
|
path)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
|
2016-06-16 17:55:50 -04:00
|
|
|
reader, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-07-05 19:00:39 -04:00
|
|
|
defer reader.Close()
|
2016-06-16 17:55:50 -04:00
|
|
|
|
|
|
|
bundle, err := bundlefile.LoadFile(reader)
|
2016-06-08 13:47:46 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
|
|
|
|
}
|
|
|
|
return bundle, err
|
|
|
|
}
|