8000 rkt: Implement distribution points by s-urbaniak · Pull Request #3369 · rkt/rkt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

rkt: Implement distribution points #3369

Merged
merged 8 commits into from
Nov 22, 2016
Merged

rkt: Implement distribution points #3369

merged 8 commits into from
Nov 22, 2016

Conversation

s-urbaniak
Copy link
Contributor

This is the implementation of the distribution concept proposed in #2953.

Supersedes #3101

This is work in progress to check the output of CI.

Copy link
Contributor Author
@s-urbaniak s-urbaniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are notes to myself

8000
}

// NewACIArchive creates a new aci-archive distribution from the provided distribution uri
// string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/string//

return nil, fmt.Errorf("cannot parse URI: %q: %v", u.String(), err)
}
if c.Type != TypeACIArchive {
return nil, fmt.Errorf("wrong distribution type: %q", c.Type)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/wrong/illegal

// This should be a valid URL
data, err := url.QueryUnescape(c.Data)
if err != nil {
return nil, fmt.Errorf("wrong archive transport url %q: %v", c.Data, err)
8000 Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/wrong/illegal

}
aciu, err := url.Parse(data)
if err != nil {
return nil, fmt.Errorf("wrong archive transport url %q: %v", c.Data, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/wrong/illegal


str := u.String()

path := aciu.String()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superfluous newlines


// SimpleDockerString returns a simplyfied docker cimd. This means removing
// the index url if it's the default docker registry (registry-1.docker.io),
// removing the default repo (library) when using the default docker registry
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct this doc, we are not returning a cimd


// FullDockerCIMD return the docker cimd populated with all the default values
// docker strings like "busybox" or
// "registry-1.docker.io/library/busybox:latest" will become the same docker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct this doc, we are not returning a cimd

func DistFromImageString(is string) (dist.Distribution, error) {
u, err := url.Parse(is)
if err != nil {
errwrap.Wrap(fmt.Errorf("failed to parse image string %q", is), err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failed to parse image string %q as url

// FetchImage will take an image as either a path, a URL or a name
// string and import it into the store if found. If ascPath is not "",
// it must exist as a local file and will be used as the signature
// file for verification, unless verification is disabled. If
// f.WithDeps is true also image dependencies are fetched.
func (f *Fetcher) FetchImage(img string, ascPath string, imgType apps.AppImageType) (string, error) {
func (f *Fetcher) FetchImage(d dist.Distribution, str, ascPath string) (*types.Hash, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name str is too ambiguous

h, err := types.NewHash(hash)
if err != nil {
// should never happen
log.PanicE("got an invalid hash, looks like it is corrupted", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"invalid hash"

@s-urbaniak s-urbaniak force-pushed the pr-3101 branch 4 times, most recently from 33685a8 to d4542e5 Compare November 14, 2016 12:43
}, nil
}

// NewCIMDString creates a new cimd URL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewCIMDString creates a new cimd URL string.

// Distribution is the interface that represents a distribution point.
type Distribution interface {
// URI returns a copy of the Distribution CIMD URI.
URI() *url.URL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply call this CIMD()?

@@ -218,9 +218,15 @@ func DistFromImageString(is string) (dist.Distribution, error) {
return nil, fmt.Errorf("docker distribution creation error: %v", err)
}
return dist, nil
default:
// Try to create a dist directly from the provided URI
case "cimd":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference the cimd schme constant directly

@s-urbaniak s-urbaniak changed the title [WIP] rkt: Implement distribution points rkt: Implement distribution points Nov 16, 2016
@s-urbaniak s-urbaniak force-pushed the pr-3101 branch 2 times, most recently from 519b311 to 3bd8afa Compare November 16, 2016 09:57
@@ -79,12 +112,17 @@ func (f *Fetcher) getAsc(ascPath string) *asc {
// fetchImageDeps will recursively fetch all the image dependencies
func (f *Fetcher) fetchImageDeps(hash string) error {
imgsl := list.New()
seen := map[string]struct{}{}
seen := map[dist.Distribution]struct{}{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems very dangerous to me as it is very easy to miss the equality invariant of the underlying dynamic type. I'd rather make this map[string]dist.Distrbution, where the key is the string representation of the cimd URL.

@s-urbaniak
Copy link
Contributor Author

@lucab PTAL

// dependencies is correct since it may break noarch dependencies. Reference:
// https://github.com/coreos/rkt/pull/2317
func (db *distBundle) setAppDefaults() error {
app := db.dist.(*dist.Appc 9E88 ).App()
if _, ok := app.Labels["arch"]; !ok {
app.Labels["arch"] = runtime.GOARCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: this will need to be adjusted following appc/spec#668.

Copy link
Member
@lucab lucab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments inline.

import (
"sort"

"github.com/appc/spec/schema/types"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is something appc-specific, should we somehow label this to make it more explicit (and perhaps move to appc/spec at some point in the future)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed OOB: This is indeed appc-specific, and makes sense to move to appc/spec itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I'm fine to have it here for the moment to avoid a tag-and-sync delay, just leave a TODO note at the top for the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return Get(u)
}

// from github.com/PuerkitoBio/purell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the relevant license (BSD-3) to the header here, as well as the author. And this comment would better reference the exact file and version we took this from, for future-proof inspection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I'll simply import the library, it is small, and we will have a direct dependency. Since sortQuery modifies the given url in-place using purell.NormalizeURL will work.

func DistFromImageString(is string) (dist.Distribution, error) {
u, err := url.Parse(is)
if err != nil {
errwrap.Wrap(fmt.Errorf("failed to parse image url %q", is), err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return.

for _, l := range ls {
out = append(out, fmt.Sprintf("%q:%q", l.Name, l.Value))
}
return "[" + strings.Join(out, ", ") + "]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look too nice, and seems to used exactly once in the code for error-printing. Should we get rid of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, the error format can refer directly to the %q fmt qualifier which will print i.e. [{"version" "1.0"} {"os" "linux"}] ..., so there is no need for this function.

@s-urbaniak s-urbaniak force-pushed the pr-3101 branch 2 times, most recently from c70c6e7 to 0382834 Compare November 21, 2016 09:35
@lucab
Copy link
Member
lucab commented Nov 21, 2016

This LGTM, but CI looks very confused here. Perhaps @s-urbaniak could re-trigger it later.

s-urbaniak and others added 8 commits November 21, 2016 19:48
Currently glide errors out because some dependencies could not be found:

[ERROR] Error scanning google.golang.org/grpc/stats: open
/home/sur/.glide/cache/src/https-google.golang.org-grpc/stats: no such
file or directory
[ERROR] This error means the referenced package was not found.
[ERROR] Missing file or directory errors usually occur when multiple
packages
[ERROR] share a common dependency and the first reference encountered by
the scanner
[ERROR] sets the version to one that does not contain a subpackage
needed required
[ERROR] by another package that uses the shared dependency. Try setting
a
[ERROR] version in your glide.yaml that works for all packages that
share this
[ERROR] dependency.
[ERROR] Error scanning google.golang.org/grpc/tap: open
/home/sur/.glide/cache/src/https-google.golang.org-grpc/tap: no such
file or directory
...

This fixes it by introducing them manually.
This removes the `-u` parameter suggestion for `glide get` since it is
the default now.
This patch implements the distribution point concept with the three initial
kind of distributions already used by rkt (appc, aci-archive, docker).

It just makes the smallest required changes to the fetchers logic to make them
work and pass the functional tests.

This is the base for future fetchers (a future patch will refactor the
fetcher logic to better fit the distribution concept) and store refactors.
Currently if the user specifies an app name like "app-name:v1.0" it
won't be recognized because "app-name" is treated like an unknown URL
scheme.

This fixes it by assuming that unknown URL schemes imply appc images.

Fixes rkt#3326
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0