Пример #1
0
func pullImage(client *dockerclient.Client, service *Service, image string) error {
	taglessRemote, tag := parsers.ParseRepositoryTag(image)
	if tag == "" {
		image = utils.ImageReference(taglessRemote, DefaultTag)
	}

	repoInfo, err := registry.ParseRepositoryInfo(taglessRemote)
	if err != nil {
		return err
	}

	authConfig := cliconfig.AuthConfig{}
	if service.context.ConfigFile != nil && repoInfo != nil && repoInfo.Index != nil {
		authConfig = registry.ResolveAuthConfig(service.context.ConfigFile, repoInfo.Index)
	}

	err = client.PullImage(
		dockerclient.PullImageOptions{
			Repository:   image,
			OutputStream: os.Stderr, // TODO maybe get the stream from some configured place
		},
		dockerclient.AuthConfiguration{
			Username: authConfig.Username,
			Password: authConfig.Password,
			Email:    authConfig.Email,
		},
	)

	if err != nil {
		logrus.Errorf("Failed to pull image %s: %v", image, err)
	}

	return err
}
Пример #2
0
// pullImage pulls the inspected image using the given client.
// It will try to use all the given authentication methods and will fail
// only if all of them failed.
func (i *defaultImageInspector) pullImage(client *docker.Client) error {
	log.Printf("Pulling image %s", i.opts.Image)

	var imagePullAuths *docker.AuthConfigurations
	var authCfgErr error
	if imagePullAuths, authCfgErr = i.getAuthConfigs(); authCfgErr != nil {
		return authCfgErr
	}

	reader, writer := io.Pipe()
	// handle closing the reader/writer in the method that creates them
	defer writer.Close()
	defer reader.Close()
	imagePullOption := docker.PullImageOptions{
		Repository:    i.opts.Image,
		OutputStream:  writer,
		RawJSONStream: true,
	}

	bytesChan := make(chan int)
	go aggregateBytesAndReport(bytesChan)
	go decodeDockerPullMessages(bytesChan, reader)

	// Try all the possible auth's from the config file
	var authErr error
	for name, auth := range imagePullAuths.Configs {
		if authErr = client.PullImage(imagePullOption, auth); authErr == nil {
			return nil
		}
		log.Printf("Authentication with %s failed: %v", name, authErr)
	}
	return fmt.Errorf("Unable to pull docker image: %v\n", authErr)
}
Пример #3
0
func pullImages(client *dockerapi.Client, images []string) error {
	for _, image := range images {
		err := client.PullImage(dockerapi.PullImageOptions{
			Repository: image,
		}, dockerapi.AuthConfiguration{})
		if err != nil {
			return err
		}
	}

	return nil
}
func pullImage(data *Data, client *dc.Client, image string) error {
	// TODO: Test local registry handling. It should be working
	// based on the code that was ported over

	pullOpts := parseImageOptions(image)
	auth := dc.AuthConfiguration{}

	if err := client.PullImage(pullOpts, auth); err != nil {
		return fmt.Errorf("Error pulling image %s: %s\n", image, err)
	}

	return fetchLocalImages(data, client)
}
Пример #5
0
// pullImage creates an image by pulling it from a docker registry
func (d *DockerDriver) pullImage(driverConfig *DockerDriverConfig, client *docker.Client, repo string, tag string) error {
	pullOptions := docker.PullImageOptions{
		Repository: repo,
		Tag:        tag,
	}

	authOptions := docker.AuthConfiguration{}
	if len(driverConfig.Auth) != 0 {
		authOptions = docker.AuthConfiguration{
			Username:      driverConfig.Auth[0].Username,
			Password:      driverConfig.Auth[0].Password,
			Email:         driverConfig.Auth[0].Email,
			ServerAddress: driverConfig.Auth[0].ServerAddress,
		}
	}

	if authConfigFile := d.config.Read("docker.auth.config"); authConfigFile != "" {
		if f, err := os.Open(authConfigFile); err == nil {
			defer f.Close()
			var authConfigurations *docker.AuthConfigurations
			if authConfigurations, err = docker.NewAuthConfigurations(f); err != nil {
				return fmt.Errorf("Failed to create docker auth object: %v", err)
			}

			authConfigurationKey := ""
			if driverConfig.SSL {
				authConfigurationKey += "https://"
			}

			authConfigurationKey += strings.Split(driverConfig.ImageName, "/")[0]
			if authConfiguration, ok := authConfigurations.Configs[authConfigurationKey]; ok {
				authOptions = authConfiguration
			} else {
				d.logger.Printf("[INFO] Failed to find docker auth with key %s", authConfigurationKey)
			}
		} else {
			return fmt.Errorf("Failed to open auth config file: %v, error: %v", authConfigFile, err)
		}
	}

	err := client.PullImage(pullOptions, authOptions)
	if err != nil {
		d.logger.Printf("[ERR] driver.docker: failed pulling container %s:%s: %s", repo, tag, err)
		return d.recoverablePullError(err, driverConfig.ImageName)
	}
	d.logger.Printf("[DEBUG] driver.docker: docker pull %s:%s succeeded", repo, tag)
	return nil
}
Пример #6
0
func PullImage(client *docker.Client, image, username, password, email string) error {
	opts := docker.PullImageOptions{
		Repository: image,
		//OutputStream: os.Stdout,
	}

	auth := docker.AuthConfiguration{
		Username: username,
		Password: password,
		Email:    email,
	}

	if err := client.PullImage(opts, auth); err != nil {
		return err
	}

	return nil
}
func pullImage(data *Data, client *dc.Client, image string) error {
	// TODO: Test local registry handling. It should be working
	// based on the code that was ported over

	pullOpts := dc.PullImageOptions{}

	splitImageName := strings.Split(image, ":")
	switch len(splitImageName) {

	// It's in registry:port/username/repo:tag or registry:port/repo:tag format
	case 3:
		splitPortRepo := strings.Split(splitImageName[1], "/")
		pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
		pullOpts.Tag = splitImageName[2]
		pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")

	// It's either registry:port/username/repo, registry:port/repo,
	// or repo:tag with default registry
	case 2:
		splitPortRepo := strings.Split(splitImageName[1], "/")
		switch len(splitPortRepo) {
		// repo:tag
		case 1:
			pullOpts.Repository = splitImageName[0]
			pullOpts.Tag = splitImageName[1]

		// registry:port/username/repo or registry:port/repo
		default:
			pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
			pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")
			pullOpts.Tag = "latest"
		}

	// Plain username/repo or repo
	default:
		pullOpts.Repository = image
	}

	if err := client.PullImage(pullOpts, dc.AuthConfiguration{}); err != nil {
		return fmt.Errorf("Error pulling image %s: %s\n", image, err)
	}

	return fetchLocalImages(data, client)
}
Пример #8
0
func pullImage(name string, client *docker.Client) error {
	chunks := strings.Split(name, ":")

	imgName := chunks[0]
	imgTag := "latest"

	if len(chunks) == 2 {
		imgTag = chunks[1]
	}

	auth := docker.AuthConfiguration{}
	opts := docker.PullImageOptions{
		Repository:   imgName,
		Tag:          imgTag,
		OutputStream: os.Stdout,
	}

	return client.PullImage(opts, auth)
}