当前位置: 首页>>代码示例>>Golang>>正文


Golang image.SaveImageCustomData函数代码示例

本文整理汇总了Golang中github.com/tsuru/tsuru/app/image.SaveImageCustomData函数的典型用法代码示例。如果您正苦于以下问题:Golang SaveImageCustomData函数的具体用法?Golang SaveImageCustomData怎么用?Golang SaveImageCustomData使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SaveImageCustomData函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestDeleteAllAppImageNamesSimilarApps

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"},
	})
}
开发者ID:tsuru,项目名称:tsuru,代码行数:25,代码来源:image_test.go

示例2: TestGetImageWebProcessName

func (s *S) TestGetImageWebProcessName(c *check.C) {
	img1 := "tsuru/app-myapp:v1"
	customData1 := map[string]interface{}{
		"processes": map[string]interface{}{
			"web":    "python myapp.py",
			"worker": "someworker",
		},
	}
	err := image.SaveImageCustomData(img1, customData1)
	c.Assert(err, check.IsNil)
	img2 := "tsuru/app-myapp:v2"
	customData2 := map[string]interface{}{
		"processes": map[string]interface{}{
			"worker1": "python myapp.py",
			"worker2": "someworker",
		},
	}
	err = image.SaveImageCustomData(img2, customData2)
	c.Assert(err, check.IsNil)
	img3 := "tsuru/app-myapp:v3"
	customData3 := map[string]interface{}{
		"processes": map[string]interface{}{
			"api": "python myapi.py",
		},
	}
	err = image.SaveImageCustomData(img3, customData3)
	c.Assert(err, check.IsNil)
	img4 := "tsuru/app-myapp:v4"
	customData4 := map[string]interface{}{}
	err = image.SaveImageCustomData(img4, customData4)
	c.Assert(err, check.IsNil)
	web1, err := image.GetImageWebProcessName(img1)
	c.Check(err, check.IsNil)
	c.Check(web1, check.Equals, "web")
	web2, err := image.GetImageWebProcessName(img2)
	c.Check(err, check.IsNil)
	c.Check(web2, check.Equals, "web")
	web3, err := image.GetImageWebProcessName(img3)
	c.Check(err, check.IsNil)
	c.Check(web3, check.Equals, "api")
	web4, err := image.GetImageWebProcessName(img4)
	c.Check(err, check.IsNil)
	c.Check(web4, check.Equals, "")
	img5 := "tsuru/app-myapp:v5"
	web5, err := image.GetImageWebProcessName(img5)
	c.Check(err, check.IsNil)
	c.Check(web5, check.Equals, "")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:48,代码来源:image_test.go

示例3: TestSwarmNodeUnits

func (s *S) TestSwarmNodeUnits(c *check.C) {
	srv, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	defer srv.Stop()
	opts := provision.AddNodeOptions{Address: srv.URL()}
	err = s.p.AddNode(opts)
	c.Assert(err, check.IsNil)
	nodes, err := s.p.ListNodes(nil)
	c.Assert(err, check.IsNil)
	c.Assert(nodes, check.HasLen, 1)
	units, err := nodes[0].Units()
	c.Assert(err, check.IsNil)
	c.Assert(units, check.HasLen, 0)
	a := &app.App{Name: "myapp", TeamOwner: s.team.Name, Deploys: 1}
	err = app.CreateApp(a, s.user)
	c.Assert(err, check.IsNil)
	imgName := "myapp:v1"
	err = image.SaveImageCustomData(imgName, map[string]interface{}{
		"processes": map[string]interface{}{
			"web": "python myapp.py",
		},
	})
	c.Assert(err, check.IsNil)
	err = image.AppendAppImageName(a.GetName(), imgName)
	c.Assert(err, check.IsNil)
	err = s.p.AddUnits(a, 1, "web", nil)
	c.Assert(err, check.IsNil)
	units, err = nodes[0].Units()
	c.Assert(err, check.IsNil)
	c.Assert(units, check.HasLen, 1)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:31,代码来源:node_test.go

示例4: TestHealthcheckErrorsAfterMaxTime

func (s *S) TestHealthcheckErrorsAfterMaxTime(c *check.C) {
	a := app.App{Name: "myapp1"}
	imageName := "tsuru/app"
	customData := map[string]interface{}{
		"healthcheck": map[string]interface{}{
			"path": "/x/y",
		},
	}
	err := image.SaveImageCustomData(imageName, customData)
	c.Assert(err, check.IsNil)
	err = s.storage.Apps().Insert(a)
	c.Assert(err, check.IsNil)
	defer s.storage.Apps().RemoveAll(bson.M{"name": a.Name})
	url, _ := url.Parse("http://some-invalid-server-name.some-invalid-server-name.com:9123")
	host, port, _ := net.SplitHostPort(url.Host)
	cont := container.Container{AppName: a.Name, HostAddr: host, HostPort: port, Image: imageName}
	buf := bytes.Buffer{}
	config.Set("docker:healthcheck:max-time", -1)
	defer config.Unset("docker:healthcheck:max-time")
	done := make(chan struct{})
	go func() {
		err = runHealthcheck(&cont, &buf)
		close(done)
	}()
	select {
	case <-time.After(5 * time.Second):
		c.Fatal("Timed out waiting for healthcheck to fail")
	case <-done:
	}
	c.Assert(err, check.ErrorMatches, "healthcheck fail.*lookup some-invalid-server-name.some-invalid-server-name.com.*no such host")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:31,代码来源:healthcheck_test.go

示例5: TestSetRouterHealthcheckBackward

func (s *S) TestSetRouterHealthcheckBackward(c *check.C) {
	app := provisiontest.NewFakeApp("myapp", "python", 1)
	imageName := "tsuru/img1"
	customData := map[string]interface{}{
		"healthcheck": map[string]interface{}{
			"path":          "/x/y",
			"status":        http.StatusCreated,
			"match":         "ignored",
			"use_in_router": true,
		},
	}
	err := image.SaveImageCustomData(imageName, customData)
	c.Assert(err, check.IsNil)
	routertest.FakeRouter.AddBackend(app.GetName())
	defer routertest.FakeRouter.RemoveBackend(app.GetName())
	args := changeUnitsPipelineArgs{
		app:         app,
		provisioner: s.p,
		imageId:     imageName,
	}
	cont1 := container.Container{ID: "ble-1", AppName: app.GetName(), ProcessName: "web", HostAddr: "127.0.0.1", HostPort: "1234"}
	context := action.FWContext{Previous: []container.Container{cont1}, Params: []interface{}{args}}
	_, err = setRouterHealthcheck.Forward(context)
	c.Assert(err, check.IsNil)
	hcData := routertest.FakeRouter.GetHealthcheck(app.GetName())
	c.Assert(hcData, check.DeepEquals, router.HealthcheckData{
		Path:   "/x/y",
		Status: http.StatusCreated,
	})
	bwcontext := action.BWContext{Params: []interface{}{args}}
	setRouterHealthcheck.Backward(bwcontext)
	hcData = routertest.FakeRouter.GetHealthcheck(app.GetName())
	c.Assert(hcData, check.DeepEquals, router.HealthcheckData{Path: "/"})
}
开发者ID:tsuru,项目名称:tsuru,代码行数:34,代码来源:actions_test.go

示例6: TestAddNewRouteForwardNoWeb

func (s *S) TestAddNewRouteForwardNoWeb(c *check.C) {
	app := provisiontest.NewFakeApp("myapp", "python", 1)
	routertest.FakeRouter.AddBackend(app.GetName())
	defer routertest.FakeRouter.RemoveBackend(app.GetName())
	imageName := "tsuru/app-" + app.GetName()
	customData := map[string]interface{}{
		"processes": map[string]interface{}{
			"api": "python myapi.py",
		},
	}
	err := image.SaveImageCustomData(imageName, customData)
	c.Assert(err, check.IsNil)
	cont1 := container.Container{ID: "ble-1", AppName: app.GetName(), ProcessName: "api", HostAddr: "127.0.0.1", HostPort: "1234"}
	cont2 := container.Container{ID: "ble-2", AppName: app.GetName(), ProcessName: "api", HostAddr: "127.0.0.2", HostPort: "4321"}
	defer cont1.Remove(s.p)
	defer cont2.Remove(s.p)
	args := changeUnitsPipelineArgs{
		app:         app,
		provisioner: s.p,
		imageId:     imageName,
	}
	context := action.FWContext{Previous: []container.Container{cont1, cont2}, Params: []interface{}{args}}
	r, err := addNewRoutes.Forward(context)
	c.Assert(err, check.IsNil)
	containers := r.([]container.Container)
	hasRoute := routertest.FakeRouter.HasRoute(app.GetName(), cont1.Address().String())
	c.Assert(hasRoute, check.Equals, true)
	hasRoute = routertest.FakeRouter.HasRoute(app.GetName(), cont2.Address().String())
	c.Assert(hasRoute, check.Equals, true)
	c.Assert(containers, check.HasLen, 2)
	c.Assert(containers[0].Routable, check.Equals, true)
	c.Assert(containers[0].ID, check.Equals, "ble-1")
	c.Assert(containers[1].Routable, check.Equals, true)
	c.Assert(containers[1].ID, check.Equals, "ble-2")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:35,代码来源:actions_test.go

示例7: TestHealthcheckDefaultCheck

func (s *S) TestHealthcheckDefaultCheck(c *check.C) {
	var requests []*http.Request
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		requests = append(requests, r)
		w.WriteHeader(http.StatusOK)
	}))
	defer server.Close()
	a := app.App{Name: "myapp1"}
	imageName := "tsuru/app"
	customData := map[string]interface{}{
		"healthcheck": map[string]interface{}{
			"path": "/x/y",
		},
	}
	err := image.SaveImageCustomData(imageName, customData)
	c.Assert(err, check.IsNil)
	err = s.storage.Apps().Insert(a)
	c.Assert(err, check.IsNil)
	defer s.storage.Apps().RemoveAll(bson.M{"name": a.Name})
	url, _ := url.Parse(server.URL)
	host, port, _ := net.SplitHostPort(url.Host)
	cont := container.Container{AppName: a.Name, HostAddr: host, HostPort: port, Image: imageName}
	buf := bytes.Buffer{}
	err = runHealthcheck(&cont, &buf)
	c.Assert(err, check.IsNil)
	c.Assert(requests, check.HasLen, 1)
	c.Assert(requests[0].Method, check.Equals, "GET")
	c.Assert(requests[0].URL.Path, check.Equals, "/x/y")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:29,代码来源:healthcheck_test.go

示例8: TestActionUpdateServicesForwardUpdateExisting

func (s *S) TestActionUpdateServicesForwardUpdateExisting(c *check.C) {
	srv, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	metadata := map[string]string{"m1": "v1", labelNodePoolName.String(): "p1"}
	opts := provision.AddNodeOptions{
		Address:  srv.URL(),
		Metadata: metadata,
	}
	err = s.p.AddNode(opts)
	c.Assert(err, check.IsNil)
	cli, err := chooseDBSwarmNode()
	c.Assert(err, check.IsNil)
	_, err = cli.CreateService(docker.CreateServiceOptions{
		ServiceSpec: swarm.ServiceSpec{
			TaskTemplate: swarm.TaskSpec{
				ContainerSpec: swarm.ContainerSpec{
					Command: []string{"oldcmd"},
				},
			},
			Annotations: swarm.Annotations{
				Name: "myapp-web",
			},
		},
	})
	c.Assert(err, check.IsNil)
	a := &app.App{Name: "myapp", Platform: "whitespace", TeamOwner: s.team.Name}
	err = app.CreateApp(a, s.user)
	c.Assert(err, check.IsNil)
	imgName := "app:v1"
	err = image.SaveImageCustomData(imgName, map[string]interface{}{
		"processes": map[string]interface{}{
			"web": "python myapp.py",
		},
	})
	c.Assert(err, check.IsNil)
	args := &pipelineArgs{
		client:           cli,
		app:              a,
		newImage:         imgName,
		newImageSpec:     processSpec{"web": processState{}},
		currentImageSpec: processSpec{},
	}
	processes, err := updateServices.Forward(action.FWContext{Params: []interface{}{args}})
	c.Assert(err, check.IsNil)
	c.Assert(processes, check.DeepEquals, []string{"web"})
	service, err := cli.InspectService("myapp-web")
	c.Assert(err, check.IsNil)
	c.Assert(service.Spec.TaskTemplate.ContainerSpec.Command, check.DeepEquals, []string{
		"/bin/sh",
		"-lc",
		fmt.Sprintf(
			"[ -d /home/application/current ] && cd /home/application/current; %s && exec python myapp.py",
			extraRegisterCmds(a),
		),
	})
}
开发者ID:tsuru,项目名称:tsuru,代码行数:56,代码来源:actions_test.go

示例9: TestSavePortInImageCustomData

func (s *S) TestSavePortInImageCustomData(c *check.C) {
	img1 := "tsuru/app-myapp:v1"
	customData1 := map[string]interface{}{
		"exposedPort": "3434",
	}
	err := image.SaveImageCustomData(img1, customData1)
	c.Assert(err, check.IsNil)
	imageMetaData, err := image.GetImageCustomData(img1)
	c.Check(err, check.IsNil)
	c.Check(imageMetaData.ExposedPort, check.Equals, "3434")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:11,代码来源:image_test.go

示例10: TestDeleteAllAppImageNamesRemovesCustomDataWithoutImages

func (s *S) TestDeleteAllAppImageNamesRemovesCustomDataWithoutImages(c *check.C) {
	imgName := "tsuru/app-myapp:v1"
	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.ErrorMatches, "not found")
	yamlData, err := image.GetImageTsuruYamlData(imgName)
	c.Assert(err, check.IsNil)
	c.Assert(yamlData, check.DeepEquals, provision.TsuruYamlData{})
}
开发者ID:tsuru,项目名称:tsuru,代码行数:11,代码来源:image_test.go

示例11: TestActionUpdateServicesBackwardNotInCurrent

func (s *S) TestActionUpdateServicesBackwardNotInCurrent(c *check.C) {
	srv, err := testing.NewServer("127.0.0.1:0", nil, nil)
	c.Assert(err, check.IsNil)
	metadata := map[string]string{"m1": "v1", labelNodePoolName.String(): "p1"}
	opts := provision.AddNodeOptions{
		Address:  srv.URL(),
		Metadata: metadata,
	}
	err = s.p.AddNode(opts)
	c.Assert(err, check.IsNil)
	cli, err := chooseDBSwarmNode()
	c.Assert(err, check.IsNil)
	a := &app.App{Name: "myapp", Platform: "whitespace", TeamOwner: s.team.Name}
	err = app.CreateApp(a, s.user)
	c.Assert(err, check.IsNil)
	_, err = cli.CreateService(docker.CreateServiceOptions{
		ServiceSpec: swarm.ServiceSpec{
			TaskTemplate: swarm.TaskSpec{
				ContainerSpec: swarm.ContainerSpec{
					Command: []string{"original-web"},
				},
			},
			Annotations: swarm.Annotations{
				Name: "myapp-web",
			},
		},
	})
	c.Assert(err, check.IsNil)
	imgName := "app:v1"
	err = image.SaveImageCustomData(imgName, map[string]interface{}{
		"processes": map[string]interface{}{
			"web": "python myapp.py",
		},
	})
	c.Assert(err, check.IsNil)
	args := &pipelineArgs{
		client:           cli,
		app:              a,
		currentImage:     imgName,
		newImageSpec:     processSpec{"web": processState{}},
		currentImageSpec: processSpec{},
	}
	updateServices.Backward(action.BWContext{
		FWResult: []string{"web"},
		Params:   []interface{}{args},
	})
	_, err = cli.InspectService("myapp-web")
	c.Assert(err, check.ErrorMatches, "No such service.*")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:49,代码来源:actions_test.go

示例12: TestRunLeanContainersCmd

func (s *S) TestRunLeanContainersCmd(c *check.C) {
	imageId := "tsuru/app-sample"
	customData := map[string]interface{}{
		"processes": map[string]interface{}{
			"web": "python web.py",
		},
	}
	err := image.SaveImageCustomData(imageId, customData)
	c.Assert(err, check.IsNil)
	cmds, process, err := LeanContainerCmds("web", imageId, nil)
	c.Assert(err, check.IsNil)
	c.Assert(process, check.Equals, "web")
	expected := []string{"/bin/sh", "-lc", "[ -d /home/application/current ] && cd /home/application/current; exec python web.py"}
	c.Assert(cmds, check.DeepEquals, expected)
}
开发者ID:tsuru,项目名称:tsuru,代码行数:15,代码来源:commands_test.go

示例13: TestHealthcheckSuccessfulWithAllowedFailures

func (s *S) TestHealthcheckSuccessfulWithAllowedFailures(c *check.C) {
	var requests []*http.Request
	lock := sync.Mutex{}
	step := 0
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		lock.Lock()
		defer lock.Unlock()
		requests = append(requests, r)
		if step == 2 {
			w.WriteHeader(http.StatusOK)
		} else if step == 1 {
			w.WriteHeader(http.StatusBadGateway)
		} else {
			hj := w.(http.Hijacker)
			conn, _, _ := hj.Hijack()
			conn.Close()
		}
		step++
	}))
	defer server.Close()
	a := app.App{Name: "myapp1"}
	customData := map[string]interface{}{
		"healthcheck": map[string]interface{}{
			"path":             "/x/y",
			"allowed_failures": 1,
		},
	}
	imageName := "tsuru/app"
	err := image.SaveImageCustomData(imageName, customData)
	c.Assert(err, check.IsNil)
	err = s.storage.Apps().Insert(a)
	c.Assert(err, check.IsNil)
	defer s.storage.Apps().RemoveAll(bson.M{"name": a.Name})
	url, _ := url.Parse(server.URL)
	host, port, _ := net.SplitHostPort(url.Host)
	cont := container.Container{AppName: a.Name, HostAddr: host, HostPort: port, Image: imageName}
	buf := bytes.Buffer{}
	err = runHealthcheck(&cont, &buf)
	c.Assert(err, check.IsNil)
	c.Assert(buf.String(), check.Matches, `(?s).*---> healthcheck fail.*?Trying again in 3s.*---> healthcheck fail.*?Trying again in 3s.*---> healthcheck successful.*`)
	c.Assert(requests, check.HasLen, 3)
	c.Assert(requests[0].Method, check.Equals, "GET")
	c.Assert(requests[0].URL.Path, check.Equals, "/x/y")
	c.Assert(requests[1].Method, check.Equals, "GET")
	c.Assert(requests[1].URL.Path, check.Equals, "/x/y")
	c.Assert(requests[2].Method, check.Equals, "GET")
	c.Assert(requests[2].URL.Path, check.Equals, "/x/y")
}
开发者ID:tsuru,项目名称:tsuru,代码行数:48,代码来源:healthcheck_test.go

