• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang docker.NewProject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: newProject

func newProject(name string, cfg *config.CloudConfig, environmentLookup project.EnvironmentLookup) (*project.Project, error) {
	clientFactory, err := rosDocker.NewClientFactory(docker.ClientOpts{})
	if err != nil {
		return nil, err
	}

	if environmentLookup == nil {
		environmentLookup = rosDocker.NewConfigEnvironment(cfg)
	}

	serviceFactory := &rosDocker.ServiceFactory{
		Deps: map[string][]string{},
	}
	context := &docker.Context{
		ClientFactory: clientFactory,
		Context: project.Context{
			ProjectName:       name,
			NoRecreate:        true, // for libcompose to not recreate on project reload, looping up the boot :)
			EnvironmentLookup: environmentLookup,
			ServiceFactory:    serviceFactory,
			Log:               cfg.Rancher.Log,
			LoggerFactory:     logger.NewColorLoggerFactory(),
		},
	}
	serviceFactory.Context = context

	return docker.NewProject(context)
}
开发者ID:carriercomm,项目名称:os,代码行数:28,代码来源:project.go


示例2: createComposeProject

func (s *BaseSuite) createComposeProject(c *check.C, name string) {
	composeProject, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFile: fmt.Sprintf("resources/compose/%s.yml", name),
			ProjectName: fmt.Sprintf("integration-test-%s", name),
		},
	})
	c.Assert(err, checker.IsNil)
	s.composeProject = composeProject

	s.started = make(chan bool)
	s.stopped = make(chan bool)
	s.deleted = make(chan bool)

	s.listenChan = make(chan project.Event)
	go s.startListening(c)

	composeProject.AddListener(s.listenChan)

	composeProject.Start()

	// Wait for compose to start
	<-s.started
	defer close(s.started)
}
开发者ID:rasata,项目名称:traefik,代码行数:25,代码来源:integration_test.go


示例3: ReadComposeVolumes

// ReadComposeVolumes reads a docker-compose.yml and return a slice of
// directories to sync into the Docker Host
//
// "." and "./." is converted to the current directory parity is running from.
// Any volume starting with "/" will be treated as an absolute path.
// All other volumes (e.g. starting with "./" or without a prefix "/") will be treated as
// relative paths.
func ReadComposeVolumes() []string {
	var volumes []string

	files := FindDockerComposeFiles()
	for i, file := range files {
		if _, err := os.Stat(file); err == nil {
			project, err := docker.NewProject(&docker.Context{
				Context: project.Context{
					ComposeFiles: []string{file},
					ProjectName:  fmt.Sprintf("parity-%d", i),
				},
			})

			if err != nil {
				log.Info("Could not parse compose file")
			}

			for _, c := range project.Configs {
				for _, v := range c.Volumes {
					v = strings.SplitN(v, ":", 2)[0]

					if v == "." || v == "./." {
						v, _ = os.Getwd()
					} else if strings.Index(v, "/") != 0 {
						cwd, _ := os.Getwd()
						v = fmt.Sprintf("%s/%s", cwd, v)
					}
					volumes = append(volumes, mutils.LinuxPath(v))
				}
			}
		}
	}

	return volumes
}
开发者ID:mefellows,项目名称:parity,代码行数:42,代码来源:utils.go


示例4: createDockerContext

func (c *ComposeWrapper) createDockerContext() (project.APIProject, error) {

	if c.context.EnvParams != nil && len(c.context.EnvParams) > 0 {
		file, err := os.Open(c.context.ComposeFile)
		if err != nil {
			return nil, fmt.Errorf("Error opening filename %s, %s", c.context.ComposeFile, err.Error())
		}
		parsed, missing := envsubst.SubstFileTokens(file, c.context.EnvParams)
		log.Debug("Map: %v\nParsed: %s\n", c.context.EnvParams, parsed)

		if c.context.ErrorOnMissingParams && missing {
			return nil, ErrorParamsMissing
		}
		file, err = ioutil.TempFile("", "depcon")
		if err != nil {
			return nil, err
		}
		err = ioutil.WriteFile(file.Name(), []byte(parsed), os.ModeTemporary)
		if err != nil {
			return nil, err
		}
		c.context.ComposeFile = file.Name()
	}
	return docker.NewProject(&ctx.Context{
		Context: project.Context{
			ComposeFiles: strings.Split(c.context.ComposeFile, ","),
			ProjectName:  c.context.ProjectName,
		},
	}, nil)
}
开发者ID:ContainX,项目名称:depcon,代码行数:30,代码来源:compose_wrapper.go


