Skip to content

Commit

Permalink
WIP support multiple different images
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Aug 1, 2020
1 parent 5697640 commit 5a67f7f
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions docker/internal/tarfile/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,51 @@ func (w *Writer) addLegacyTags(lastLayerID string, repoTags []reference.NamedTag
}
}

// checkManifestItemsMatch checks that a and b describe the same image,
// and returns an error if that’s not the case (which should never happen).
func checkManifestItemsMatch(a, b *ManifestItem) error {
if a.Config != b.Config {
return fmt.Errorf("Internal error: Trying to reuse ManifestItem values with configs %#v vs. %#v", a.Config, b.Config)
}
if len(a.Layers) != len(b.Layers) {
return fmt.Errorf("Internal error: Trying to reuse ManifestItem values with layers %#v vs. %#v", a.Layers, b.Layers)
}
for i := range a.Layers {
if a.Layers[i] != b.Layers[i] {
return fmt.Errorf("Internal error: Trying to reuse ManifestItem values with layers[i] %#v vs. %#v", a.Layers[i], b.Layers[i])
}
}
// Ignore RepoTags, that will be built later.
// Ignore Parent and LayerSources, which we don’t set to anything meaningful.
return nil
}

// addManifestTags records that repoTags point to (configPath, layerPaths)
func (w *Writer) addManifestTags(configPath string, layerPaths []string, repoTags []reference.NamedTagged) error {
var item *ManifestItem
newItem := ManifestItem{
Config: configPath,
RepoTags: []string{},
Layers: layerPaths,
Parent: "", // We don’t have this information
LayerSources: nil,
}
if i, ok := w.manifestByConfig[configPath]; ok {
// FIXME: compare Layers array
item = &w.manifest[i]
if err := checkManifestItemsMatch(item, &newItem); err != nil {
return err
}
} else {
i := len(w.manifest)
w.manifest = append(w.manifest, ManifestItem{
Config: configPath,
RepoTags: []string{},
Layers: layerPaths,
Parent: "",
LayerSources: nil,
})
w.manifestByConfig[configPath] = i
w.manifest = append(w.manifest, newItem)
item = &w.manifest[i]
}

knownRepoTags := map[string]struct{}{}
for _, repoTag := range item.RepoTags {
knownRepoTags[repoTag] = struct{}{}
}
for _, tag := range repoTags {
// For github.com/docker/docker consumers, this works just as well as
// refString := ref.String()
Expand All @@ -179,8 +206,11 @@ func (w *Writer) addManifestTags(configPath string, layerPaths []string, repoTag
// See https://github.com/containers/image/issues/72 for a more detailed
// analysis and explanation.
refString := fmt.Sprintf("%s:%s", tag.Name(), tag.Tag())
// FIXME: Only if it does not already exist?
item.RepoTags = append(item.RepoTags, refString)

if _, ok := knownRepoTags[refString]; !ok {
item.RepoTags = append(item.RepoTags, refString)
knownRepoTags[refString] = struct{}{}
}
}

return nil
Expand Down

0 comments on commit 5a67f7f

Please sign in to comment.