Exemple #1
0
//PushHandler push image to Clair
func PushHandler(rw http.ResponseWriter, request *http.Request) error {
	local := request.URL.Query()["local"]

	docker.IsLocal = len(local) > 0
	logrus.Debugf("Hyperclair is local: %v", docker.IsLocal)

	var image docker.Image
	if !docker.IsLocal {
		var err error
		image, err = docker.Pull(parseImageURL(request))
		if err != nil {
			return err
		}
	} else {
		var err error
		image, err = docker.Parse(parseImageURL(request))
		if err != nil {
			return err
		}
		err = docker.Prepare(&image)
		logrus.Debugf("prepared image layers: %d", len(image.FsLayers))
		if err != nil {
			return err
		}
	}

	logrus.Info("Pushing Image")
	if err := docker.Push(image); err != nil {
		return err
	}
	rw.WriteHeader(http.StatusCreated)
	return nil
}
Exemple #2
0
			if err != nil {
				if err == xerrors.NotFound {
					fmt.Println(err)
				} else {
					fmt.Println(xerrors.InternalError)
				}
				logrus.Fatalf("pulling image %q: %v", imageName, err)
			}
		} else {
			var err error
			image, err = docker.Parse(imageName)
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("parsing local image %q: %v", imageName, err)
			}
			err = docker.Prepare(&image)
			logrus.Debugf("prepared image layers: %d", len(image.FsLayers))
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("preparing local image %q from history: %v", imageName, err)
			}
		}

		logrus.Info("Pushing Image")
		if err := docker.Push(image); err != nil {
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("pushing image %q: %v", imageName, err)
			}
		}