-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
image: Refactor to use cas/ref engines instead of walkers
The validation/unpacking code doesn't really care what the reference and CAS implemenations are. And the new generic interfaces in image/refs and image/cas will scale better as we add new backends than the walker interface. The old tar/directory distinction between image and imageLayout is gone. The new CAS/refs engines don't support directory backends yet (I plan on adding them once the engine framework lands), but the new framework will handle tar/directory/... detection inside layout.NewEngine (and possibly inside a new (cas|refs).NewEngine when we grow engine types that aren't based on image-layout). I'd prefer casLayout and refsLayout for the imported packages, but Stephen doesn't want camelCase for package names [1]. [1]: #159 (comment) Signed-off-by: W. Trevor King <wking@tremily.us>
- Loading branch information
Showing
12 changed files
with
157 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,16 +18,16 @@ import ( | |
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/opencontainers/image-spec/image/cas" | ||
"github.com/opencontainers/image-spec/schema" | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
imageSpecs "github.com/opencontainers/image-spec/specs-go" | ||
runtimeSpecs "github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/pkg/errors" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
type cfg struct { | ||
|
@@ -49,43 +49,35 @@ type config struct { | |
Config cfg `json:"config"` | ||
} | ||
|
||
func findConfig(w walker, d *descriptor) (*config, error) { | ||
var c config | ||
cpath := filepath.Join("blobs", d.algo(), d.hash()) | ||
func findConfig(ctx context.Context, engine cas.Engine, descriptor *imageSpecs.Descriptor) (*config, error) { | ||
reader, err := engine.Get(ctx, descriptor.Digest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch err := w.walk(func(path string, info os.FileInfo, r io.Reader) error { | ||
if info.IsDir() || filepath.Clean(path) != cpath { | ||
return nil | ||
} | ||
buf, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
return errors.Wrapf(err, "%s: error reading config", path) | ||
} | ||
buf, err := ioutil.ReadAll(reader) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "%s: error reading manifest", descriptor.Digest) | ||
} | ||
|
||
if err := schema.MediaTypeImageConfig.Validate(bytes.NewReader(buf)); err != nil { | ||
return errors.Wrapf(err, "%s: config validation failed", path) | ||
} | ||
if err := schema.MediaTypeImageConfig.Validate(bytes.NewReader(buf)); err != nil { | ||
return nil, errors.Wrapf(err, "%s: config validation failed", descriptor.Digest) | ||
} | ||
|
||
if err := json.Unmarshal(buf, &c); err != nil { | ||
return err | ||
} | ||
return errEOW | ||
}); err { | ||
case nil: | ||
return nil, fmt.Errorf("%s: config not found", cpath) | ||
case errEOW: | ||
return &c, nil | ||
default: | ||
var c config | ||
if err := json.Unmarshal(buf, &c); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &c, nil | ||
} | ||
|
||
func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) { | ||
func (c *config) runtimeSpec(rootfs string) (*runtimeSpecs.Spec, error) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wking
via email
Author
Contributor
|
||
if c.OS != "linux" { | ||
return nil, fmt.Errorf("%s: unsupported OS", c.OS) | ||
} | ||
|
||
var s specs.Spec | ||
var s runtimeSpecs.Spec | ||
s.Version = "0.5.0" | ||
// we should at least apply the default spec, otherwise this is totally useless | ||
s.Process.Terminal = true | ||
|
@@ -128,12 +120,12 @@ func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) { | |
swap := uint64(c.Config.MemorySwap) | ||
shares := uint64(c.Config.CPUShares) | ||
|
||
s.Linux.Resources = &specs.Resources{ | ||
CPU: &specs.CPU{ | ||
s.Linux.Resources = &runtimeSpecs.Resources{ | ||
CPU: &runtimeSpecs.CPU{ | ||
Shares: &shares, | ||
}, | ||
|
||
Memory: &specs.Memory{ | ||
Memory: &runtimeSpecs.Memory{ | ||
Limit: &mem, | ||
Reservation: &mem, | ||
Swap: &swap, | ||
|
@@ -143,7 +135,7 @@ func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) { | |
for vol := range c.Config.Volumes { | ||
s.Mounts = append( | ||
s.Mounts, | ||
specs.Mount{ | ||
runtimeSpecs.Mount{ | ||
Destination: vol, | ||
Type: "bind", | ||
Options: []string{"rbind"}, | ||
|
Oops, something went wrong.
This whole
runtimeSpec
is ugly and should/could be replaced by using the library inocitools
probably - it's so easy to get outdated and it's easy to forget something (I already made a PR which was fixing how this was generated)