示例5: CreateProject

// CreateProject creates a compose project with the given name based on the
// specified compose files
func CreateProject(name string, composeFiles ...string) (*Project, error) {
	apiClient, err := client.NewEnvClient()
	if err != nil {
		return nil, err
	}
	composeProject, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFiles: composeFiles,
			ProjectName:  name,
		},
	})
	if err != nil {
		return nil, err
	}
	p := &Project{
		composeProject: composeProject,
		listenChan:     make(chan project.Event),
		started:        make(chan struct{}),
		stopped:        make(chan struct{}),
		deleted:        make(chan struct{}),
		client:         apiClient,
	}

	// Listen to compose events
	go p.startListening()
	p.composeProject.AddListener(p.listenChan)

	return p, nil
}
开发者ID:vdemeester,项目名称:libkermit,代码行数:31,代码来源:compose.go


示例6: Create

// Create implements ProjectFactory.Create using docker client.
func (p *ProjectFactory) Create(c *cli.Context) (*project.Project, error) {
	context := &docker.Context{}
	context.LoggerFactory = logger.NewColorLoggerFactory()
	Populate(context, c)
	command.Populate(&context.Context, c)

	return docker.NewProject(context)
}
开发者ID:pirater,项目名称:os,代码行数:9,代码来源:factory.go


示例7: up

func up(cmd *cobra.Command, args []string) {

	//make sure user is authenticated
	username, token, _ := Login()

	//read the harbor compose file
	harborCompose := DeserializeHarborCompose(HarborComposeFile)

	//read the docker compose file
	dockerCompose := DeserializeDockerCompose(DockerComposeFile)

	//use libcompose to parse compose yml file as well (since it supports the full spec)
	dockerComposeProject, err := docker.NewProject(&ctx.Context{
		Context: project.Context{
			ComposeFiles: []string{DockerComposeFile},
		},
	}, nil)

	if err != nil {
		log.Fatal(err)
	}

	//iterate shipments
	for shipmentName, shipment := range harborCompose.Shipments {
		fmt.Printf("Starting %v ...\n", shipmentName)

		if Verbose {
			log.Printf("processing shipment: %v/%v", shipmentName, shipment.Env)
		}

		//fetch the current state
		shipmentObject := GetShipmentEnvironment(username, token, shipmentName, shipment.Env)

		//creating a shipment is a different workflow than updating
		//bulk create a shipment if it doesn't exist
		if shipmentObject == nil {
			if Verbose {
				log.Println("shipment environment not found")
			}
			createShipment(username, token, shipmentName, dockerCompose, shipment, dockerComposeProject)

		} else {
			//make changes to harbor based on compose files
			updateShipment(username, token, shipmentObject, shipmentName, dockerCompose, shipment, dockerComposeProject)

			//TODO: desired state reconciliation
		}

		fmt.Println("done")

	} //shipments
}
开发者ID:turnerlabs,项目名称:harbor-compose,代码行数:52,代码来源:up.go


示例8: main

func main() {
	project, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFile: "docker-compose.yml",
			ProjectName: "yeah-compose",
		},
	})

	if err != nil {
		log.Fatal(err)
	}

	project.Up()
}
开发者ID:schmunk42,项目名称:libcompose,代码行数:14,代码来源:main.go


示例9: createDockerContext

func (c *ComposeWrapper) createDockerContext() (*project.Project, error) {

	clientFactory, err := docker.NewDefaultClientFactory(docker.ClientOpts{})
	if err != nil {
		log.Fatal(err)
	}

	tlsVerify := os.Getenv(DOCKER_TLS_VERIFY)

	if tlsVerify == "1" {
		clientFactory, err = docker.NewDefaultClientFactory(docker.ClientOpts{
			TLS:       true,
			TLSVerify: true,
		})
		if err != nil {
			log.Fatal(err)
		}
	}

	if c.context.EnvParams != nil && len(c.context.EnvParams) > 0 {
		file, err := os.Open(c.context.ComposeFile)
		if err != nil {
			return nil, fmt.Errorf("Error opening filename %s, %s", c.context.ComposeFile, err.Error())
		}
		parsed, missing := envsubst.SubstFileTokens(file, c.context.ComposeFile, c.context.EnvParams)
		log.Debug("Map: %v\nParsed: %s\n", c.context.EnvParams, parsed)

		if c.context.ErrorOnMissingParams && missing {
			return nil, ErrorParamsMissing
		}
		file, err = ioutil.TempFile("", "depcon")
		if err != nil {
			return nil, err
		}
		err = ioutil.WriteFile(file.Name(), []byte(parsed), os.ModeTemporary)
		if err != nil {
			return nil, err
		}
		c.context.ComposeFile = file.Name()
	}

	return docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFile: c.context.ComposeFile,
			ProjectName: c.context.ProjectName,
		},
		ClientFactory: clientFactory,
	})
}
开发者ID:f1yegor,项目名称:depcon,代码行数:49,代码来源:compose_wrapper.go


