diff --git a/docs/stream_processors.md b/docs/stream_processors.md index 67af20d58..ba227a599 100644 --- a/docs/stream_processors.md +++ b/docs/stream_processors.md @@ -21,20 +21,20 @@ pipe's path set as the value of the environment variable `STREAM_PROCESSOR_PIPE` ## Configuration To configure stream processors for containerd, entries in the config file need to be made. -The `stream_processors` field is an array so that users can chain together multiple processors +The `stream_processors` field is a map so that users can chain together multiple processors to mutate content streams. Processor Fields: -* `id` - ID of the processor, used for passing a specific payload to the processor. +* Key - ID of the processor, used for passing a specific payload to the processor. * `accepts` - Accepted media-types for the processor that it can handle. * `returns` - The media-type that the processor returns. * `path` - Path to the processor binary. * `args` - Arguments passed to the processor binary. ```toml -[[stream_processors]] - id = "io.containerd.processor.v1.pigz" +[stream_processors] + [stream_processors."io.containerd.processor.v1.pigz"] accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"] returns = "application/vnd.oci.image.layer.v1.tar" path = "unpigz" diff --git a/services/server/config/config.go b/services/server/config/config.go index e3aacbae8..bc9520fea 100644 --- a/services/server/config/config.go +++ b/services/server/config/config.go @@ -63,13 +63,11 @@ type Config struct { // Imports are additional file path list to config files that can overwrite main config file fields Imports []string `toml:"imports"` - StreamProcessors []StreamProcessor `toml:"stream_processors"` + StreamProcessors map[string]StreamProcessor `toml:"stream_processors"` } // StreamProcessor provides configuration for diff content processors type StreamProcessor struct { - // ID of the processor, also used to fetch the specific payload - ID string `toml:"id"` // Accepts specific media-types Accepts []string `toml:"accepts"` // Returns the media-type diff --git a/services/server/config/config_test.go b/services/server/config/config_test.go index 2f0848894..90cba46f2 100644 --- a/services/server/config/config_test.go +++ b/services/server/config/config_test.go @@ -86,6 +86,11 @@ func TestLoadSingleConfig(t *testing.T) { data := ` version = 2 root = "/var/lib/containerd" + +[stream_processors] + [stream_processors."io.containerd.processor.v1.pigz"] + accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"] + path = "unpigz" ` tempDir, err := ioutil.TempDir("", "containerd_") assert.NilError(t, err) @@ -100,6 +105,12 @@ root = "/var/lib/containerd" assert.NilError(t, err) assert.Equal(t, 2, out.Version) assert.Equal(t, "/var/lib/containerd", out.Root) + assert.DeepEqual(t, map[string]StreamProcessor{ + "io.containerd.processor.v1.pigz": { + Accepts: []string{"application/vnd.docker.image.rootfs.diff.tar.gzip"}, + Path: "unpigz", + }, + }, out.StreamProcessors) } func TestLoadConfigWithImports(t *testing.T) { diff --git a/services/server/server.go b/services/server/server.go index 3f2bad22b..92cd75e7d 100644 --- a/services/server/server.go +++ b/services/server/server.go @@ -89,8 +89,8 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) { if err != nil { return nil, err } - for _, p := range config.StreamProcessors { - diff.RegisterProcessor(diff.BinaryHandler(p.ID, p.Returns, p.Accepts, p.Path, p.Args)) + for id, p := range config.StreamProcessors { + diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args)) } serverOpts := []grpc.ServerOption{