Пример #1
0
func (cli *DogestryCli) RegularPull(image string) error {
	imageRoot, err := cli.WorkDir(image)
	if err != nil {
		return err
	}

	r, err := remote.NewRemote(cli.Config)
	if err != nil {
		return err
	}

	fmt.Printf("Using docker endpoints for pull: %v\n", cli.PullHosts)
	fmt.Printf("S3 Connection: %v\n", r.Desc())

	fmt.Printf("Image tag: %v\n", image)

	id, err := r.ResolveImageNameToId(image)
	if err != nil {
		return err
	}

	fmt.Printf("Image '%s' resolved to ID '%s'\n", image, id.Short())

	fmt.Println("Determining which images need to be downloaded from S3...")
	downloadMap, err := cli.makeDownloadMap(r, id, imageRoot)
	if err != nil {
		return err
	}

	fmt.Println("Downloading images from S3...")
	if err := cli.downloadImages(r, downloadMap, imageRoot); err != nil {
		return err
	}

	fmt.Println("Generating repositories JSON file...")
	if err := cli.createRepositoriesJsonFile(image, imageRoot, r); err != nil {
		return err
	}

	fmt.Printf("Importing image(%s) TAR file to docker hosts: %v\n", id.Short(), cli.PullHosts)
	if err := cli.sendTar(imageRoot); err != nil {
		return err
	}

	return nil
}
Пример #2
0
func (cli *DogestryCli) CmdPush(args ...string) error {
	pushFlags := cli.Subcmd("push", "REMOTE IMAGE[:TAG]", PushHelpMessage)
	if err := pushFlags.Parse(args); err != nil {
		return nil
	}

	if len(pushFlags.Args()) < 2 {
		fmt.Fprintln(cli.err, "Error: IMAGE and REMOTE not specified")
		pushFlags.Usage()
		os.Exit(2)
	}

	S3URL := pushFlags.Arg(0)
	image := pushFlags.Arg(1)

	imageRoot, err := cli.WorkDir(image)
	if err != nil {
		return err
	}

	cli.Config.SetS3URL(S3URL)

	remote, err := remote.NewRemote(cli.Config)
	if err != nil {
		return err
	}

	fmt.Printf("Using docker endpoint for push: %v\n", cli.DockerHost)
	fmt.Printf("Remote: %v\n", remote.Desc())

	if err = cli.exportToFiles(image, remote, imageRoot); err != nil {
		return err
	}

	if err := remote.Push(image, imageRoot); err != nil {
		fmt.Printf(`{"Status":"error", "Message": "%v"}`+"\n", err.Error())
		return err
	}

	fmt.Println(`{"Status":"ok"}`)
	return nil
}
Пример #3
0
func (cli *DogestryCli) CmdList(args ...string) error {
	listFlags := cli.Subcmd("list", "REMOTE", ListHelpMessage)
	if err := listFlags.Parse(args); err != nil {
		return nil
	}

	if len(listFlags.Args()) < 1 {
		fmt.Fprintln(cli.err, "Error: REMOTE not specified")
		listFlags.Usage()
		os.Exit(2)
	}

	S3URL := listFlags.Arg(0)

	w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
	defer w.Flush()

	cli.Config.SetS3URL(S3URL)

	r, err := remote.NewRemote(cli.Config)
	if err != nil {
		return err
	}

	images, err := r.List()
	if err != nil {
		return err
	}

	fmt.Fprintf(w, "REPOSITORY\tTAG\n")

	for _, i := range images {
		line := fmt.Sprintf("%s\t%s", i.Repository, i.Tag)
		fmt.Fprintln(w, line)
	}

	return nil
}
Пример #4
0
func (cli *DogestryCli) CmdPull(args ...string) error {
	pullFlags := cli.Subcmd("pull", "REMOTE IMAGE[:TAG]", PullHelpMessage)

	// Don't return error here, this part is only relevant for CLI
	if err := pullFlags.Parse(args); err != nil {
		return nil
	}

	if len(pullFlags.Args()) < 2 {
		return errors.New("Error: REMOTE and IMAGE not specified")
	}

	S3URL := pullFlags.Arg(0)
	image := pullFlags.Arg(1)

	cli.Config.SetS3URL(S3URL)

	imageRoot, err := cli.WorkDir(image)
	if err != nil {
		return err
	}

	r, err := remote.NewRemote(cli.Config)
	if err != nil {
		return err
	}

	fmt.Printf("Using docker endpoints for pull: %v\n", cli.PullHosts)
	fmt.Printf("S3 Connection: %v\n", r.Desc())

	fmt.Printf("Image tag: %v\n", image)

	id, err := r.ResolveImageNameToId(image)
	if err != nil {
		return err
	}

	fmt.Printf("Image '%s' resolved to ID '%s'\n", image, id.Short())

	fmt.Println("Determining which images need to be downloaded from S3...")
	downloadMap, err := cli.makeDownloadMap(r, id, imageRoot)
	if err != nil {
		return err
	}

	fmt.Println("Downloading images from S3...")
	if err := cli.downloadImages(r, downloadMap, imageRoot); err != nil {
		return err
	}

	fmt.Println("Generating repositories JSON file...")
	if err := cli.createRepositoriesJsonFile(image, imageRoot, r); err != nil {
		return err
	}

	fmt.Printf("Importing image(%s) TAR file to docker hosts: %v\n", id.Short(), cli.PullHosts)
	if err := cli.sendTar(imageRoot); err != nil {
		return err
	}

	return nil
}