Ejemplo n.º 1
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("usage: build <src>")
		os.Exit(1)
	}

	src := os.Args[1]

	if src == "-" {
		extractTar()
	} else {
		cloneGit(src)
	}

	writeDockerAuth()

	m, err := manifest.Read("src", manifestPath)
	handleError(err)

	data, err := m.Raw()
	handleError(err)

	handleErrors(m.Build(app, "src", cache))
	handleErrors(m.Push(app, registryAddress, buildId, repository))

	_, err = rackClient.UpdateBuild(os.Getenv("APP"), os.Getenv("BUILD"), string(data), "complete", "")
	handleError(err)
}
Ejemplo n.º 2
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
	}

	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
	}
}
Ejemplo n.º 3
0
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")
	noCache := flag.Bool("no-cache", false, "skip the docker cache")

	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.Read(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)
	}

	cache := !*noCache

	errors := m.Build(app, dir, cache)

	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])
		}
	}
}
Ejemplo n.º 4
0
Archivo: main.go Proyecto: cozmo/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")
	dockercfg := flag.String("dockercfg", "", "dockercfg auth json for pull")
	noCache := flag.Bool("no-cache", false, "skip the docker cache")
	config := flag.String("config", "docker-compose.yml", "docker compose filename")
	flatten := flag.String("flatten", "", "flatten images into a single namespace")

	flag.Parse()

	l := len(flag.Args())

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

	args := flag.Args()

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

	dir, err := clone(source, app)

	if err != nil {
		die(err)
	}

	m, err := manifest.Read(dir, *config)

	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)
	}

	if *dockercfg != "" {
		err := os.MkdirAll("/root/.docker", 0700)

		if err != nil {
			die(err)
		}

		err = ioutil.WriteFile("/root/.docker/config.json", []byte(*dockercfg), 0400)

		if err != nil {
			die(err)
		}
	}

	cache := !*noCache

	errors := m.Build(app, dir, cache)

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

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

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

		if len(errors) > 0 {
			die(errors[0])
		}
	}
}
Ejemplo n.º 5
0
Archivo: start.go Proyecto: cozmo/rack
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
	}
}