Beispiel #1
0
// fetchImageByURL will try fetch an image using an URL.
func (f *fetcher) fetchImageByURL(u *url.URL, ascFile *os.File) (string, error) {
	// Always fetch if it's a file
	if u.Scheme == "file" {
		stderr("rkt: using image from file %s", u.Path)
		return f.fetchImageFromURL(u.String(), u.Scheme, ascFile, false)
	}

	// check the store
	if !f.noStore {
		rem, ok, err := f.s.GetRemote(u.String())
		if err != nil {
			return "", err
		}
		if ok {
			stderr("rkt: using image from local store for url %s", u.String())
			return rem.BlobKey, nil
		}
	}

	// do remote fetching
	if !f.storeOnly {
		latest := false
		if u.Scheme == "docker" {
			dockerURL := common.ParseDockerURL(path.Join(u.Host, u.Path))
			if dockerURL.Tag == "latest" {
				latest = true
			}
		}
		stderr("rkt: remote fetching from url %s", u.String())
		return f.fetchImageFromURL(u.String(), u.Scheme, ascFile, latest)
	}

	return "", fmt.Errorf("unable to fetch image for url %s", u.String())
}
Beispiel #2
0
func (lb *FileBackend) GetImageInfo(dockerURL string) ([]string, *types.ParsedDockerURL, error) {
	parsedDockerURL := common.ParseDockerURL(dockerURL)

	appImageID, parsedDockerURL, err := getImageID(lb.file, parsedDockerURL)
	if err != nil {
		return nil, nil, fmt.Errorf("error getting ImageID: %v", err)
	}

	ancestry, err := getAncestry(lb.file, appImageID)
	if err != nil {
		return nil, nil, fmt.Errorf("error getting ancestry: %v", err)
	}

	return ancestry, parsedDockerURL, nil
}
Beispiel #3
0
func (rb *RepositoryBackend) GetImageInfo(url string) ([]string, *types.ParsedDockerURL, error) {
	dockerURL := common.ParseDockerURL(url)

	var supportsV2, ok bool
	if supportsV2, ok = rb.hostsV2Support[dockerURL.IndexURL]; !ok {
		var err error
		supportsV2, err = rb.supportsV2(dockerURL.IndexURL)
		if err != nil {
			return nil, nil, err
		}
		rb.hostsV2Support[dockerURL.IndexURL] = supportsV2
	}

	if supportsV2 {
		return rb.getImageInfoV2(dockerURL)
	} else {
		return rb.getImageInfoV1(dockerURL)
	}
}
Beispiel #4
0
func (rb *RepositoryBackend) GetImageInfo(url string) ([]string, *types.ParsedDockerURL, error) {
	dockerURL := common.ParseDockerURL(url)
	repoData, err := rb.getRepoData(dockerURL.IndexURL, dockerURL.ImageName)
	if err != nil {
		return nil, nil, fmt.Errorf("error getting repository data: %v", err)
	}

	// TODO(iaguis) check more endpoints
	appImageID, err := getImageIDFromTag(repoData.Endpoints[0], dockerURL.ImageName, dockerURL.Tag, repoData)
	if err != nil {
		return nil, nil, fmt.Errorf("error getting ImageID from tag %s: %v", dockerURL.Tag, err)
	}

	ancestry, err := getAncestry(appImageID, repoData.Endpoints[0], repoData)
	if err != nil {
		return nil, nil, err
	}

	rb.repoData = repoData

	return ancestry, dockerURL, nil
}
Beispiel #5
0
// fetchSingleImage will take an image as either a URL or a name string and
// import it into the store if found.  If discover is true meta-discovery is
// enabled.  If asc is not "", it must exist as a local file and will be used
// as the signature file for verification, unless verification is disabled.
func (f *fetcher) fetchSingleImage(img string, asc string, discover bool) (string, error) {
	var (
		ascFile *os.File
		err     error
		latest  bool
	)
	if asc != "" && f.ks != nil {
		ascFile, err = os.Open(asc)
		if err != nil {
			return "", fmt.Errorf("unable to open signature file: %v", err)
		}
		defer ascFile.Close()
	}

	u, err := url.Parse(img)
	if err != nil {
		return "", fmt.Errorf("not a valid image reference (%s)", img)
	}

	// if img refers to a local file, ensure the scheme is file:// and make the url path absolute
	_, err = os.Stat(u.Path)
	if err == nil {
		u.Path, err = filepath.Abs(u.Path)
		if err != nil {
			return "", fmt.Errorf("unable to get abs path: %v", err)
		}
		u.Scheme = "file"
	} else if !os.IsNotExist(err) {
		return "", fmt.Errorf("unable to access %q: %v", img, err)
	}

	if discover && u.Scheme == "" {
		if app := newDiscoveryApp(img); app != nil {
			var discoveryError error
			if !f.local {
				stderr("rkt: searching for app image %s", img)
				ep, err := discoverApp(app, true)
				if err != nil {
					discoveryError = err
				} else {
					// No specified version label, mark it as latest
					if _, ok := app.Labels["version"]; !ok {
						latest = true
					}
					return f.fetchImageFromEndpoints(app.Name.String(), ep, ascFile, latest)
				}
			}
			if discoveryError != nil {
				stderr("discovery failed for %q: %v. Trying to find image in the store.", img, discoveryError)
			}
			if f.local || discoveryError != nil {
				return f.fetchImageFromStore(img)
			}
		}
	}

	switch u.Scheme {
	case "http", "https", "file":
	case "docker":
		dockerURL := common.ParseDockerURL(path.Join(u.Host, u.Path))
		if dockerURL.Tag == "latest" {
			latest = true
		}
	default:
		return "", fmt.Errorf("rkt only supports http, https, docker or file URLs (%s)", img)
	}
	return f.fetchImageFromURL(u.String(), u.Scheme, ascFile, latest)
}
Beispiel #6
0
// GetHash uses docker2aci to download the image and convert it to
// ACI, then stores it in the store and returns the hash.
func (f *dockerFetcher) GetHash(u *url.URL) (string, error) {
	dockerURL := d2acommon.ParseDockerURL(path.Join(u.Host, u.Path))
	latest := dockerURL.Tag == "latest"
	return f.fetchImageFrom(u, latest)
}