示例10: NewProject

// Helepr function to return a new project.
func NewProject(n string) *project.Project {
	c := &docker.Context{
		Context: project.Context{
			ComposeFile: "docker-compose.yml",
			ProjectName: n,
		},
	}

	p, err := docker.NewProject(c)
	if err != nil {
		Exit(err)
	}

	return p
}
开发者ID:nickschuch,项目名称:up,代码行数:16,代码来源:main.go


示例11: Compose

func (ComposeService) Compose(s string) error {
	project, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFile: "docker-compose.yml",
			ProjectName: "my-compose",
		},
	})

	check(err)
	fmt.Println(s)

	project.Up()

	return nil
}
开发者ID:gunjan5,项目名称:Skywalker,代码行数:15,代码来源:compose.go


示例12: BuildComposeProject

func BuildComposeProject(composeFile string) (*project.Project, error) {
	project, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFile:   composeFile,
			ProjectName:   projectNameByGitProject(),
			LoggerFactory: logger.NewColorLoggerFactory(),
		},
	})
	if err != nil {
		return nil, err
	}
	sanitizeConfig(project)

	return project, nil
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:15,代码来源:types.go


示例13: main

// main function
func main() {

	fmt.Println("Feed me a compose file now:")
	// Read in our compose file from stdin
	yamlbytes, err := ioutil.ReadAll(os.Stdin)

	// unmarshal it so we can enumerate our services
	yaml.Unmarshal(yamlbytes, &services)

	// create a new compose project
	p, err = docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeBytes: yamlbytes,
			ProjectName:  "my-compose", // TODO make an environment variable
		},
	})

	if err != nil {
		log.Fatal(err)
	}

	// create our docker client link
	client, _ := dockerclient.NewClientFromEnv()

	// make and attach our listener channel
	events := make(chan *dockerclient.APIEvents)
	client.AddEventListener(events)

	// start watching for events
	go watchEvents(events)

	// main loop
	for {
		// look up how many nodes we have in the cluster
		// this is mainly for when a node is added
		nodes = getNodes(client)

		// Print the number of nodes we found
		log.Printf("Nodes: %d\n", nodes)

		// Do the heavy lifting once
		scale()

		// sleep for a bit, then check again
		time.Sleep(time.Minute) // TODO make an environment variable
	}
}
开发者ID:brimstone,项目名称:go-compose,代码行数:48,代码来源:main.go


示例14: Create

// Create implements ProjectFactory.Create using docker client.
func (p *ProjectFactory) Create(c *cli.Context) (project.APIProject, error) {
	context := &docker.Context{}
	context.LoggerFactory = logger.NewColorLoggerFactory()
	Populate(context, c)

	context.ComposeFiles = c.GlobalStringSlice("file")

	if len(context.ComposeFiles) == 0 {
		context.ComposeFiles = []string{"docker-compose.yml"}
		if _, err := os.Stat("docker-compose.override.yml"); err == nil {
			context.ComposeFiles = append(context.ComposeFiles, "docker-compose.override.yml")
		}
	}

	context.ProjectName = c.GlobalString("project-name")

	return docker.NewProject(context, nil)
}
开发者ID:haj,项目名称:kompose,代码行数:19,代码来源:factory.go


示例15: main

func main() {
	project, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFiles: []string{"docker-compose.yml"},
			ProjectName:  "yeah-compose",
		},
	}, nil)

	if err != nil {
		log.Fatal(err)
	}

	err = project.Up(context.Background(), options.Up{})

	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:haj,项目名称:kompose,代码行数:18,代码来源:main.go


示例16: TestVolumeWithoutComposeFile

