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


Golang Job.SetenvBool方法代码示例

本文整理汇总了Golang中github.com/docker/docker/engine.Job.SetenvBool方法的典型用法代码示例。如果您正苦于以下问题:Golang Job.SetenvBool方法的具体用法?Golang Job.SetenvBool怎么用?Golang Job.SetenvBool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/docker/docker/engine.Job的用法示例。


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

示例1: postImagesCreate

// Creates an image from Pull or from Import
func postImagesCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	if err := parseForm(r); err != nil {
		return err
	}

	var (
		image = r.Form.Get("fromImage")
		repo  = r.Form.Get("repo")
		tag   = r.Form.Get("tag")
		job   *engine.Job
	)
	authEncoded := r.Header.Get("X-Registry-Auth")
	authConfig := &registry.AuthConfig{}
	if authEncoded != "" {
		authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
		if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
			// for a pull it is not an error if no auth was given
			// to increase compatibility with the existing api it is defaulting to be empty
			authConfig = &registry.AuthConfig{}
		}
	}
	if image != "" { //pull
		if tag == "" {
			image, tag = parsers.ParseRepositoryTag(image)
		}
		metaHeaders := map[string][]string{}
		for k, v := range r.Header {
			if strings.HasPrefix(k, "X-Meta-") {
				metaHeaders[k] = v
			}
		}
		job = eng.Job("pull", image, tag)
		job.SetenvBool("parallel", version.GreaterThan("1.3"))
		job.SetenvJson("metaHeaders", metaHeaders)
		job.SetenvJson("authConfig", authConfig)
	} else { //import
		if tag == "" {
			repo, tag = parsers.ParseRepositoryTag(repo)
		}
		job = eng.Job("import", r.Form.Get("fromSrc"), repo, tag)
		job.Stdin.Add(r.Body)
		job.SetenvList("changes", r.Form["changes"])
	}

	if version.GreaterThan("1.0") {
		job.SetenvBool("json", true)
		streamJSON(job, w, true)
	} else {
		job.Stdout.Add(utils.NewWriteFlusher(w))
	}
	if err := job.Run(); err != nil {
		if !job.Stdout.Used() {
			return err
		}
		sf := utils.NewStreamFormatter(version.GreaterThan("1.0"))
		w.Write(sf.FormatError(err))
	}

	return nil
}
开发者ID:pombredanne,项目名称:docker,代码行数:61,代码来源:server.go

示例2: ContainerStart

func ContainerStart(job *engine.Job) engine.Status {
	hostConfig := runconfig.ContainerHostConfigFromJob(job)
	if len(job.Args) != 1 {
		return job.Errorf("Usage: %s CONTAINER\n", job.Name)
	}
	var (
		name = job.Args[0]
	)

	v := url.Values{}

	if job.EnvExists("t") {
		v.Set("t", strconv.Itoa(job.GetenvInt("t")))
	}

	job.SetenvBool("all", true)

	ship := shipWithContainerId(job, name)

	cli := client.NewKraneClientApi(*ship, false, job)

	if ship != nil {
		body, statusCode, err := cli.Call("POST", "/containers/"+name+"/start?"+v.Encode(), hostConfig, false)
		if statusCode == 304 {
			return job.Errorf("Container already started")
		} else if statusCode == 404 {
			return job.Errorf("No such container: %s\n", name)
		} else if statusCode == 404 {
			return job.Errorf("Cannot start container %s: %s\n", name, err)
		} else if (statusCode >= 200) && (statusCode < 300) {
			fmt.Printf("%s", body)
		} else {
			return job.Errorf("Cannot start container %s: %s\n", name, err)
		}
	} else {
		return job.Errorf("No such container: %s\n", name)
	}

	return engine.StatusOK
}
开发者ID:nikolayvoronchikhin,项目名称:krane,代码行数:40,代码来源:container.go


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