當前位置: 首頁>>代碼示例>>Golang>>正文


Golang project.Service類代碼示例

本文整理匯總了Golang中github.com/docker/libcompose/project.Service的典型用法代碼示例。如果您正苦於以下問題:Golang Service類的具體用法?Golang Service怎麽用?Golang Service使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Service類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Build

// Build implements Builder. It consumes the docker build API endpoint and sends
// a tar of the specified service build context.
func (d *DaemonBuilder) Build(p *project.Project, service project.Service) (string, error) {
	if service.Config().Build == "" {
		return service.Config().Image, nil
	}

	tag := fmt.Sprintf("%s_%s", p.Name, service.Name())
	context, err := CreateTar(p, service.Name())
	if err != nil {
		return "", err
	}

	defer context.Close()

	client := d.context.ClientFactory.Create(service)

	logrus.Infof("Building %s...", tag)

	err = client.BuildImage(dockerclient.BuildImageOptions{
		InputStream:    context,
		OutputStream:   os.Stdout,
		RawJSONStream:  false,
		Name:           tag,
		RmTmpContainer: true,
		Dockerfile:     service.Config().Dockerfile,
		NoCache:        d.context.NoCache,
	})

	if err != nil {
		return "", err
	}

	return tag, nil
}
開發者ID:schmunk42,項目名稱:libcompose,代碼行數:35,代碼來源:builder.go

示例2: DefaultDependentServices

// DefaultDependentServices return the dependent services (as an array of ServiceRelationship)
// for the specified project and service. It looks for : links, volumesFrom, net and ipc configuration.
// It uses default project implementation and append some docker specific ones.
func DefaultDependentServices(p *project.Project, s project.Service) []project.ServiceRelationship {
	result := project.DefaultDependentServices(p, s)

	result = appendNs(p, result, s.Config().NetworkMode, project.RelTypeNetNamespace)
	result = appendNs(p, result, s.Config().Ipc, project.RelTypeIpcNamespace)

	return result
}
開發者ID:vdemeester,項目名稱:rancher-compose,代碼行數:11,代碼來源:utils.go

示例3: Create

func (c *ClientFactory) Create(service project.Service) dockerclient.APIClient {
	if IsSystemContainer(service.Config()) {
		waitFor(&c.systemOnce, c.systemClient, config.DOCKER_SYSTEM_HOST)
		return c.systemClient
	}

	waitFor(&c.userOnce, c.userClient, config.DOCKER_HOST)
	return c.userClient
}
開發者ID:coderjoe,項目名稱:os,代碼行數:9,代碼來源:client_factory.go

示例4: Build

// Build implements Builder. It consumes the docker build API endpoint and sends
// a tar of the specified service build context.
func (d *DaemonBuilder) Build(p *project.Project, service project.Service) (string, error) {
	if service.Config().Build == "" {
		return service.Config().Image, nil
	}

	tag := fmt.Sprintf("%s_%s", p.Name, service.Name())
	context, err := CreateTar(p, service.Name())
	if err != nil {
		return "", err
	}

	defer context.Close()

	client := d.context.ClientFactory.Create(service)

	logrus.Infof("Building %s...", tag)
	output, err := client.BuildImage(&dockerclient.BuildImage{
		Context:        context,
		RepoName:       tag,
		Remove:         true,
		DockerfileName: service.Config().Dockerfile,
	})
	if err != nil {
		return "", err
	}

	defer output.Close()

	// Don't really care about errors in the scanner
	scanner := bufio.NewScanner(output)
	for scanner.Scan() {
		text := scanner.Text()
		data := map[string]interface{}{}
		err := json.Unmarshal([]byte(text), &data)
		if stream, ok := data["stream"]; ok && err == nil {
			fmt.Print(stream)
		}
	}

	return tag, nil
}
開發者ID:alena1108,項目名稱:rancher-compose-executor,代碼行數:43,代碼來源:builder.go

示例5: Build

// Build implements Builder. It consumes the docker build API endpoint and sends
// a tar of the specified service build context.
func (d *DaemonBuilder) Build(imageName string, p *project.Project, service project.Service) error {
	if service.Config().Build == "" {
		return fmt.Errorf("Specified service does not have a build section")
	}

	context, err := CreateTar(p, service.Name())
	if err != nil {
		return err
	}

	defer context.Close()

	client := d.context.ClientFactory.Create(service)

	logrus.Infof("Building %s...", imageName)

	return client.BuildImage(dockerclient.BuildImageOptions{
		InputStream:    context,
		OutputStream:   os.Stdout,
		RawJSONStream:  false,
		Name:           imageName,
		RmTmpContainer: true,
		Dockerfile:     service.Config().Dockerfile,
		NoCache:        d.context.NoCache,
	})
}
開發者ID:aanand,項目名稱:libcompose,代碼行數:28,代碼來源:builder.go

示例6: Build

// Build implements Builder. It consumes the docker build API endpoint and sends
// a tar of the specified service build context.
func (d *DaemonBuilder) Build(imageName string, p *project.Project, service project.Service) error {
	if service.Config().Build == "" {
		return fmt.Errorf("Specified service does not have a build section")
	}

	ctx, err := CreateTar(p, service.Name())
	if err != nil {
		return err
	}
	defer ctx.Close()

	var progBuff io.Writer = os.Stdout
	var buildBuff io.Writer = os.Stdout

	// Setup an upload progress bar
	progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(progBuff, true)

	var body io.Reader = progress.NewProgressReader(ctx, progressOutput, 0, "", "Sending build context to Docker daemon")

	client := d.context.ClientFactory.Create(service)

	logrus.Infof("Building %s...", imageName)

	outFd, isTerminalOut := term.GetFdInfo(os.Stdout)

	response, err := client.ImageBuild(context.Background(), types.ImageBuildOptions{
		Context:     body,
		Tags:        []string{imageName},
		NoCache:     d.context.NoCache,
		Remove:      true,
		Dockerfile:  service.Config().Dockerfile,
		AuthConfigs: d.context.ConfigFile.AuthConfigs,
	})

	err = jsonmessage.DisplayJSONMessagesStream(response.Body, buildBuff, outFd, isTerminalOut, nil)
	if err != nil {
		if jerr, ok := err.(*jsonmessage.JSONError); ok {
			// If no error code is set, default to 1
			if jerr.Code == 0 {
				jerr.Code = 1
			}
			fmt.Fprintf(os.Stderr, "%s%s", progBuff, buildBuff)
			return fmt.Errorf("Status: %s, Code: %d", jerr.Message, jerr.Code)
		}
	}
	return err
}
開發者ID:datawolf,項目名稱:libcompose,代碼行數:49,代碼來源:builder.go


注:本文中的github.com/docker/libcompose/project.Service類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。