Skip to content

Commit f4f7763

Browse files
committed
support all-platforms flag with soci convert
Signed-off-by: Swagat Bora <[email protected]>
1 parent 05ab86f commit f4f7763

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

cmd/nerdctl/image/image_convert.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ func convertOptions(cmd *cobra.Command) (types.ImageConvertOptions, error) {
303303
SociOptions: types.SociOptions{
304304
SpanSize: sociSpanSize,
305305
MinLayerSize: sociMinLayerSize,
306+
Platforms: platforms,
307+
AllPlatforms: allPlatforms,
306308
},
307309
},
308310
Stdout: cmd.OutOrStdout(),

cmd/nerdctl/image/image_convert_linux_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestImageConvert(t *testing.T) {
3939
require.Not(nerdtest.Docker),
4040
),
4141
Setup: func(data test.Data, helpers test.Helpers) {
42-
helpers.Ensure("pull", "--quiet", testutil.CommonImage)
42+
helpers.Ensure("pull", "--quiet", "--all-platforms", testutil.CommonImage)
4343
},
4444
SubTests: []*test.Case{
4545
{
@@ -107,6 +107,24 @@ func TestImageConvert(t *testing.T) {
107107
},
108108
Expected: test.Expects(0, nil, nil),
109109
},
110+
{
111+
Description: "soci with all-platforms",
112+
Require: require.All(
113+
require.Not(nerdtest.Docker),
114+
nerdtest.Soci,
115+
nerdtest.SociVersion("0.10.0"),
116+
),
117+
Cleanup: func(data test.Data, helpers test.Helpers) {
118+
helpers.Anyhow("rmi", "-f", data.Identifier("converted-image"))
119+
},
120+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
121+
return helpers.Command("image", "convert", "--soci", "--all-platforms",
122+
"--soci-span-size", "2097152",
123+
"--soci-min-layer-size", "0",
124+
testutil.CommonImage, data.Identifier("converted-image"))
125+
},
126+
Expected: test.Expects(0, nil, nil),
127+
},
110128
},
111129
}
112130

pkg/api/types/image_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,8 @@ type SociOptions struct {
310310
SpanSize int64
311311
// Minimum layer size to build zTOC for. Smaller layers won't have zTOC and not lazy pulled. Default is 10 MiB.
312312
MinLayerSize int64
313+
// Platforms convert content for a specific platform
314+
Platforms []string
315+
// AllPlatforms convert content for all platforms
316+
AllPlatforms bool
313317
}

pkg/cmd/image/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func Convert(ctx context.Context, client *containerd.Client, srcRawRef, targetRa
171171
convertType = "nydus"
172172
case soci:
173173
// Convert image to SOCI format
174-
convertedRef, err := snapshotterutil.ConvertSociIndexV2(ctx, client, srcRef, targetRef, options.GOptions, options.Platforms, options.SociOptions)
174+
convertedRef, err := snapshotterutil.ConvertSociIndexV2(ctx, client, srcRef, targetRef, options.GOptions, options.SociOptions)
175175
if err != nil {
176176
return fmt.Errorf("failed to convert image to SOCI format: %w", err)
177177
}

pkg/snapshotterutil/sociutil.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func CheckSociVersion(requiredVersion string) error {
104104
}
105105

106106
// ConvertSociIndexV2 converts an image to SOCI format and returns the converted image reference with digest
107-
func ConvertSociIndexV2(ctx context.Context, client *client.Client, srcRef string, destRef string, gOpts types.GlobalCommandOptions, platforms []string, sOpts types.SociOptions) (string, error) {
107+
func ConvertSociIndexV2(ctx context.Context, client *client.Client, srcRef string, destRef string, gOpts types.GlobalCommandOptions, sOpts types.SociOptions) (string, error) {
108108
// Check if SOCI version is at least 0.10.0 which is required for the convert operation
109109
if err := CheckSociVersion("0.10.0"); err != nil {
110110
return "", err
@@ -117,10 +117,12 @@ func ConvertSociIndexV2(ctx context.Context, client *client.Client, srcRef strin
117117

118118
sociCmd.Args = append(sociCmd.Args, "convert")
119119

120-
if len(platforms) > 0 {
120+
if sOpts.AllPlatforms {
121+
sociCmd.Args = append(sociCmd.Args, "--all-platforms")
122+
} else if len(sOpts.Platforms) > 0 {
121123
// multiple values need to be passed as separate, repeating flags in soci as it uses urfave
122124
// https://github.com/urfave/cli/blob/main/docs/v2/examples/flags.md#multiple-values-per-single-flag
123-
for _, p := range platforms {
125+
for _, p := range sOpts.Platforms {
124126
sociCmd.Args = append(sociCmd.Args, "--platform", p)
125127
}
126128
}

0 commit comments

Comments
 (0)