forked from cfregly/Nut
/
multi.go
53 lines (44 loc) · 1.14 KB
/
multi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package commands
import (
"flag"
"fmt"
"github.com/PagerDuty/nut/container"
"github.com/mitchellh/cli"
log "github.com/sirupsen/logrus"
"strings"
)
type MultiCommand struct {
}
func Multi() (cli.Command, error) {
command := &MultiCommand{}
return command, nil
}
func (command *MultiCommand) Help() string {
helpText := `
Usage: nut multi [options]
Create a set of LXC container from docker-compose like yaml specifiction
Options:
-specfile=docker-compose.yml Path of the specification file
`
return strings.TrimSpace(helpText)
}
func (command *MultiCommand) Synopsis() string {
synopsis := "Build multi container environment from docker compose specification"
return synopsis
}
func (command *MultiCommand) Run(args []string) int {
flagSet := flag.NewFlagSet("multi", flag.ExitOnError)
flagSet.Usage = func() { fmt.Println(command.Help()) }
file := flagSet.String("specfile", "docker-compose.yml", "Multi-container specification file")
flagSet.Parse(args)
g, err := container.GroupFromYAML(*file)
if err != nil {
log.Errorln(err)
return -1
}
if err := g.Create(); err != nil {
log.Errorln(err)
return -1
}
return 0
}