Skip to content

Commit 337f5a1

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

File tree

4 files changed

+57
-37
lines changed

4 files changed

+57
-37
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/command-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,8 @@ Flags:
979979
- `--oci` : convert Docker media types to OCI media types
980980
- `--platform=<PLATFORM>` : convert content for a specific platform
981981
- `--all-platforms` : convert content for all platforms (default: false)
982-
- `--soci` : generate SOCI v2 Indices to oci images.
983-
*[**Note**: content is converted for all platforms by default when using this flag, use the `--platorm` flag to limit this behavior]*
982+
- `--soci` : convert content to SOCI image manifest v2
983+
*[**Note**: soci convert uses the default platform if nothing is specified. --platform flag can be used to specify a platform]*
984984
- `--soci-span-size` : Span size in bytes that soci index uses to segment layer data. Default is 4 MiB.
985985
- `--soci-min-layer-size`: Minimum layer size in bytes to build zTOC for. Smaller layers won't have zTOC and not lazy pulled. Default is 10 MiB.
986986

docs/soci.md

Lines changed: 21 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,11 @@ 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+, When using `nerdctl push --snapshotter=soci`, it creates and pushes v1 indices. When pushing a converted image (created with `nerdctl image convert --soci`), it will push v2 indices.
4966
5067
## Enable SOCI for `nerdctl image convert`
5168

52-
| :zap: Requirement | nerdctl >= 2.2.0 |
69+
| :zap: Requirement | nerdctl >= 2.1.3 |
5370
| ----------------- | ---------------- |
5471

5572
| :zap: Requirement | soci-snapshotter >= 0.10.0 |
@@ -59,4 +76,6 @@ nerdctl push --snapshotter=soci --soci-span-size=2097152 --soci-min-layer-size=2
5976
```console
6077
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
6178
```
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.
79+
--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+
81+
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.

pkg/snapshotterutil/sociutil.go

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,37 @@ import (
2727
"strings"
2828

2929
"github.com/Masterminds/semver/v3"
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 {
@@ -59,49 +82,27 @@ func CheckSociVersion(requiredVersion string) error {
5982
}
6083

6184
// Extract version number
62-
installedVersion := matches[1]
85+
installedVersionStr := matches[1]
6386

64-
// Compare versions using semver
65-
v1, err := semver.NewVersion(installedVersion)
87+
// Parse versions using semver package
88+
installedVersion, err := semver.NewVersion(installedVersionStr)
6689
if err != nil {
67-
return fmt.Errorf("failed to parse installed version %s: %v", installedVersion, err)
90+
return fmt.Errorf("failed to parse installed SOCI version: %w", err)
6891
}
6992

70-
v2, err := semver.NewVersion(requiredVersion)
93+
reqVersion, err := semver.NewVersion(requiredVersion)
7194
if err != nil {
72-
return fmt.Errorf("failed to parse minimum required version %s: %v", requiredVersion, err)
95+
return fmt.Errorf("failed to parse required SOCI version: %w", err)
7396
}
7497

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)
98+
// Compare versions
99+
if installedVersion.LessThan(reqVersion) {
100+
return fmt.Errorf("SOCI version %s is lower than the required version %s for the convert operation", installedVersion.String(), reqVersion.String())
77101
}
78102

79103
return nil
80104
}
81105

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-
105106
// ConvertSociIndexV2 converts an image to SOCI format and returns the converted image reference with digest
106107
func ConvertSociIndexV2(ctx context.Context, client *client.Client, srcRef string, destRef string, gOpts types.GlobalCommandOptions, platforms []string, sOpts types.SociOptions) (string, error) {
107108
// Check if SOCI version is at least 0.10.0 which is required for the convert operation

0 commit comments

Comments
 (0)