示例#1
0
文件: blobapiv2.go 项目: rechen/wharf
func (this *BlobAPIV2Controller) PutBlobs() {
	var digest string

	this.Ctx.Input.Bind(&digest, "digest")

	basePath := beego.AppConfig.String("docker::BasePath")
	imagePath := fmt.Sprintf("%v/uuid/%v", basePath, strings.Split(digest, ":")[1])
	layerfile := fmt.Sprintf("%v/uuid/%v/layer", basePath, strings.Split(digest, ":")[1])

	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, "", map[string][]modules.ErrorDescriptor{"errors": []modules.ErrorDescriptor{modules.ErrorDescriptors[modules.APIErrorCodeBlobUploadUnknown]}})
		return
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusCreated)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
示例#2
0
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
}