Skip to content

Commit

Permalink
fix getArchiveTags error when using containerd
Browse files Browse the repository at this point in the history
Co-Authored-By: Akihiro Suda <suda.kyoto@gmail.com>
  • Loading branch information
ktKongTong and AkihiroSuda committed Jan 14, 2023
1 parent b357fa4 commit 2765f06
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions pkg/build/nodeimage/internal/container/docker/archive.go
Expand Up @@ -53,7 +53,7 @@ func GetArchiveTags(path string) ([]string, error) {
if err != nil {
return nil, err
}
if hdr.Name == "repositories" {
if hdr.Name == "manifest.json" || hdr.Name == "repositories" {
break
}
}
Expand All @@ -62,17 +62,25 @@ func GetArchiveTags(path string) ([]string, error) {
if err != nil {
return nil, err
}
// parse
repoTags, err := parseRepositories(b)
if err != nil {
return nil, err
}
// convert to tags in the docker CLI sense
res := []string{}
for repo, tags := range repoTags {
for tag := range tags {
res = append(res, fmt.Sprintf("%s:%s", repo, tag))
// parse
if hdr.Name == "repositories" {
repoTags, err := parseRepositories(b)
if err != nil {
return nil, err
}
// convert to tags in the docker CLI sense
for repo, tags := range repoTags {
for tag := range tags {
res = append(res, fmt.Sprintf("%s:%s", repo, tag))
}
}
} else if hdr.Name == "manifest.json" {
manifest, err := parseDockerV1Manifest(b)
if err != nil {
return nil, err
}
res = append(res, manifest[0].RepoTags...)
}
return res, nil
}
Expand Down Expand Up @@ -215,3 +223,13 @@ func parseRepositories(data []byte) (archiveRepositories, error) {
}
return repoTags, nil
}

// parseDockerV1Manifest parses Docker Image Spec v1 manifest (not OCI Image Spec manifest)
// https://github.com/moby/moby/blob/v20.10.22/image/spec/v1.2.md#combined-image-json--filesystem-changeset-format
func parseDockerV1Manifest(data []byte) ([]metadataEntry, error) {
var entries []metadataEntry
if err := json.Unmarshal(data, &entries); err != nil {
return nil, err
}
return entries, nil
}

0 comments on commit 2765f06

Please sign in to comment.