本文整理汇总了Golang中github.com/tsuru/tsuru/app.GetPlatform函数的典型用法代码示例。如果您正苦于以下问题:Golang GetPlatform函数的具体用法?Golang GetPlatform怎么用?Golang GetPlatform使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetPlatform函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestContainerCreate
func (s *S) TestContainerCreate(c *gocheck.C) {
app := testing.NewFakeApp("app-name", "brainfuck", 1)
app.Memory = 15
rtesting.FakeRouter.AddBackend(app.GetName())
defer rtesting.FakeRouter.RemoveBackend(app.GetName())
dockerCluster().PullImage(
docker.PullImageOptions{Repository: "tsuru/brainfuck"},
docker.AuthConfiguration{},
)
cont := container{Name: "myName", AppName: app.GetName(), Type: app.GetPlatform(), Status: "created"}
err := cont.create(app, getImage(app), []string{"docker", "run"})
c.Assert(err, gocheck.IsNil)
defer s.removeTestContainer(&cont)
c.Assert(cont.ID, gocheck.Not(gocheck.Equals), "")
c.Assert(cont, gocheck.FitsTypeOf, container{})
c.Assert(cont.AppName, gocheck.Equals, app.GetName())
c.Assert(cont.Type, gocheck.Equals, app.GetPlatform())
u, _ := url.Parse(s.server.URL())
host, _, _ := net.SplitHostPort(u.Host)
c.Assert(cont.HostAddr, gocheck.Equals, host)
user, err := config.GetString("docker:ssh:user")
c.Assert(err, gocheck.IsNil)
c.Assert(cont.User, gocheck.Equals, user)
dcli, _ := docker.NewClient(s.server.URL())
container, err := dcli.InspectContainer(cont.ID)
c.Assert(err, gocheck.IsNil)
c.Assert(container.Path, gocheck.Equals, "docker")
c.Assert(container.Args, gocheck.DeepEquals, []string{"run"})
c.Assert(container.Config.User, gocheck.Equals, user)
c.Assert(container.Config.Memory, gocheck.Equals, int64(app.Memory*1024*1024))
}
示例2: TestContainerCreate
func (s *S) TestContainerCreate(c *check.C) {
config.Set("host", "my.cool.tsuru.addr:8080")
defer config.Unset("host")
app := provisiontest.NewFakeApp("app-name", "brainfuck", 1)
app.Memory = 15
app.Swap = 15
app.CpuShare = 50
app.SetEnv(bind.EnvVar{Name: "A", Value: "myenva"})
app.SetEnv(bind.EnvVar{Name: "ABCD", Value: "other env"})
routertest.FakeRouter.AddBackend(app.GetName())
defer routertest.FakeRouter.RemoveBackend(app.GetName())
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
ProcessName: "myprocess1",
}
err := cont.Create(&CreateArgs{
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
c.Assert(cont.ID, check.Not(check.Equals), "")
c.Assert(cont.AppName, check.Equals, app.GetName())
c.Assert(cont.Type, check.Equals, app.GetPlatform())
u, _ := url.Parse(s.server.URL())
host, _, _ := net.SplitHostPort(u.Host)
c.Assert(cont.HostAddr, check.Equals, host)
user, err := config.GetString("docker:user")
c.Assert(err, check.IsNil)
c.Assert(cont.User, check.Equals, user)
dcli, _ := docker.NewClient(s.server.URL())
container, err := dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(container.Path, check.Equals, "docker")
c.Assert(container.Args, check.DeepEquals, []string{"run"})
c.Assert(container.Config.User, check.Equals, user)
c.Assert(container.Config.Memory, check.Equals, app.Memory)
c.Assert(container.Config.MemorySwap, check.Equals, app.Memory+app.Swap)
c.Assert(container.Config.CPUShares, check.Equals, int64(app.CpuShare))
sort.Strings(container.Config.Env)
c.Assert(container.Config.Env, check.DeepEquals, []string{
"A=myenva",
"ABCD=other env",
"PORT=8888",
"TSURU_HOST=my.cool.tsuru.addr:8080",
"TSURU_PROCESSNAME=myprocess1",
"port=8888",
})
}
示例3: TestCreateContainerForward
func (s *S) TestCreateContainerForward(c *check.C) {
config.Set("docker:user", "ubuntu")
defer config.Unset("docker:user")
err := s.newFakeImage(s.p, "tsuru/python", nil)
c.Assert(err, check.IsNil)
client, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
images, err := client.ListImages(docker.ListImagesOptions{All: true})
c.Assert(err, check.IsNil)
cmds := []string{"ps", "-ef"}
app := provisiontest.NewFakeApp("myapp", "python", 1)
cont := container.Container{Name: "myName", AppName: app.GetName(), Type: app.GetPlatform(), Status: "created"}
args := runContainerActionsArgs{
app: app,
imageID: images[0].ID,
commands: cmds,
provisioner: s.p,
buildingImage: images[0].ID,
isDeploy: true,
}
context := action.FWContext{Previous: cont, Params: []interface{}{args}}
r, err := createContainer.Forward(context)
c.Assert(err, check.IsNil)
cont = r.(container.Container)
defer cont.Remove(s.p)
c.Assert(cont, check.FitsTypeOf, container.Container{})
c.Assert(cont.ID, check.Not(check.Equals), "")
c.Assert(cont.HostAddr, check.Equals, "127.0.0.1")
dcli, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
cc, err := dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(cc.State.Running, check.Equals, false)
c.Assert(cc.Config.User, check.Equals, "ubuntu")
args = runContainerActionsArgs{
app: app,
imageID: images[0].ID,
commands: cmds,
provisioner: s.p,
}
optsPull := docker.PullImageOptions{Repository: images[0].ID, OutputStream: nil}
err = s.p.Cluster().PullImage(optsPull, docker.AuthConfiguration{})
c.Assert(err, check.IsNil)
cont = container.Container{Name: "myName2", AppName: app.GetName(), Type: app.GetPlatform(), Status: "created"}
context = action.FWContext{Previous: cont, Params: []interface{}{args}}
r, err = createContainer.Forward(context)
c.Assert(err, check.IsNil)
cont = r.(container.Container)
defer cont.Remove(s.p)
cc, err = dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(cc.Config.User, check.Equals, "")
}
示例4: TestInsertEmptyContainerInDBForward
func (s *S) TestInsertEmptyContainerInDBForward(c *check.C) {
app := provisiontest.NewFakeApp("myapp", "python", 1)
args := runContainerActionsArgs{
app: app,
imageID: "image-id",
buildingImage: "next-image",
provisioner: s.p,
}
context := action.FWContext{Params: []interface{}{args}}
r, err := insertEmptyContainerInDB.Forward(context)
c.Assert(err, check.IsNil)
cont := r.(container.Container)
c.Assert(cont, check.FitsTypeOf, container.Container{})
c.Assert(cont.AppName, check.Equals, app.GetName())
c.Assert(cont.Type, check.Equals, app.GetPlatform())
c.Assert(cont.Name, check.Not(check.Equals), "")
c.Assert(strings.HasPrefix(cont.Name, app.GetName()+"-"), check.Equals, true)
c.Assert(cont.Name, check.HasLen, 26)
c.Assert(cont.Status, check.Equals, "created")
c.Assert(cont.Image, check.Equals, "image-id")
c.Assert(cont.BuildingImage, check.Equals, "next-image")
coll := s.p.Collection()
defer coll.Close()
defer coll.Remove(bson.M{"name": cont.Name})
var retrieved container.Container
err = coll.Find(bson.M{"name": cont.Name}).One(&retrieved)
c.Assert(err, check.IsNil)
c.Assert(retrieved.Name, check.Equals, cont.Name)
}
示例5: TestContainerCreateDoesNotAlocatesPortForDeploy
func (s *S) TestContainerCreateDoesNotAlocatesPortForDeploy(c *check.C) {
s.server.CustomHandler("/images/.*/json", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := docker.Image{
Config: &docker.Config{
ExposedPorts: map[docker.Port]struct{}{},
},
}
j, _ := json.Marshal(response)
w.Write(j)
}))
app := provisiontest.NewFakeApp("app-name", "brainfuck", 1)
app.Memory = 15
routertest.FakeRouter.AddBackend(app.GetName())
defer routertest.FakeRouter.RemoveBackend(app.GetName())
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
}
err := cont.Create(&CreateArgs{
Deploy: true,
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
info, err := cont.NetworkInfo(s.p)
c.Assert(err, check.IsNil)
c.Assert(info.HTTPHostPort, check.Equals, "")
}
示例6: TestContainerCreateSecurityOptions
func (s *S) TestContainerCreateSecurityOptions(c *check.C) {
config.Set("docker:security-opts", []string{"label:type:svirt_apache", "ptrace [email protected]"})
defer config.Unset("docker:security-opts")
app := provisiontest.NewFakeApp("app-name", "brainfuck", 1)
app.Memory = 15
app.Swap = 15
app.CpuShare = 50
routertest.FakeRouter.AddBackend(app.GetName())
defer routertest.FakeRouter.RemoveBackend(app.GetName())
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
}
err := cont.Create(&CreateArgs{
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
dcli, _ := docker.NewClient(s.server.URL())
container, err := dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(container.Config.SecurityOpts, check.DeepEquals, []string{"label:type:svirt_apache", "ptrace [email protected]"})
}
示例7: TestContainerCreateDoesNotAlocatesPortForDeploy
func (s *S) TestContainerCreateDoesNotAlocatesPortForDeploy(c *check.C) {
app := provisiontest.NewFakeApp("app-name", "brainfuck", 1)
app.Memory = 15
routertest.FakeRouter.AddBackend(app.GetName())
defer routertest.FakeRouter.RemoveBackend(app.GetName())
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
}
err := cont.Create(&CreateArgs{
Deploy: true,
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
info, err := cont.NetworkInfo(s.p)
c.Assert(err, check.IsNil)
c.Assert(info.HTTPHostPort, check.Equals, "")
}
示例8: TestContainerCreateUndefinedUser
func (s *S) TestContainerCreateUndefinedUser(c *check.C) {
oldUser, _ := config.Get("docker:user")
defer config.Set("docker:user", oldUser)
config.Unset("docker:user")
img := "tsuru/python:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
app := provisiontest.NewFakeApp("app-name", "python", 1)
routertest.FakeRouter.AddBackend(app.GetName())
defer routertest.FakeRouter.RemoveBackend(app.GetName())
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
}
err := cont.Create(&CreateArgs{
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
dcli, _ := docker.NewClient(s.server.URL())
container, err := dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(container.Config.User, check.Equals, "")
}
示例9: TestProvisionRemoveOldUnitForward
func (s *S) TestProvisionRemoveOldUnitForward(c *gocheck.C) {
err := newImage("tsuru/python", s.server.URL())
c.Assert(err, gocheck.IsNil)
container, err := s.newContainer(nil)
c.Assert(err, gocheck.IsNil)
defer rtesting.FakeRouter.RemoveBackend(container.AppName)
client, err := dockerClient.NewClient(s.server.URL())
c.Assert(err, gocheck.IsNil)
err = client.StartContainer(container.ID, nil)
c.Assert(err, gocheck.IsNil)
app := testing.NewFakeApp(container.AppName, "python", 0)
unit := provision.Unit{
Name: container.ID,
AppName: app.GetName(),
Type: app.GetPlatform(),
Ip: container.HostAddr,
Status: provision.StatusBuilding,
}
context := action.FWContext{Params: []interface{}{app, "", *container}, Previous: unit}
result, err := provisionRemoveOldUnit.Forward(context)
c.Assert(err, gocheck.IsNil)
retUnit := result.(provision.Unit)
c.Assert(retUnit, gocheck.DeepEquals, unit)
_, err = getContainer(container.ID)
c.Assert(err, gocheck.NotNil)
}
示例10: TestCreateContainerForward
func (s *S) TestCreateContainerForward(c *gocheck.C) {
cmutex.Lock()
oldClusterNodes := clusterNodes
clusterNodes = map[string]string{
"server": "http://localhost:8081",
}
cmutex.Unlock()
defer func() {
cmutex.Lock()
clusterNodes = oldClusterNodes
cmutex.Unlock()
}()
err := newImage("tsuru/python", s.server.URL())
c.Assert(err, gocheck.IsNil)
client, err := dockerClient.NewClient(s.server.URL())
c.Assert(err, gocheck.IsNil)
images, err := client.ListImages(true)
c.Assert(err, gocheck.IsNil)
cmds := []string{"ps", "-ef"}
app := testing.NewFakeApp("myapp", "python", 1)
cont := container{Name: "myName", AppName: app.GetName(), Type: app.GetPlatform(), Status: "created"}
context := action.FWContext{Previous: cont, Params: []interface{}{app, images[0].ID, cmds}}
r, err := createContainer.Forward(context)
c.Assert(err, gocheck.IsNil)
cont = r.(container)
defer cont.remove()
c.Assert(cont, gocheck.FitsTypeOf, container{})
c.Assert(cont.ID, gocheck.Not(gocheck.Equals), "")
c.Assert(cont.HostAddr, gocheck.Equals, "localhost")
dcli, err := dockerClient.NewClient(s.server.URL())
c.Assert(err, gocheck.IsNil)
cc, err := dcli.InspectContainer(cont.ID)
c.Assert(err, gocheck.IsNil)
c.Assert(cc.State.Running, gocheck.Equals, false)
}
示例11: TestCreateContainerForward
func (s *S) TestCreateContainerForward(c *check.C) {
err := s.newFakeImage(s.p, "tsuru/python", nil)
c.Assert(err, check.IsNil)
client, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
images, err := client.ListImages(docker.ListImagesOptions{All: true})
c.Assert(err, check.IsNil)
cmds := []string{"ps", "-ef"}
app := provisiontest.NewFakeApp("myapp", "python", 1)
cont := container.Container{Name: "myName", AppName: app.GetName(), Type: app.GetPlatform(), Status: "created"}
args := runContainerActionsArgs{
app: app,
imageID: images[0].ID,
commands: cmds,
provisioner: s.p,
}
context := action.FWContext{Previous: cont, Params: []interface{}{args}}
r, err := createContainer.Forward(context)
c.Assert(err, check.IsNil)
cont = r.(container.Container)
defer cont.Remove(s.p)
c.Assert(cont, check.FitsTypeOf, container.Container{})
c.Assert(cont.ID, check.Not(check.Equals), "")
c.Assert(cont.HostAddr, check.Equals, "127.0.0.1")
dcli, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
cc, err := dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(cc.State.Running, check.Equals, false)
}
示例12: TestContainerCreateOverwriteEntrypoint
func (s *S) TestContainerCreateOverwriteEntrypoint(c *check.C) {
config.Set("host", "my.cool.tsuru.addr:8080")
defer config.Unset("host")
app := provisiontest.NewFakeApp("app-name", "brainfuck", 1)
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
}
err := cont.Create(&CreateArgs{
Deploy: true,
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
dcli, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
container, err := dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(container.Config.Entrypoint, check.DeepEquals, []string{})
}
示例13: TestContainerCreateCustomLog
func (s *S) TestContainerCreateCustomLog(c *check.C) {
client, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
app := provisiontest.NewFakeApp("myapp", "python", 1)
app.Pool = "mypool"
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
testCases := []struct {
name string
opts map[string]string
}{
{"fluentd", map[string]string{
"fluentd-address": "localhost:24224",
}},
{"syslog", map[string]string{
"syslog-address": "udp://localhost:1514",
}},
{"fluentd", map[string]string{
"fluentd-address": "somewhere:24224",
"tag": "x",
}},
}
for i, testData := range testCases {
c.Logf("test %d", i)
cont := Container{
Name: fmt.Sprintf("myName-%d", i),
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
ProcessName: "myprocess1",
ExposedPort: "8888/tcp",
}
conf := DockerLogConfig{Driver: testData.name, LogOpts: testData.opts}
err = conf.Save(app.Pool)
c.Assert(err, check.IsNil)
err := cont.Create(&CreateArgs{
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
dockerContainer, err := client.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(dockerContainer.HostConfig.LogConfig.Type, check.Equals, testData.name)
c.Assert(dockerContainer.HostConfig.LogConfig.Config, check.DeepEquals, testData.opts)
}
}
示例14: TestContainerCreateForDeploy
func (s *S) TestContainerCreateForDeploy(c *check.C) {
s.server.CustomHandler("/images/.*/json", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := docker.Image{
Config: &docker.Config{
ExposedPorts: map[docker.Port]struct{}{},
},
}
j, _ := json.Marshal(response)
w.Write(j)
}))
app := provisiontest.NewFakeApp("app-name", "brainfuck", 1)
app.Memory = 15
app.Swap = 15
app.CpuShare = 50
routertest.FakeRouter.AddBackend(app.GetName())
defer routertest.FakeRouter.RemoveBackend(app.GetName())
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
}
err := cont.Create(&CreateArgs{
Deploy: true,
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
info, err := cont.NetworkInfo(s.p)
c.Assert(err, check.IsNil)
c.Assert(info.HTTPHostPort, check.Equals, "")
client, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
dockerContainer, err := client.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
c.Assert(dockerContainer.HostConfig.RestartPolicy.Name, check.Equals, "")
c.Assert(dockerContainer.HostConfig.LogConfig.Type, check.Equals, "")
c.Assert(dockerContainer.HostConfig.Memory, check.Equals, int64(0))
c.Assert(dockerContainer.HostConfig.MemorySwap, check.Equals, int64(0))
c.Assert(dockerContainer.HostConfig.CPUShares, check.Equals, int64(50))
c.Assert(dockerContainer.HostConfig.OomScoreAdj, check.Equals, 1000)
}
示例15: TestContainerCreateDoesNotSetEnvs
func (s *S) TestContainerCreateDoesNotSetEnvs(c *check.C) {
s.server.CustomHandler("/images/.*/json", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := docker.Image{
Config: &docker.Config{
ExposedPorts: map[docker.Port]struct{}{},
},
}
j, _ := json.Marshal(response)
w.Write(j)
}))
config.Set("host", "my.cool.tsuru.addr:8080")
defer config.Unset("host")
app := provisiontest.NewFakeApp("app-name", "brainfuck", 1)
app.SetEnv(bind.EnvVar{Name: "A", Value: "myenva"})
app.SetEnv(bind.EnvVar{Name: "ABCD", Value: "other env"})
routertest.FakeRouter.AddBackend(app.GetName())
defer routertest.FakeRouter.RemoveBackend(app.GetName())
img := "tsuru/brainfuck:latest"
s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
cont := Container{
Name: "myName",
AppName: app.GetName(),
Type: app.GetPlatform(),
Status: "created",
}
err := cont.Create(&CreateArgs{
Deploy: true,
App: app,
ImageID: img,
Commands: []string{"docker", "run"},
Provisioner: s.p,
})
c.Assert(err, check.IsNil)
defer s.removeTestContainer(&cont)
dcli, err := docker.NewClient(s.server.URL())
c.Assert(err, check.IsNil)
container, err := dcli.InspectContainer(cont.ID)
c.Assert(err, check.IsNil)
sort.Strings(container.Config.Env)
c.Assert(container.Config.Env, check.DeepEquals, []string{
"PORT=",
"TSURU_HOST=my.cool.tsuru.addr:8080",
"port=",
})
}