forked from docker-archive/deploykit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (56 loc) · 1.65 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"os"
"text/template"
log "github.com/Sirupsen/logrus"
"github.com/docker/infrakit/pkg/cli"
instance_plugin "github.com/docker/infrakit/pkg/rpc/instance"
"github.com/spf13/cobra"
)
func main() {
cmd := &cobra.Command{
Use: os.Args[0],
Short: "Vagrant instance plugin",
}
name := cmd.Flags().String("name", "instance-vagrant", "Plugin name to advertise for discovery")
logLevel := cmd.Flags().Int("log", cli.DefaultLogLevel, "Logging level. 0 is least verbose. Max is 5")
defaultDir, err := os.Getwd()
if err != nil {
log.Error(err)
os.Exit(1)
}
dir := cmd.Flags().String("dir", defaultDir, "Vagrant directory")
templFile := cmd.Flags().String("template", "", "Vagrant Template file")
cmd.RunE = func(c *cobra.Command, args []string) error {
var templ *template.Template
if *templFile == "" {
templ = template.Must(template.New("").Parse(VagrantFile))
} else {
var err error
templ, err = template.ParseFiles()
if err != nil {
return err
}
}
cli.SetLogLevel(*logLevel)
cli.RunPlugin(*name, instance_plugin.PluginServer(NewVagrantPlugin(*dir, templ)))
return nil
}
cmd.AddCommand(cli.VersionCommand())
if err := cmd.Execute(); err != nil {
log.Error(err)
os.Exit(1)
}
}
// VagrantFile is the minimum definition of the vagrant file
const VagrantFile = `
Vagrant.configure("2") do |config|
config.vm.box = "{{.Properties.Box}}"
config.vm.hostname = "infrakit.box"
config.vm.network "private_network"{{.NetworkOptions}}
config.vm.provision :shell, path: "boot.sh"
config.vm.provider :virtualbox do |vb|
vb.memory = {{.Properties.Memory}}
vb.cpus = {{.Properties.CPUs}}
end
end`