Skip to content

Commit 134f401

Browse files
committed
fix golangci-lint
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent b4bcc30 commit 134f401

File tree

4 files changed

+56
-44
lines changed

4 files changed

+56
-44
lines changed

cmd/nerdctl/image/image_convert_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestImageConvert(t *testing.T) {
102102
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
103103
return helpers.Command("image", "convert", "--soci",
104104
"--soci-span-size", "2097152",
105-
"--soci-min-layer-size", "20971520",
105+
"--soci-min-layer-size", "0",
106106
testutil.CommonImage, data.Identifier("converted-image"))
107107
},
108108
Expected: test.Expects(0, nil, nil),

docs/soci.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ SOCI Snapshotter is a containerd snapshotter plugin. It enables standard OCI ima
44

55
See https://github.com/awslabs/soci-snapshotter to learn further information.
66

7+
## SOCI Index Manifest Versions
8+
9+
SOCI supports two index manifest versions:
10+
11+
- **v1**: Original format using OCI Referrers API (disabled by default in SOCI v0.10.0+)
12+
- **v2**: New format that packages SOCI index with the image (default in SOCI v0.10.0+)
13+
14+
To enable v1 indices in SOCI v0.10.0+, add to `/etc/soci-snapshotter-grpc/config.toml`:
15+
```toml
16+
[pull_modes]
17+
[pull_modes.soci_v1]
18+
enable = true
19+
```
20+
21+
For detailed information about the differences between v1 and v2, see the [SOCI Index Manifest v2 documentation](https://github.com/awslabs/soci-snapshotter/blob/main/docs/soci-index-manifest-v2.md).
22+
723
## Prerequisites
824

925
- Install containerd remote snapshotter plugin (`soci-snapshotter-grpc`) from https://github.com/awslabs/soci-snapshotter/blob/main/docs/getting-started.md
@@ -46,10 +62,12 @@ nerdctl push --snapshotter=soci --soci-span-size=2097152 --soci-min-layer-size=2
4662
```
4763
--soci-span-size and --soci-min-layer-size are two properties to customize the SOCI index. See [Command Reference](https://github.com/containerd/nerdctl/blob/377b2077bb616194a8ef1e19ccde32aa1ffd6c84/docs/command-reference.md?plain=1#L773) for further details.
4864

65+
> **Note**: With SOCI v0.10.0+, `nerdctl push` creates and pushes v2 indices by default. For v1 indices, enable them in the snapshotter config as described in the section above.
66+
4967

5068
## Enable SOCI for `nerdctl image convert`
5169

52-
| :zap: Requirement | nerdctl >= 2.2.0 |
70+
| :zap: Requirement | nerdctl >= 2.1.3 |
5371
| ----------------- | ---------------- |
5472

5573
| :zap: Requirement | soci-snapshotter >= 0.10.0 |
@@ -59,4 +77,6 @@ nerdctl push --snapshotter=soci --soci-span-size=2097152 --soci-min-layer-size=2
5977
```console
6078
nerdctl image convert --soci --soci-span-size=2097152 --soci-min-layer-size=20971520 public.ecr.aws/my-registry/my-repo:latest public.ecr.aws/my-registry/my-repo:soci
6179
```
62-
--soci-span-size and --soci-min-layer-size are two properties to customize the SOCI index. See [Command Reference](https://github.com/containerd/nerdctl/blob/377b2077bb616194a8ef1e19ccde32aa1ffd6c84/docs/command-reference.md?plain=1#L773) for further details.
80+
--soci-span-size and --soci-min-layer-size are two properties to customize the SOCI index. See [Command Reference](https://github.com/containerd/nerdctl/blob/377b2077bb616194a8ef1e19ccde32aa1ffd6c84/docs/command-reference.md?plain=1#L773) for further details.
81+
82+
The `image convert` command with `--soci` flag creates SOCI-enabled images using SOCI Index Manifest v2, which combines the SOCI index and the original image into a single artifact.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ require (
136136
go.opentelemetry.io/otel/metric v1.35.0 // indirect
137137
go.opentelemetry.io/otel/trace v1.35.0 // indirect
138138
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
139-
golang.org/x/mod v0.25.0 // indirect
139+
golang.org/x/mod v0.25.0
140140
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
141141
//gomodjail:unconfined
142142
google.golang.org/grpc v1.72.2 // indirect

pkg/snapshotterutil/sociutil.go

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,38 @@ import (
2626
"strconv"
2727
"strings"
2828

29-
"github.com/Masterminds/semver/v3"
29+
"golang.org/x/mod/semver"
30+
3031
"github.com/containerd/containerd/v2/client"
3132
"github.com/containerd/log"
3233

3334
"github.com/containerd/nerdctl/v2/pkg/api/types"
3435
)
3536

37+
// setupSociCommand creates and sets up a SOCI command with common configuration
38+
func setupSociCommand(gOpts types.GlobalCommandOptions) (*exec.Cmd, error) {
39+
sociExecutable, err := exec.LookPath("soci")
40+
if err != nil {
41+
log.L.WithError(err).Error("soci executable not found in path $PATH")
42+
log.L.Info("you might consider installing soci from: https://github.com/awslabs/soci-snapshotter/blob/main/docs/install.md")
43+
return nil, err
44+
}
45+
46+
sociCmd := exec.Command(sociExecutable)
47+
sociCmd.Env = os.Environ()
48+
49+
// #region for global flags.
50+
if gOpts.Address != "" {
51+
sociCmd.Args = append(sociCmd.Args, "--address", gOpts.Address)
52+
}
53+
if gOpts.Namespace != "" {
54+
sociCmd.Args = append(sociCmd.Args, "--namespace", gOpts.Namespace)
55+
}
56+
57+
return sociCmd, nil
58+
}
59+
3660
// CheckSociVersion checks if the SOCI binary version is at least the required version
37-
// This function can be used by both production code and tests
3861
func CheckSociVersion(requiredVersion string) error {
3962
sociExecutable, err := exec.LookPath("soci")
4063
if err != nil {
@@ -58,50 +81,19 @@ func CheckSociVersion(requiredVersion string) error {
5881
return fmt.Errorf("failed to parse SOCI version from output: %s", versionStr)
5982
}
6083

61-
// Extract version number
62-
installedVersion := matches[1]
84+
// Extract version number and add 'v' prefix required by semver package
85+
// The regex captures only the numeric part, so we always need to add the 'v'
86+
installedVersion := "v" + matches[1]
87+
requiredSemver := "v" + requiredVersion
6388

64-
// Compare versions using semver
65-
v1, err := semver.NewVersion(installedVersion)
66-
if err != nil {
67-
return fmt.Errorf("failed to parse installed version %s: %v", installedVersion, err)
68-
}
69-
70-
v2, err := semver.NewVersion(requiredVersion)
71-
if err != nil {
72-
return fmt.Errorf("failed to parse minimum required version %s: %v", requiredVersion, err)
73-
}
74-
75-
if v1.LessThan(v2) {
76-
return fmt.Errorf("SOCI version %s is lower than the required version %s for the convert operation", installedVersion, requiredVersion)
89+
// Use semver package to compare versions
90+
if semver.Compare(installedVersion, requiredSemver) < 0 {
91+
return fmt.Errorf("SOCI version %s is lower than the required version %s for the convert operation", strings.TrimPrefix(installedVersion, "v"), requiredVersion)
7792
}
7893

7994
return nil
8095
}
8196

82-
// setupSociCommand creates and sets up a SOCI command with common configuration
83-
func setupSociCommand(gOpts types.GlobalCommandOptions) (*exec.Cmd, error) {
84-
sociExecutable, err := exec.LookPath("soci")
85-
if err != nil {
86-
log.L.WithError(err).Error("soci executable not found in path $PATH")
87-
log.L.Info("you might consider installing soci from: https://github.com/awslabs/soci-snapshotter/blob/main/docs/install.md")
88-
return nil, err
89-
}
90-
91-
sociCmd := exec.Command(sociExecutable)
92-
sociCmd.Env = os.Environ()
93-
94-
// #region for global flags.
95-
if gOpts.Address != "" {
96-
sociCmd.Args = append(sociCmd.Args, "--address", gOpts.Address)
97-
}
98-
if gOpts.Namespace != "" {
99-
sociCmd.Args = append(sociCmd.Args, "--namespace", gOpts.Namespace)
100-
}
101-
102-
return sociCmd, nil
103-
}
104-
10597
// ConvertSociIndexV2 converts an image to SOCI format and returns the converted image reference with digest
10698
func ConvertSociIndexV2(ctx context.Context, client *client.Client, srcRef string, destRef string, gOpts types.GlobalCommandOptions, platforms []string, sOpts types.SociOptions) (string, error) {
10799
// Check if SOCI version is at least 0.10.0 which is required for the convert operation

0 commit comments

Comments
 (0)