
After some analysis, it was found that Content.Reader was generally redudant to an io.ReaderAt. This change removes `Content.Reader` in favor of a `Content.ReaderAt`. In general, `ReaderAt` can perform better over interfaces with indeterminant latency because it avoids remote state for reads. Where a reader is required, a helper is provided to convert it into an `io.SectionReader`. Signed-off-by: Stephen J Day <stephen.day@docker.com>
80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
// +build windows
|
|
|
|
package containerd
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/containerd/containerd/containers"
|
|
"github.com/containerd/containerd/content"
|
|
"github.com/containerd/containerd/images"
|
|
"github.com/containerd/containerd/typeurl"
|
|
"github.com/opencontainers/image-spec/specs-go/v1"
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
)
|
|
|
|
func WithImageConfig(ctx context.Context, i Image) SpecOpts {
|
|
return func(s *specs.Spec) error {
|
|
var (
|
|
image = i.(*image)
|
|
store = image.client.ContentStore()
|
|
)
|
|
ic, err := image.i.Config(ctx, store)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var (
|
|
ociimage v1.Image
|
|
config v1.ImageConfig
|
|
)
|
|
switch ic.MediaType {
|
|
case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config:
|
|
p, err := content.ReadBlob(ctx, store, ic.Digest)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := json.Unmarshal(p, &ociimage); err != nil {
|
|
return err
|
|
}
|
|
config = ociimage.Config
|
|
default:
|
|
return fmt.Errorf("unknown image config media type %s", ic.MediaType)
|
|
}
|
|
s.Process.Env = config.Env
|
|
s.Process.Args = append(config.Entrypoint, config.Cmd...)
|
|
s.Process.User = specs.User{
|
|
Username: config.User,
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func WithTTY(width, height int) SpecOpts {
|
|
return func(s *specs.Spec) error {
|
|
s.Process.Terminal = true
|
|
s.Process.ConsoleSize.Width = uint(width)
|
|
s.Process.ConsoleSize.Height = uint(height)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func WithSpec(spec *specs.Spec) NewContainerOpts {
|
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
|
any, err := typeurl.MarshalAny(spec)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
c.Spec = any
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func WithResources(resources *specs.WindowsResources) UpdateTaskOpts {
|
|
return func(ctx context.Context, client *Client, r *UpdateTaskInfo) error {
|
|
r.Resources = resources
|
|
return nil
|
|
}
|
|
}
|