예제 #1
0
파일: image_test.go 프로젝트: tsuru/tsuru
func (s *S) TestGetImageCustomDataLegacyProcesses(c *check.C) {
	data := image.ImageMetadata{
		Name: "tsuru/app-myapp:v1",
		LegacyProcesses: map[string]string{
			"worker1": "python myapp.py",
			"worker2": "worker2",
		},
	}
	err := data.Save()
	c.Assert(err, check.IsNil)
	dbMetadata, err := image.GetImageCustomData(data.Name)
	c.Assert(err, check.IsNil)
	c.Assert(dbMetadata.Processes, check.DeepEquals, map[string][]string{
		"worker1": {"python myapp.py"},
		"worker2": {"worker2"},
	})
	data.Name = "tsuru/app-myapp:v2"
	data.Processes = map[string][]string{
		"w1": {"has", "priority"},
	}
	err = data.Save()
	c.Assert(err, check.IsNil)
	dbMetadata, err = image.GetImageCustomData(data.Name)
	c.Assert(err, check.IsNil)
	c.Assert(dbMetadata.Processes, check.DeepEquals, map[string][]string{
		"w1": {"has", "priority"},
	})
}
예제 #2
0
파일: docker.go 프로젝트: tsuru/tsuru
func PrepareImageForDeploy(args PrepareImageArgs) (string, error) {
	fmt.Fprintf(args.Out, "---- Inspecting image %q ----\n", args.ImageId)
	procfile := image.GetProcessesFromProcfile(args.ProcfileRaw)
	imageInspect, err := args.Client.InspectImage(args.ImageId)
	if err != nil {
		return "", err
	}
	if len(procfile) == 0 {
		fmt.Fprintln(args.Out, "  ---> Procfile not found, using entrypoint and cmd")
		procfile["web"] = append(imageInspect.Config.Entrypoint, imageInspect.Config.Cmd...)
	}
	for k, v := range procfile {
		fmt.Fprintf(args.Out, "  ---> Process %q found with commands: %q\n", k, v)
	}
	newImage, err := image.AppNewImageName(args.App.GetName())
	if err != nil {
		return "", err
	}
	imageInfo := strings.Split(newImage, ":")
	repo, tag := strings.Join(imageInfo[:len(imageInfo)-1], ":"), imageInfo[len(imageInfo)-1]
	err = args.Client.TagImage(args.ImageId, docker.TagImageOptions{Repo: repo, Tag: tag, Force: true})
	if err != nil {
		return "", err
	}
	registry, err := config.GetString("docker:registry")
	if err != nil {
		return "", err
	}
	fmt.Fprintf(args.Out, "---- Pushing image %q to tsuru ----\n", newImage)
	pushOpts := docker.PushImageOptions{
		Name:              repo,
		Tag:               tag,
		Registry:          registry,
		OutputStream:      args.Out,
		InactivityTimeout: net.StreamInactivityTimeout,
		RawJSONStream:     true,
	}
	err = args.Client.PushImage(pushOpts, args.AuthConfig)
	if err != nil {
		return "", err
	}
	imageData := image.ImageMetadata{
		Name:      newImage,
		Processes: procfile,
	}
	if len(imageInspect.Config.ExposedPorts) > 1 {
		return "", errors.New("Too many ports. You should especify which one you want to.")
	}
	for k := range imageInspect.Config.ExposedPorts {
		imageData.ExposedPort = string(k)
	}
	err = imageData.Save()
	if err != nil {
		return "", err
	}
	return newImage, nil
}