opts.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package stack
  2. import (
  3. "fmt"
  4. "io"
  5. "os"
  6. "github.com/docker/docker/cli/command/bundlefile"
  7. "github.com/pkg/errors"
  8. "github.com/spf13/pflag"
  9. )
  10. func addComposefileFlag(opt *string, flags *pflag.FlagSet) {
  11. flags.StringVarP(opt, "compose-file", "c", "", "Path to a Compose file")
  12. flags.SetAnnotation("compose-file", "version", []string{"1.25"})
  13. }
  14. func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
  15. flags.StringVar(opt, "bundle-file", "", "Path to a Distributed Application Bundle file")
  16. flags.SetAnnotation("bundle-file", "experimental", nil)
  17. }
  18. func addRegistryAuthFlag(opt *bool, flags *pflag.FlagSet) {
  19. flags.BoolVar(opt, "with-registry-auth", false, "Send registry authentication details to Swarm agents")
  20. }
  21. func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
  22. defaultPath := fmt.Sprintf("%s.dab", namespace)
  23. if path == "" {
  24. path = defaultPath
  25. }
  26. if _, err := os.Stat(path); err != nil {
  27. return nil, errors.Errorf(
  28. "Bundle %s not found. Specify the path with --file",
  29. path)
  30. }
  31. fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
  32. reader, err := os.Open(path)
  33. if err != nil {
  34. return nil, err
  35. }
  36. defer reader.Close()
  37. bundle, err := bundlefile.LoadFile(reader)
  38. if err != nil {
  39. return nil, errors.Errorf("Error reading %s: %v\n", path, err)
  40. }
  41. return bundle, err
  42. }