Esempio n. 1
0
func (p *dockerProvisioner) ImageDeploy(app provision.App, imageId string, evt *event.Event) (string, error) {
	cluster := p.Cluster()
	if !strings.Contains(imageId, ":") {
		imageId = fmt.Sprintf("%s:latest", imageId)
	}
	w := evt
	fmt.Fprintln(w, "---- Pulling image to tsuru ----")
	pullOpts := docker.PullImageOptions{
		Repository:        imageId,
		OutputStream:      w,
		InactivityTimeout: net.StreamInactivityTimeout,
	}
	nodes, err := cluster.NodesForMetadata(map[string]string{"pool": app.GetPool()})
	if err != nil {
		return "", err
	}
	node, _, err := p.scheduler.minMaxNodes(nodes, app.GetName(), "")
	if err != nil {
		return "", err
	}
	err = cluster.PullImage(pullOpts, docker.AuthConfiguration{}, node)
	if err != nil {
		return "", err
	}
	fmt.Fprintln(w, "---- Getting process from image ----")
	cmd := "cat /home/application/current/Procfile || cat /app/user/Procfile || cat /Procfile"
	var outBuf bytes.Buffer
	err = p.runCommandInContainer(imageId, cmd, app, &outBuf, nil)
	if err != nil {
		return "", err
	}
	newImage, err := dockercommon.PrepareImageForDeploy(dockercommon.PrepareImageArgs{
		Client:      cluster,
		App:         app,
		ProcfileRaw: outBuf.String(),
		ImageId:     imageId,
		AuthConfig:  p.RegistryAuthConfig(),
		Out:         w,
	})
	if err != nil {
		return "", err
	}
	app.SetUpdatePlatform(true)
	return newImage, p.deploy(app, newImage, evt)
}
Esempio n. 2
0
func (p *swarmProvisioner) ImageDeploy(a provision.App, imgID string, evt *event.Event) (string, error) {
	client, err := chooseDBSwarmNode()
	if err != nil {
		return "", err
	}
	if !strings.Contains(imgID, ":") {
		imgID = fmt.Sprintf("%s:latest", imgID)
	}
	fmt.Fprintln(evt, "---- Pulling image to tsuru ----")
	var buf bytes.Buffer
	cmds := []string{"/bin/bash", "-c", "cat /home/application/current/Procfile || cat /app/user/Procfile || cat /Procfile"}
	srvID, task, err := runOnceBuildCmds(client, a, cmds, imgID, "", &buf)
	if srvID != "" {
		defer removeServiceAndLog(client, srvID)
	}
	if err != nil {
		return "", err
	}
	client, err = clientForNode(client, task.NodeID)
	if err != nil {
		return "", err
	}
	newImage, err := dockercommon.PrepareImageForDeploy(dockercommon.PrepareImageArgs{
		Client:      client,
		App:         a,
		ProcfileRaw: buf.String(),
		ImageId:     imgID,
		Out:         evt,
	})
	if err != nil {
		return "", err
	}
	a.SetUpdatePlatform(true)
	err = deployProcesses(client, a, newImage, nil)
	if err != nil {
		return "", err
	}
	return newImage, nil
}