func (s *APISuite) TestVolumeWithoutComposeFile(c *C) {
	service := `
service:
  image: busybox
  command: echo Hello world!
  volumes:
    - /etc/selinux:/etc/selinux`

	project, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeBytes: [][]byte{[]byte(service)},
			ProjectName:  "test-volume-without-compose-file",
		},
	})

	c.Assert(err, IsNil)

	err = project.Up()
	c.Assert(err, IsNil)
}
开发者ID:kunalkushwaha,项目名称:libcompose,代码行数:20,代码来源:api_test.go


示例17: GetProject

// GetProject returns the Docker project from the configuration
func (c *DockerCompose) GetProject() (p *project.Project, err error) {
	if _, err = os.Stat(c.ComposeFile); err == nil {
		p, err = docker.NewProject(&docker.Context{
			Context: project.Context{
				ComposeFiles: []string{c.ComposeFile},
				ProjectName:  fmt.Sprintf("parity-%s", c.pluginConfig.ProjectNameSafe),
			},
		})

		if err != nil {
			log.Error("Could not create Compose project %s", err.Error())
			return p, err
		}
	} else {
		log.Error("Could not parse compose file: %s", err.Error())
		return p, err
	}

	return p, nil
}
开发者ID:mefellows,项目名称:parity,代码行数:21,代码来源:compose.go


示例18: TestEvents

func (s *APISuite) TestEvents(c *check.C) {
	testRequires(c, not(DaemonVersionIs("1.9")))
	composeFile := `
simple:
  image: busybox:latest
  command: top
another:
  image: busybox:latest
  command: top
`
	project, err := docker.NewProject(&ctx.Context{
		Context: project.Context{
			ComposeBytes: [][]byte{[]byte(composeFile)},
			ProjectName:  "test-api-events",
		},
	}, nil)
	c.Assert(err, check.IsNil)

	ctx, cancelFun := context.WithCancel(context.Background())

	evts, err := project.Events(ctx)
	c.Assert(err, check.IsNil)

	go func() {
		c.Assert(project.Up(ctx, options.Up{}), check.IsNil)
		// Close after everything is done
		time.Sleep(250 * time.Millisecond)
		cancelFun()
		close(evts)
	}()

	actual := []events.ContainerEvent{}
	for event := range evts {
		actual = append(actual, event)
	}

	// Should be 4 events (2 create, 2 start)
	c.Assert(len(actual), check.Equals, 4, check.Commentf("%v", actual))
}
开发者ID:vdemeester,项目名称:libcompose,代码行数:39,代码来源:api_event_test.go


示例19: createComposeProject

func (s *BaseSuite) createComposeProject(c *check.C, name string) {
	composeProject, err := docker.NewProject(&docker.Context{
		Context: project.Context{
			ComposeFile: fmt.Sprintf("resources/compose/%s.yml", name),
			ProjectName: fmt.Sprintf("integration-test-%s", name),
		},
	})
	c.Assert(err, checker.IsNil)
	s.composeProject = composeProject

	s.listenChan = make(chan project.ProjectEvent)
	go s.startListening(c)

	composeProject.AddListener(s.listenChan)

	composeProject.Start()

	// FIXME Wait for compose to start
	// Waiting for libcompose#55 to be merged
	// <-s.started
	time.Sleep(2 * time.Second)

}
开发者ID:zackslash,项目名称:traefik,代码行数:23,代码来源:integration_test.go


示例20: newProject

func newProject(name string, cfg *config.CloudConfig) (*project.Project, error) {
	clientFactory, err := rosDocker.NewClientFactory(docker.ClientOpts{})
	if err != nil {
		return nil, err
	}

	serviceFactory := &rosDocker.ServiceFactory{
		Deps: map[string][]string{},
	}
	context := &docker.Context{
		ClientFactory: clientFactory,
		Context: project.Context{
			ProjectName:       name,
			EnvironmentLookup: rosDocker.NewConfigEnvironment(cfg),
			ServiceFactory:    serviceFactory,
			Rebuild:           true,
			Log:               cfg.Rancher.Log,
			LoggerFactory:     logger.NewColorLoggerFactory(),
		},
	}
	serviceFactory.Context = context

	return docker.NewProject(context)
}
开发者ID:clhudson2,项目名称:os,代码行数:24,代码来源:project.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang project.DefaultDependentServices函数代码示例发布时间:2022-05-23
下一篇:
Golang config.ServiceConfigs类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap