-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ddev.go
83 lines (77 loc) · 1.36 KB
/
ddev.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
package ip
import (
"log"
"os"
"os/exec"
"strconv"
"github.com/sikalabs/slu/cmd/root"
"github.com/sikalabs/slu/utils/time_utils"
"github.com/spf13/cobra"
)
var FlagVolume bool
var FlagImage string
var FlagShell string
var FlagHostNetwork bool
var Cmd = &cobra.Command{
Use: "ddev",
Short: "Run sikalabs/dev in Docker",
Args: cobra.NoArgs,
Run: func(c *cobra.Command, args []string) {
currentWorkDir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
cmdArgs := []string{
"run",
"--name", "dev-" + strconv.Itoa(time_utils.Unix()),
"--rm", "-ti",
}
if FlagVolume {
cmdArgs = append(
cmdArgs,
"-w", currentWorkDir,
"-v", currentWorkDir+":"+currentWorkDir,
)
}
cmdArgs = append(
cmdArgs,
FlagImage,
FlagShell,
)
cmd := exec.Command("docker", cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Run()
},
}
func init() {
root.RootCmd.AddCommand(Cmd)
Cmd.PersistentFlags().BoolVarP(
&FlagVolume,
"volume",
"v",
false,
"Mount current directory to container",
)
Cmd.Flags().StringVarP(
&FlagImage,
"image",
"i",
"sikalabs/dev",
"Container Image",
)
Cmd.Flags().BoolVar(
&FlagHostNetwork,
"host",
false,
"Use host network (--network=host)",
)
Cmd.Flags().StringVarP(
&FlagShell,
"shell",
"s",
"zsh",
"Shell to run in container",
)
}