Skip to content

Commit

Permalink
Drop --json/--no-json and create.json
Browse files Browse the repository at this point in the history
[#143034769]
  • Loading branch information
spikymonkey committed May 4, 2017
1 parent ba94581 commit d6c26df
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 295 deletions.
39 changes: 12 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ create:
| create.with\_clean | Clean up unused layers before creating rootfs |
| create.uid_mappings | UID mapping for image translation, e.g.: \<Namespace UID\>:\<Host UID\>:\<Size\> |
| create.gid_mappings | GID mapping for image translation, e.g.: \<Namespace GID\>:\<Host GID\>:\<Size\> |
| create.json | Format the output as JSON |
| create.without_mount | Don't perform the rootfs mount and return the mount information in the json output. Only usable with --json. |
| create.without_mount | Don't perform the rootfs mount. |
| clean.ignore\_images | Images to ignore during cleanup |
| clean.threshold\_bytes | Disk usage of the store directory at which cleanup should trigger |
Expand Down Expand Up @@ -198,35 +197,22 @@ grootfs --store /mnt/btrfs create /my-rootfs.tar my-image-id

#### Output

The output of this command is the image path
(`/mnt/btrfs/images/<uid>/my-image-id`) which has the following structure:

* The `<uid>` is the effective user id running the command.
The output of this command is a json object which has the following structure:

```
<Returned directory>
|____ rootfs/
|____ image.json
{
"rootfs": "...", # complete path to the image rootfs, which lives in <image-path>/rootfs
"config": {...}, # contents of image config, also writen to <image-path>/image.json
}
```

* The `rootfs` folder is where the root filesystem lives.
* The `image.json` file follows the [OCI image
* The `<image-path>/rootfs` folder is where the root filesystem lives.
* The `<image-path>/image.json` file follows the [OCI image
description](https://github.com/opencontainers/image-spec/blob/master/serialization.md#image-json-description)
schema.

##### JSON

When create is provided with a `--json` flag, it will print the output as json.
The json will contain:

```
{
"rootfs": "...", # complete path to the image rootfs
"config": {...}, # contents of image config, also writen to <image-path>/image.json
}
```

If `--without-mount` flag is provided (or `create.without_mount = true` in config),
If the `--without-mount` flag is provided (or `create.without_mount = true` in config),
the json output will also contain the `mount` key:

```
Expand All @@ -240,11 +226,10 @@ the json output will also contain the `mount` key:
...
```

Special notes about `--without-mount`/`create.without_mount`:
The `--without-mount` option exists so that GrootFS can be run as non-root. The mount information is compatible
with [OCI container spec](https://github.com/opencontainers/runtime-spec/blob/master/config.md#example-linux).


* It can only be used in combination with the `--json` (or `create.json` in config) option
* This option exists so that GrootFS can be run as non-root. The mount information
is compatible with [OCI container spec](https://github.com/opencontainers/runtime-spec/blob/master/config.md#example-linux).

#### User/Group ID Mapping

Expand Down
13 changes: 0 additions & 13 deletions commands/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type Create struct {
ExcludeImageFromQuota bool `yaml:"exclude_image_from_quota"`
WithClean bool `yaml:"with_clean"`
WithoutMount bool `yaml:"without_mount"`
Json bool `yaml:"json"`
DiskLimitSizeBytes int64 `yaml:"disk_limit_size_bytes"`
InsecureRegistries []string `yaml:"insecure_registries"`
GIDMappings []string `yaml:"gid_mappings"`
Expand Down Expand Up @@ -228,18 +227,6 @@ func (b *Builder) WithMount(mount bool, noMount bool) *Builder {
return b
}

func (b *Builder) WithJson(json bool, noJson bool) *Builder {
if json {
b.config.Create.Json = true
}

if noJson {
b.config.Create.Json = false
}

return b
}

func load(configPath string) (Config, error) {
configContent, err := ioutil.ReadFile(configPath)
if err != nil {
Expand Down
42 changes: 0 additions & 42 deletions commands/config/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var _ = Describe("Builder", func() {
GIDMappings: []string{"config-gid-mapping"},
InsecureRegistries: []string{"http://example.org"},
DiskLimitSizeBytes: int64(1000),
Json: false,
}

cleanCfg = config.Clean{
Expand Down Expand Up @@ -602,47 +601,6 @@ var _ = Describe("Builder", func() {
})
})

Describe("WithJson", func() {
Context("when no-json is set, and json is not set", func() {
BeforeEach(func() {
cfg.Create.Json = true
})

It("overrides the config's entry", func() {
builder = builder.WithJson(false, true)
config, err := builder.Build()
Expect(err).NotTo(HaveOccurred())
Expect(config.Create.Json).To(BeFalse())
})
})

Context("when no-json is not set, and json is set", func() {
BeforeEach(func() {
cfg.Create.Json = false
})

It("overrides the config's entry", func() {
builder = builder.WithJson(true, false)
config, err := builder.Build()
Expect(err).NotTo(HaveOccurred())
Expect(config.Create.Json).To(BeTrue())
})
})

Context("when no-json is not set, and json is not set", func() {
BeforeEach(func() {
cfg.Create.Json = true
})

It("uses the config value", func() {
builder = builder.WithJson(false, false)
config, err := builder.Build()
Expect(err).NotTo(HaveOccurred())
Expect(config.Create.Json).To(BeTrue())
})
})
})

Describe("WithMount", func() {
Context("when without-mount is set, and with-mount is not set", func() {
BeforeEach(func() {
Expand Down
37 changes: 6 additions & 31 deletions commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ var CreateCommand = cli.Command{
},
cli.BoolFlag{
Name: "without-mount",
Usage: "Do not mount the root filesystem. Must be used in conjunction with --json.",
},
cli.BoolFlag{
Name: "json",
Usage: "Print RootFS Path and container config as JSON",
},
cli.BoolFlag{
Name: "no-json",
Usage: "Do NOT print RootFS Path and container config as JSON",
Usage: "Do not mount the root filesystem.",
},
cli.StringFlag{
Name: "username",
Expand Down Expand Up @@ -110,7 +102,6 @@ var CreateCommand = cli.Command{
WithExcludeImageFromQuota(ctx.Bool("exclude-image-from-quota"),
ctx.IsSet("exclude-image-from-quota")).
WithClean(ctx.IsSet("with-clean"), ctx.IsSet("without-clean")).
WithJson(ctx.IsSet("json"), ctx.IsSet("no-json")).
WithMount(ctx.IsSet("with-mount"), ctx.IsSet("without-mount"))

cfg, err := configBuilder.Build()
Expand Down Expand Up @@ -218,7 +209,6 @@ var CreateCommand = cli.Command{

createSpec := groot.CreateSpec{
ID: id,
Json: cfg.Create.Json,
Mount: !cfg.Create.WithoutMount,
BaseImage: baseImage,
DiskLimit: cfg.Create.DiskLimitSizeBytes,
Expand All @@ -236,19 +226,12 @@ var CreateCommand = cli.Command{
return newExitError(humanizedError, 1)
}

var output string
if cfg.Create.Json {
jsonBytes, err := json.Marshal(image)
if err != nil {
logger.Error("formatting output", err)
return newExitError(err.Error(), 1)
}
output = string(jsonBytes)
} else {
output = image.Path
jsonBytes, err := json.Marshal(image)
if err != nil {
logger.Error("formatting output", err)
return newExitError(err.Error(), 1)
}

fmt.Println(output)
fmt.Println(string(jsonBytes))

usage, err := sm.MeasureStore(logger)
if err != nil {
Expand Down Expand Up @@ -344,13 +327,5 @@ func validateOptions(ctx *cli.Context, cfg config.Config) error {
return errorspkg.New("with-clean and without-clean cannot be used together")
}

if ctx.IsSet("json") && ctx.IsSet("no-json") {
return errorspkg.New("json and no-json cannot be used together")
}

if cfg.Create.WithoutMount && !cfg.Create.Json {
return errorspkg.New("without-mount option must be used with the json option")
}

return nil
}
1 change: 0 additions & 1 deletion groot/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type CreateSpec struct {
ID string
BaseImage string
DiskLimit int64
Json bool
Mount bool
ExcludeBaseImageFromQuota bool
CleanOnCreate bool
Expand Down
7 changes: 0 additions & 7 deletions integration/create_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var _ = Describe("Create with local images", func() {
BaseImage: baseImagePath,
ID: "random-id",
Mount: mountByDefault(),
Json: true,
}
})

Expand Down Expand Up @@ -87,7 +86,6 @@ var _ = Describe("Create with local images", func() {
ID: "another-random-id",
BaseImage: baseImagePath,
Mount: false,
Json: true,
})
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -127,7 +125,6 @@ var _ = Describe("Create with local images", func() {
ID: "my-image-1",
BaseImage: baseImagePath,
Mount: true,
Json: true,
})
Expect(err).NotTo(HaveOccurred())

Expand All @@ -146,7 +143,6 @@ var _ = Describe("Create with local images", func() {
ID: "my-image-2",
BaseImage: baseImage2Path,
Mount: true,
Json: true,
}
_, err := Runner.Create(createSpec)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -234,7 +230,6 @@ var _ = Describe("Create with local images", func() {
ID: "random-id-2",
BaseImage: baseImagePath,
Mount: mountByDefault(),
Json: true,
})
Expect(err).NotTo(HaveOccurred())
Expect(Runner.EnsureMounted(image)).To(Succeed())
Expand All @@ -259,7 +254,6 @@ var _ = Describe("Create with local images", func() {
ID: "random-id-2",
BaseImage: baseImagePath,
Mount: mountByDefault(),
Json: true,
})
Expect(Runner.EnsureMounted(image)).To(Succeed())
Expect(err).NotTo(HaveOccurred())
Expand All @@ -274,7 +268,6 @@ var _ = Describe("Create with local images", func() {
BaseImage: "/invalid/image",
ID: "random-id",
Mount: false,
Json: true,
})
Expect(err).To(MatchError(ContainSubstring("stat /invalid/image: no such file or directory")))
})
Expand Down
1 change: 0 additions & 1 deletion integration/create_overlayxfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var _ = Describe("Create (overlay-xfs only)", func() {
BaseImage: baseImagePath,
ID: "random-id",
Mount: mountByDefault(),
Json: !mountByDefault(),
DiskLimit: tenMegabytes,
}
})
Expand Down
Loading

0 comments on commit d6c26df

Please sign in to comment.