Skip to content

Commit

Permalink
Nydusify: ignore arch for single manifest
Browse files Browse the repository at this point in the history
For a single manifest image, we just ignore the arch, so that allowing
to do a default conversion on a different arch's host, for example
converting an arm64 image on an amd64 host.

Signed-off-by: Yan Song <imeoer@linux.alibaba.com>
  • Loading branch information
imeoer committed Apr 6, 2022
1 parent 2774e4a commit c4c7909
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion contrib/nydusify/cmd/nydusify.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func main() {
&cli.BoolFlag{Name: "prefetch-patterns", Value: false, Usage: "Prefetched file path patterns from STDIN, specify absolute/relative path of rootfs line by line", EnvVars: []string{"PREFETCH_PATTERNS"}},
&cli.StringFlag{Name: "nydus-image", Value: "nydus-image", Usage: "The nydus-image binary path, if unset, search in PATH environment", EnvVars: []string{"NYDUS_IMAGE"}},
&cli.BoolFlag{Name: "multi-platform", Value: false, Usage: "Merge OCI & Nydus manifest to manifest index for target image, please ensure that OCI manifest already exists in target image", EnvVars: []string{"MULTI_PLATFORM"}},
&cli.StringFlag{Name: "platform", Value: "linux/" + runtime.GOARCH, Usage: "Let nydusify choose image of specified platform from manifest index. Possible value is `amd64` or `arm64`"},
&cli.StringFlag{Name: "platform", Value: "linux/" + runtime.GOARCH, Usage: "Let nydusify choose image of specified platform from manifest index. Possible value is `linux/amd64` or `linux/arm64`"},
&cli.BoolFlag{Name: "docker-v2-format", Value: false, Usage: "Use docker image manifest v2, schema 2 format", EnvVars: []string{"DOCKER_V2_FORMAT"}},
&cli.StringFlag{Name: "backend-type", Value: "registry", Usage: "Specify Nydus blob storage backend type", EnvVars: []string{"BACKEND_TYPE"}},
&cli.StringFlag{Name: "backend-config", Value: "", Usage: "Specify Nydus blob storage backend in JSON config string", EnvVars: []string{"BACKEND_CONFIG"}},
Expand Down
29 changes: 22 additions & 7 deletions contrib/nydusify/pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (parser *Parser) pullIndex(ctx context.Context, desc *ocispec.Descriptor) (
}

func (parser *Parser) parseImage(
ctx context.Context, desc *ocispec.Descriptor, onlyManifest *ocispec.Manifest,
ctx context.Context, desc *ocispec.Descriptor, onlyManifest *ocispec.Manifest, ignoreArch bool,
) (*Image, error) {
var manifest *ocispec.Manifest
var err error
Expand All @@ -136,12 +136,22 @@ func (parser *Parser) parseImage(
}

if config.OS == "" || config.Architecture == "" {
return nil, errors.New("Source image configuration does not have os or architecture")
err = errors.New("Source image configuration does not have os or architecture")
if ignoreArch {
logrus.WithError(err).Warn("Ignore image arch")
} else {
return nil, err
}
}

// Just give user a simple hint telling option was ignored.
if config.Architecture != parser.interestedArch {
return nil, errors.Errorf("Specified %s architecture was not found", parser.interestedArch)
err = errors.Errorf("Found arch %s, but the specified target arch is %s", config.Architecture, parser.interestedArch)
if ignoreArch {
logrus.WithError(err).Warn("Ignore image arch, attempting to continue conversion")
} else {
return nil, err
}
}

return &Image{
Expand Down Expand Up @@ -185,6 +195,7 @@ func (parser *Parser) Parse(ctx context.Context) (*Parsed, error) {
var ociDesc *ocispec.Descriptor
var nydusDesc *ocispec.Descriptor
var onlyManifest *ocispec.Manifest
var ignoreArch bool

switch imageDesc.MediaType {
// Handle image manifest
Expand All @@ -202,6 +213,10 @@ func (parser *Parser) Parse(ctx context.Context) (*Parsed, error) {
} else {
ociDesc = imageDesc
}
// For a single manifest image, we just ignore the arch, so that allowing
// to do a default conversion on a different arch's host, for example
// converting an arm64 image on an amd64 host.
ignoreArch = true

// Handle image manifest index
case ocispec.MediaTypeImageIndex, images.MediaTypeDockerSchema2ManifestList:
Expand Down Expand Up @@ -232,16 +247,16 @@ func (parser *Parser) Parse(ctx context.Context) (*Parsed, error) {
}

if ociDesc != nil {
parsed.OCIImage, err = parser.parseImage(ctx, ociDesc, onlyManifest)
parsed.OCIImage, err = parser.parseImage(ctx, ociDesc, onlyManifest, ignoreArch)
if err != nil {
return nil, errors.Wrap(err, "parse OCI image")
return nil, errors.Wrap(err, "Parse OCI image")
}
}

if nydusDesc != nil {
parsed.NydusImage, err = parser.parseImage(ctx, nydusDesc, onlyManifest)
parsed.NydusImage, err = parser.parseImage(ctx, nydusDesc, onlyManifest, ignoreArch)
if err != nil {
return nil, errors.Wrap(err, "parse Nydus image")
return nil, errors.Wrap(err, "Parse Nydus image")
}
}

Expand Down

0 comments on commit c4c7909

Please sign in to comment.