Add global --override-arch and --override-os options

This e.g. allows accessing Linux images on macOS.
This commit is contained in:
Miloslav Trmač 2017-09-16 04:12:33 +02:00
parent 0543f551c7
commit e8fb01e1ed
5 changed files with 25 additions and 3 deletions

View File

@ -24,11 +24,15 @@ var layersCmd = cli.Command{
if c.NArg() == 0 { if c.NArg() == 0 {
return errors.New("Usage: layers imageReference [layer...]") return errors.New("Usage: layers imageReference [layer...]")
} }
ctx, err := contextFromGlobalOptions(c, "")
if err != nil {
return err
}
rawSource, err := parseImageSource(c, c.Args()[0]) rawSource, err := parseImageSource(c, c.Args()[0])
if err != nil { if err != nil {
return err return err
} }
src, err := image.FromSource(rawSource) src, err := image.FromSource(ctx, rawSource)
if err != nil { if err != nil {
if closeErr := rawSource.Close(); closeErr != nil { if closeErr := rawSource.Close(); closeErr != nil {
return errors.Wrapf(err, " (close error: %v)", closeErr) return errors.Wrapf(err, " (close error: %v)", closeErr)

View File

@ -50,6 +50,16 @@ func createApp() *cli.App {
Value: "", Value: "",
Usage: "use registry configuration files in `DIR` (e.g. for container signature storage)", Usage: "use registry configuration files in `DIR` (e.g. for container signature storage)",
}, },
cli.StringFlag{
Name: "override-arch",
Value: "",
Usage: "use `ARCH` instead of the architecture of the machine for choosing images",
},
cli.StringFlag{
Name: "override-os",
Value: "",
Usage: "use `OS` instead of the running OS for choosing images",
},
} }
app.Before = func(c *cli.Context) error { app.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") { if c.GlobalBool("debug") {

View File

@ -11,8 +11,10 @@ import (
func contextFromGlobalOptions(c *cli.Context, flagPrefix string) (*types.SystemContext, error) { func contextFromGlobalOptions(c *cli.Context, flagPrefix string) (*types.SystemContext, error) {
ctx := &types.SystemContext{ ctx := &types.SystemContext{
RegistriesDirPath: c.GlobalString("registries.d"), RegistriesDirPath: c.GlobalString("registries.d"),
DockerCertPath: c.String(flagPrefix + "cert-dir"), ArchitectureChoice: c.GlobalString("override-arch"),
OSChoice: c.GlobalString("override-os"),
DockerCertPath: c.String(flagPrefix + "cert-dir"),
// DEPRECATED: keep this here for backward compatibility, but override // DEPRECATED: keep this here for backward compatibility, but override
// them if per subcommand flags are provided (see below). // them if per subcommand flags are provided (see below).
DockerInsecureSkipTLSVerify: !c.GlobalBoolT("tls-verify"), DockerInsecureSkipTLSVerify: !c.GlobalBoolT("tls-verify"),

View File

@ -103,6 +103,8 @@ _skopeo_skopeo() {
local options_with_args=" local options_with_args="
--policy --policy
--registries.d --registries.d
--override-arch
--override-os
" "
local boolean_options=" local boolean_options="
--insecure-policy --insecure-policy

View File

@ -43,6 +43,10 @@ Most commands refer to container images, using a _transport_`:`_details_ format.
**--registries.d** _dir_ use registry configuration files in _dir_ (e.g. for container signature storage), overriding the default path. **--registries.d** _dir_ use registry configuration files in _dir_ (e.g. for container signature storage), overriding the default path.
**--override-arch** _arch_ Use _arch_ instead of the architecture of the machine for choosing images.
**--override-os** _OS_ Use _OS_ instead of the running OS for choosing images.
**--help**|**-h** Show help **--help**|**-h** Show help
**--version**|**-v** print the version number **--version**|**-v** print the version number