本文整理汇总了Golang中github.com/docker/libcompose/docker.NewProject函数的典型用法代码示例。如果您正苦于以下问题:Golang NewProject函数的具体用法?Golang NewProject怎么用?Golang NewProject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewProject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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()
}
示例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,
})
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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)
}
示例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)
}
}