示例14: newFakeImage

func (s *S) newFakeImage(p *dockerProvisioner, repo string, customData map[string]interface{}) error {
	if customData == nil {
		customData = map[string]interface{}{
			"processes": map[string]interface{}{
				"web": "python myapp.py",
			},
		}
	}
	var buf safe.Buffer
	opts := docker.PullImageOptions{Repository: repo, OutputStream: &buf}
	err := image.SaveImageCustomData(repo, customData)
	if err != nil && !mgo.IsDup(err) {
		return err
	}
	return p.Cluster().PullImage(opts, docker.AuthConfiguration{})
}
开发者ID:tsuru,项目名称:tsuru,代码行数:16,代码来源:docker_test.go

示例15: TestSaveImageCustomDataProcfile

func (s *S) TestSaveImageCustomDataProcfile(c *check.C) {
	img1 := "tsuru/app-myapp:v1"
	customData1 := map[string]interface{}{
		"exposedPort": "3434",
		"procfile":    "worker1: python myapp.py\nworker2: someworker",
	}
	err := image.SaveImageCustomData(img1, customData1)
	c.Assert(err, check.IsNil)
	imageMetaData, err := image.GetImageCustomData(img1)
	c.Check(err, check.IsNil)
	c.Check(imageMetaData.ExposedPort, check.Equals, "3434")
	c.Check(imageMetaData.Processes, check.DeepEquals, map[string][]string{
		"worker1": {"python myapp.py"},
		"worker2": {"someworker"},
	})
}
开发者ID:tsuru,项目名称:tsuru,代码行数:16,代码来源:image_test.go


注:本文中的github.com/tsuru/tsuru/app/image.SaveImageCustomData函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。