-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.go
90 lines (76 loc) · 1.71 KB
/
run.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"fmt"
"os"
"github.com/Sirupsen/logrus"
)
type RunCommand struct {
CreateCommand
Remove bool `long:"rm" description:"Remove environment after disconnecting."`
}
func (ccommand *RunCommand) toCreateOpts(sc SystemClient, workingDir string) CreateOpts {
var projectDir string
if len(ccommand.Directory) > 0 {
projectDir = ccommand.Directory
} else {
projectDir = workingDir
}
return CreateOpts{
Name: ccommand.Args.Name,
ProjectDir: projectDir,
Ports: ccommand.Ports,
Volumes: ccommand.Volumes,
ForceBuild: ccommand.ForceBuild || ccommand.ForcePull,
Build: BuildOpts{
Image: ImageOpts{
Type: ccommand.Type,
Version: ccommand.Version,
Image: ccommand.Image,
},
TimeZone: ccommand.TimeZone,
ForcePull: ccommand.ForcePull,
Username: sc.Username(),
UID: sc.UID(),
GID: sc.GID(),
},
}
}
var runCommand RunCommand
func (x *RunCommand) Execute(args []string) error {
dc, err := NewDockerClient(globalOptions.toConnectOpts())
if err != nil {
return err
}
sc, err := NewSystemClient()
if err != nil {
return err
}
workingDir, err := os.Getwd()
if err != nil {
return err
}
err = CreateNewEnvironment(dc, sc, runCommand.toCreateOpts(sc, workingDir), os.Stdout)
if err != nil {
return err
}
err = ConnectEnvironment(dc, sc, runCommand.Args.Name, connectCommand.Args.Rest)
if err != nil {
logrus.Debugf("error when running shell: %s", err)
}
if runCommand.Remove {
err = DestroyEnvironment(dc, sc, runCommand.Args.Name)
if err != nil {
return err
}
}
return nil
}
func init() {
_, err := parser.AddCommand("run",
"Run an environment.",
"",
&runCommand)
if err != nil {
fmt.Println(err)
}
}