Beispiel #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
}
Beispiel #2
0
			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)
			}
		}

		fmt.Printf("%v has been pushed to Clair\n", imageName)

	},
}

func init() {
	RootCmd.AddCommand(pushCmd)
	pushCmd.Flags().BoolVarP(&docker.IsLocal, "local", "l", false, "Use local images")
}