예제 #1
0
파일: image_test.go 프로젝트: tsuru/tsuru
func (s *S) TestDeleteAllAppImageNamesSimilarApps(c *check.C) {
	data := map[string]interface{}{"healthcheck": map[string]interface{}{"path": "/test"}}
	err := image.AppendAppImageName("myapp", "tsuru/app-myapp:v1")
	c.Assert(err, check.IsNil)
	err = image.SaveImageCustomData("tsuru/app-myapp:v1", data)
	c.Assert(err, check.IsNil)
	err = image.AppendAppImageName("myapp-dev", "tsuru/app-myapp-dev:v1")
	c.Assert(err, check.IsNil)
	err = image.SaveImageCustomData("tsuru/app-myapp-dev:v1", data)
	c.Assert(err, check.IsNil)
	err = image.DeleteAllAppImageNames("myapp")
	c.Assert(err, check.IsNil)
	_, err = image.ListAppImages("myapp")
	c.Assert(err, check.ErrorMatches, "not found")
	_, err = image.ListAppImages("myapp-dev")
	c.Assert(err, check.IsNil)
	yamlData, err := image.GetImageTsuruYamlData("tsuru/app-myapp:v1")
	c.Assert(err, check.IsNil)
	c.Assert(yamlData, check.DeepEquals, provision.TsuruYamlData{})
	yamlData, err = image.GetImageTsuruYamlData("tsuru/app-myapp-dev:v1")
	c.Assert(err, check.IsNil)
	c.Assert(yamlData, check.DeepEquals, provision.TsuruYamlData{
		Healthcheck: provision.TsuruYamlHealthcheck{Path: "/test"},
	})
}
예제 #2
0
파일: image_test.go 프로젝트: tsuru/tsuru
func (s *S) TestListAppImages(c *check.C) {
	err := image.AppendAppImageName("myapp", "tsuru/app-myapp:v1")
	c.Assert(err, check.IsNil)
	err = image.AppendAppImageName("myapp", "tsuru/app-myapp:v2")
	c.Assert(err, check.IsNil)
	images, err := image.ListAppImages("myapp")
	c.Assert(err, check.IsNil)
	c.Assert(images, check.DeepEquals, []string{"tsuru/app-myapp:v1", "tsuru/app-myapp:v2"})
}
예제 #3
0
파일: image_test.go 프로젝트: tsuru/tsuru
func (s *S) TestDeleteAllAppImageNames(c *check.C) {
	err := image.AppendAppImageName("myapp", "tsuru/app-myapp:v1")
	c.Assert(err, check.IsNil)
	err = image.AppendAppImageName("myapp", "tsuru/app-myapp:v2")
	c.Assert(err, check.IsNil)
	err = image.DeleteAllAppImageNames("myapp")
	c.Assert(err, check.IsNil)
	_, err = image.ListAppImages("myapp")
	c.Assert(err, check.ErrorMatches, "not found")
}
예제 #4
0
파일: deploy.go 프로젝트: tsuru/tsuru
func findValidImages(apps ...App) (set.Set, error) {
	validImages := set.Set{}
	for _, a := range apps {
		imgs, err := image.ListAppImages(a.Name)
		if err != nil && err != mgo.ErrNotFound {
			return nil, err
		}
		validImages.Add(imgs...)
	}
	return validImages, nil
}
예제 #5
0
파일: image_test.go 프로젝트: tsuru/tsuru
func (s *S) TestDeleteAllAppImageNamesRemovesCustomData(c *check.C) {
	imgName := "tsuru/app-myapp:v1"
	err := image.AppendAppImageName("myapp", imgName)
	c.Assert(err, check.IsNil)
	data := map[string]interface{}{"healthcheck": map[string]interface{}{"path": "/test"}}
	err = image.SaveImageCustomData(imgName, data)
	c.Assert(err, check.IsNil)
	err = image.DeleteAllAppImageNames("myapp")
	c.Assert(err, check.IsNil)
	_, err = image.ListAppImages("myapp")
	c.Assert(err, check.ErrorMatches, "not found")
	yamlData, err := image.GetImageTsuruYamlData(imgName)
	c.Assert(err, check.IsNil)
	c.Assert(yamlData, check.DeepEquals, provision.TsuruYamlData{})
}
예제 #6
0
파일: provisioner.go 프로젝트: tsuru/tsuru
func (p *dockerProvisioner) Destroy(app provision.App) error {
	containers, err := p.listContainersByApp(app.GetName())
	if err != nil {
		log.Errorf("Failed to list app containers: %s", err)
		return err
	}
	args := changeUnitsPipelineArgs{
		app:         app,
		toRemove:    containers,
		writer:      ioutil.Discard,
		provisioner: p,
		appDestroy:  true,
	}
	pipeline := action.NewPipeline(
		&removeOldRoutes,
		&provisionRemoveOldUnits,
		&provisionUnbindOldUnits,
	)
	err = pipeline.Execute(args)
	if err != nil {
		return err
	}
	images, err := image.ListAppImages(app.GetName())
	if err != nil {
		log.Errorf("Failed to get image ids for app %s: %s", app.GetName(), err)
	}
	cluster := p.Cluster()
	for _, imageId := range images {
		err = cluster.RemoveImage(imageId)
		if err != nil {
			log.Errorf("Failed to remove image %s: %s", imageId, err)
		}
		err = cluster.RemoveFromRegistry(imageId)
		if err != nil {
			log.Errorf("Failed to remove image %s from registry: %s", imageId, err)
		}
	}
	err = image.DeleteAllAppImageNames(app.GetName())
	if err != nil {
		log.Errorf("Failed to remove image names from storage for app %s: %s", app.GetName(), err)
	}
	return nil
}
예제 #7
0
파일: image_test.go 프로젝트: tsuru/tsuru
func (s *S) TestPullAppImageNamesRemovesCustomData(c *check.C) {
	img1Name := "tsuru/app-myapp:v1"
	err := image.AppendAppImageName("myapp", img1Name)
	c.Assert(err, check.IsNil)
	err = image.AppendAppImageName("myapp", "tsuru/app-myapp:v2")
	c.Assert(err, check.IsNil)
	err = image.AppendAppImageName("myapp", "tsuru/app-myapp:v3")
	c.Assert(err, check.IsNil)
	data := map[string]interface{}{"healthcheck": map[string]interface{}{"path": "/test"}}
	err = image.SaveImageCustomData(img1Name, data)
	c.Assert(err, check.IsNil)
	err = image.PullAppImageNames("myapp", []string{img1Name})
	c.Assert(err, check.IsNil)
	images, err := image.ListAppImages("myapp")
	c.Assert(err, check.IsNil)
	c.Assert(images, check.DeepEquals, []string{"tsuru/app-myapp:v2", "tsuru/app-myapp:v3"})
	yamlData, err := image.GetImageTsuruYamlData(img1Name)
	c.Assert(err, check.IsNil)
	c.Assert(yamlData, check.DeepEquals, provision.TsuruYamlData{})
}
예제 #8
0
파일: actions.go 프로젝트: tsuru/tsuru
var updateAppImage = action.Action{
	Name: "update-app-image",
	Forward: func(ctx action.FWContext) (action.Result, error) {
		args := ctx.Params[0].(changeUnitsPipelineArgs)
		if err := checkCanceled(args.event); err != nil {
			return nil, err
		}
		currentImageName, _ := image.AppCurrentImageName(args.app.GetName())
		if currentImageName != args.imageId {
			err := image.AppendAppImageName(args.app.GetName(), args.imageId)
			if err != nil {
				return nil, errors.Wrap(err, "unable to save image name")
			}
		}
		imgHistorySize := image.ImageHistorySize()
		allImages, err := image.ListAppImages(args.app.GetName())
		if err != nil {
			log.Errorf("Couldn't list images for cleaning: %s", err)
			return ctx.Previous, nil
		}
		for i, imgName := range allImages {
			if i > len(allImages)-imgHistorySize-1 {
				err := args.provisioner.Cluster().RemoveImageIgnoreLast(imgName)
				if err != nil {
					log.Debugf("Ignored error removing old image %q: %s", imgName, err.Error())
				}
				continue
			}
			args.provisioner.cleanImage(args.app.GetName(), imgName)
		}
		return ctx.Previous, nil