Beispiel #1
0
func (this *ImageAPIV1Controller) PutChecksum() {
	imageId := string(this.Ctx.Input.Param(":image_id"))

	image := new(models.Image)

	checksum := strings.Split(this.Ctx.Input.Header("X-Docker-Checksum"), ":")[1]
	payload := strings.Split(this.Ctx.Input.Header("X-Docker-Checksum-Payload"), ":")[1]

	if err := image.PutChecksum(imageId, checksum, true, payload); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Checksum & Payload Error", nil)
		return
	}

	if err := image.PutAncestry(imageId); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image Ancestry Error", nil)
		return
	}

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

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
Beispiel #2
0
func (this *ImageAPIV1Controller) PutImageJSON() {
	imageId := this.Ctx.Input.Param(":image_id")

	image := new(models.Image)

	j := string(this.Ctx.Input.CopyBody())

	if err := image.PutJSON(imageId, j, models.APIVERSION_V1); err != nil {
		this.JSONOut(http.StatusBadRequest, "Put Image JSON Error", nil)
		return
	}

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

	this.Ctx.Output.Context.Output.SetStatus(http.StatusOK)
	this.Ctx.Output.Context.Output.Body([]byte(""))
	return
}
Beispiel #3
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
}