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


Golang Image.PutLayer方法代碼示例

本文整理匯總了Golang中github.com/containerops/wharf/models.Image.PutLayer方法的典型用法代碼示例。如果您正苦於以下問題:Golang Image.PutLayer方法的具體用法?Golang Image.PutLayer怎麽用?Golang Image.PutLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/containerops/wharf/models.Image的用法示例。


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

示例1: PutImageLayer

func (this *ImageAPIV1Controller) PutImageLayer() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	basePath := beego.AppConfig.String("docker::BasePath")
	imagePath := fmt.Sprintf("%v/images/%v", basePath, imageId)
	layerfile := fmt.Sprintf("%v/images/%v/layer", basePath, imageId)

	if !utils.IsDirExists(imagePath) {
		os.MkdirAll(imagePath, os.ModePerm)
	}

	if _, err := os.Stat(layerfile); err == nil {
		os.Remove(layerfile)
	}

	data, _ := ioutil.ReadAll(this.Ctx.Request.Body)

	if err := ioutil.WriteFile(layerfile, data, 0777); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Layer File Error", nil)
		return
	}

	if err := image.PutLayer(imageId, layerfile, true, int64(len(data))); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Layer File Data Error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	image.Log(models.ACTION_PUT_IMAGES_LAYER, models.LEVELINFORMATIONAL, models.TYPE_APIV1, image.Id, memo)

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
開發者ID:rechen,項目名稱:wharf,代碼行數:36,代碼來源:imageapiv1.go

示例2: manifestsConvertV1

func manifestsConvertV1(data []byte) error {
	var manifest map[string]interface{}
	if err := json.Unmarshal(data, &manifest); err != nil {
		return err
	}

	tag := manifest["tag"]
	namespace, repository := strings.Split(manifest["name"].(string), "/")[0], strings.Split(manifest["name"].(string), "/")[1]

	for k := len(manifest["history"].([]interface{})) - 1; k >= 0; k-- {
		v := manifest["history"].([]interface{})[k]
		compatibility := v.(map[string]interface{})["v1Compatibility"].(string)

		var image map[string]interface{}
		if err := json.Unmarshal([]byte(compatibility), &image); err != nil {
			return err
		}

		i := map[string]string{}
		r := new(models.Repository)

		if k == 0 {
			i["Tag"] = tag.(string)
		}
		i["id"] = image["id"].(string)

		//Put V1 JSON
		if err := r.PutJSONFromManifests(i, namespace, repository); err != nil {
			return err
		}

		if k == 0 {
			//Put V1 Tag
			if err := r.PutTagFromManifests(image["id"].(string), namespace, repository, tag.(string), string(data)); err != nil {
				return err
			}
		}

		img := new(models.Image)

		tarsum := manifest["fsLayers"].([]interface{})[k].(map[string]interface{})["blobSum"].(string)
		sha256 := strings.Split(tarsum, ":")[1]

		//Put Image Json
		if err := img.PutJSON(image["id"].(string), v.(map[string]interface{})["v1Compatibility"].(string), models.APIVERSION_V2); err != nil {
			return err
		}

		//Put Image Layer
		basePath := beego.AppConfig.String("docker::BasePath")
		layerfile := fmt.Sprintf("%v/uuid/%v/layer", basePath, sha256)

		if err := img.PutLayer(image["id"].(string), layerfile, true, int64(image["Size"].(float64))); err != nil {
			return err
		}

		//Put Checksum
		if err := img.PutChecksum(image["id"].(string), sha256, true, ""); err != nil {
			return err
		}

		//Put Ancestry
		if err := img.PutAncestry(image["id"].(string)); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:rechen,項目名稱:wharf,代碼行數:69,代碼來源:common.go


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