Exemplo n.º 1
0
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
	}

	m, err := manifest.Generate(dir)

	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)

	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
	}
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: brandur/rack
func main() {
	id := flag.String("id", "", "tag the build with this id")
	push := flag.String("push", "", "push build to this prefix when done")
	auth := flag.String("auth", "", "auth token for push")

	flag.Parse()

	l := len(flag.Args())

	if l < 2 {
		flag.Usage()
		os.Exit(0)
	}

	args := flag.Args()

	app := positional(args, 0)
	source := positional(args, 1)

	dir, err := clone(source, app)

	if err != nil {
		die(err)
	}

	m, err := manifest.Generate(dir)

	if err != nil {
		die(err)
	}

	data, err := m.Raw()

	if err != nil {
		die(err)
	}

	scanner := bufio.NewScanner(bytes.NewReader(data))

	for scanner.Scan() {
		fmt.Printf("manifest|%s\n", scanner.Text())
	}

	if err := scanner.Err(); err != nil {
		die(err)
	}

	manifest.Stdout = prefixWriter("build")
	manifest.Stderr = manifest.Stdout

	if err != nil {
		die(err)
	}

	errors := m.Build(app, dir)

	if len(errors) > 0 {
		die(errors[0])
	}

	if *push != "" {
		manifest.Stdout = prefixWriter("push")
		manifest.Stderr = manifest.Stdout

		errors := m.Push(app, *push, *auth, *id)

		if len(errors) > 0 {
			die(errors[0])
		}
	}
}