func cmdInit(c *cli.Context) { wd := "." if len(c.Args()) > 0 { wd = c.Args()[0] } dir, _, err := stdcli.DirApp(c, wd) if err != nil { stdcli.Error(err) return } changed, err := manifest.Init(dir) if err != nil { stdcli.Error(err) return } if len(changed) > 0 { fmt.Printf("Generated: %s\n", strings.Join(changed, ", ")) } }
func cmdStart(c *cli.Context) { wd := "." if len(c.Args()) > 0 { wd = c.Args()[0] } dir, app, err := stdcli.DirApp(c, wd) if err != nil { stdcli.Error(err) return } file := c.String("file") m, err := manifest.Read(dir, file) if err != nil { changes, err := manifest.Init(dir) if err != nil { stdcli.Error(err) return } fmt.Printf("Generated: %s\n", strings.Join(changes, ", ")) m, err = manifest.Read(dir, file) if err != nil { stdcli.Error(err) return } } missing := m.MissingEnvironment() if len(missing) > 0 { stdcli.Error(fmt.Errorf("env expected: %s", strings.Join(missing, ", "))) return } wanted, err := m.PortsWanted() if err != nil { stdcli.Error(err) return } conflicts := make([]string, 0) host := "127.0.0.1" if h := os.Getenv("DOCKER_HOST"); h != "" { u, err := url.Parse(h) if err != nil { stdcli.Error(err) return } parts := strings.Split(u.Host, ":") host = parts[0] } for _, p := range wanted { conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", host, p), 200*time.Millisecond) if err == nil { conflicts = append(conflicts, p) defer conn.Close() } } if len(conflicts) > 0 { stdcli.Error(fmt.Errorf("ports in use: %s", strings.Join(conflicts, ", "))) return } errors := m.Build(app, dir, true) if len(errors) != 0 { fmt.Printf("errors: %+v\n", errors) return } errors = m.Run(app) if len(errors) != 0 { // TODO figure out what to do here // fmt.Printf("errors: %+v\n", errors) return } }
func cmdStart(c *cli.Context) { wd := "." if len(c.Args()) > 0 { wd = c.Args()[0] } dir, app, err := stdcli.DirApp(c, wd) if err != nil { stdcli.Error(err) return } file := c.String("file") m, err := manifest.Read(dir, file) if err != nil { changes, err := manifest.Init(dir) if err != nil { stdcli.Error(err) return } fmt.Printf("Generated: %s\n", strings.Join(changes, ", ")) m, err = manifest.Read(dir, file) if err != nil { stdcli.Error(err) return } } conflicts, err := m.PortConflicts() if err != nil { stdcli.Error(err) return } if len(conflicts) > 0 { stdcli.Error(fmt.Errorf("ports in use: %s", strings.Join(conflicts, ", "))) return } missing, err := m.MissingEnvironment() if err != nil { stdcli.Error(err) return } if len(missing) > 0 { stdcli.Error(fmt.Errorf("env expected: %s", strings.Join(missing, ", "))) return } errors := m.Build(app, dir, !c.Bool("no-cache")) if len(errors) != 0 { fmt.Printf("errors: %+v\n", errors) return } errors = m.Run(app) if len(errors) != 0 { // TODO figure out what to do here // fmt.Printf("errors: %+v\n", errors) return } }