-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support cross-compiling node-image #2176
Changes from all commits
6c96945
4eafefe
207a570
1b57dbe
da28a7d
2d5eb98
229e509
c2af3b4
0a1d35d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ func GetArchiveTags(path string) ([]string, error) { | |
// https://github.com/moby/moby/blob/master/image/spec/v1.md | ||
// https://github.com/moby/moby/blob/master/image/spec/v1.1.md | ||
// https://github.com/moby/moby/blob/master/image/spec/v1.2.md | ||
func EditArchiveRepositories(reader io.Reader, writer io.Writer, editRepositories func(string) string) error { | ||
func EditArchive(reader io.Reader, writer io.Writer, editRepositories func(string) string, architectureOverride string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have to do this because kubernetes has frequently produced images with the wrong architecture metadata when cross compiling images, which prevents success importing / unning them under containerd which is actually checking for the matching image. dockerd is pretty loose with using these but does throw warnings. |
||
tarReader := tar.NewReader(reader) | ||
tarWriter := tar.NewWriter(writer) | ||
// iterate all entries in the tarball | ||
|
@@ -117,6 +117,15 @@ func EditArchiveRepositories(reader io.Reader, writer io.Writer, editRepositorie | |
return err | ||
} | ||
hdr.Size = int64(len(b)) | ||
// edit image config when we find that | ||
} else if strings.HasSuffix(hdr.Name, ".json") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is very obscure, so every json but manifest.json is an image config manifest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, they will be named we could do this, but it doesn't seem necessary. images following the spac should only contain links to the spec are in the comments above https://github.com/moby/moby/blob/master/image/spec/v1.2.md There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a typical image archive only has two .json files in it, but it's possible to create a tarball with multiple images, in which case there is one The manifest contains an array of structs each with the config file name for an image, it's tags, and it's layers. There is also the legacy repositories file for the tags. The config file specifies the non-layer data like architecture/os, entrypoint, env, etc. for one image. We are patching the architecture field to avoid kind only working on highly patched kubernetes builds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a lot of information, do you think future us can figure it out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are comments and there are links to the spec, which is not very lengthy :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if architectureOverride != "" { | ||
b, err = editConfigArchitecture(b, architectureOverride) | ||
if err != nil { | ||
return err | ||
} | ||
hdr.Size = int64(len(b)) | ||
} | ||
} | ||
|
||
// write to the output tarball | ||
|
@@ -133,6 +142,19 @@ func EditArchiveRepositories(reader io.Reader, writer io.Writer, editRepositorie | |
|
||
/* helpers */ | ||
|
||
func editConfigArchitecture(raw []byte, architectureOverride string) ([]byte, error) { | ||
var cfg map[string]interface{} | ||
if err := json.Unmarshal(raw, &cfg); err != nil { | ||
return nil, err | ||
} | ||
const architecture = "architecture" | ||
if _, ok := cfg[architecture]; !ok { | ||
return raw, nil | ||
} | ||
cfg[architecture] = architectureOverride | ||
return json.Marshal(cfg) | ||
} | ||
|
||
// archiveRepositories represents repository:tag:ref | ||
// | ||
// https://github.com/moby/moby/blob/master/image/spec/v1.md | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this always returns nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes? Because the contract is a method that returns an error type but we are only running one thing and it will error and that's fine. We check later that the images are loaded.
Ctr pull does not have the --no-unpack option unlike the option I added to import.