Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update image-layout.md: fix json format in practice #453

Merged
merged 1 commit into from
Dec 1, 2016
Merged

Update image-layout.md: fix json format in practice #453

merged 1 commit into from
Dec 1, 2016

Conversation

Sn0rt
Copy link
Contributor

@Sn0rt Sn0rt commented Nov 7, 2016

In real world, if you do not format the output of cat, it will be so ugly.
And the original document may generate through imagination.

Example:

[guohao@localhost image-tools]$ cat etcd-oci/
blobs/      oci-layout  refs/       
[guohao@localhost image-tools]$ cat etcd-oci/refs/latest 
{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:99ef9268131c383a83c2845413684a66d391e98560c4a0a9ae923c5f04f79e69","size":1042}[guohao@localhost image-tools]$ cat etcd-oci/blobs/sha256/
79ac26bcdd8013a398c7b54506d25cd7c738ba061b362fd1ed56cde4d6152a26  99ef9268131c383a83c2845413684a66d391e98560c4a0a9ae923c5f04f79e69  eeee0535bf3cec7a24bff2c6e97481afa3d37e2cdeff277c57cb5cbdb2fa9e92
95e6aab6810eee8381957a8e83ddd76c5dde9d523e7cfda8f172c7b0e3e60c17  a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4  
[guohao@localhost image-tools]$ cat etcd-oci/blobs/sha256/79ac26bcdd8013a398c7b54506d25cd7c738ba061b362fd1ed56cde4d6152a26 
{"architecture":"amd64","author":"Dawn Chen \u003cdawnchen@google.com\u003e","config":{"Hostname":"aded96b43f48","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":{"2379/tcp":{},"2380/tcp":{},"4001/tcp":{},"7001/tcp":{}},"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["sh"],"Image":"3a9a9956eb76a35a3bccaf0b4de38d2ef8262b58cf0df6206fbd1c63f27bfcd3","Volumes":null,"VolumeDriver":"","WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"MacAddress":"","OnBuild":[],"Labels":{}},"container":"78991c8b805f5e57b54e05566640485309acdd6c3292ce23294b08a80e587014","container_config":{"Hostname":"aded96b43f48","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":{"2379/tcp":{},"2380/tcp":{},"4001/tcp":{},"7001/tcp":{}},"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) COPY multi:706b1bbcebb521830420b655a1ea7fe8cfabc2e90d8804a618926df98558efac in /usr/local/bin/"],"Image":"3a9a9956eb76a35a3bccaf0b4de38d2ef8262b58cf0df6206fbd1c63f27bfcd3","Volumes":null,"VolumeDriver":"","WorkingDir":"","Entrypoint":null,"NetworkDisabled":false,"MacAddress":"","OnBuild":[],"Labels":{}},"created":"2016-08-10T06:33:47.01604452Z","docker_version":"1.7.1","history":[{"created":"2016-01-15T18:06:40.707908287Z","created_by":"/bin/sh -c #(nop) ADD file:a62b361be92f978752150570261ddc6fc21b025e3a28418820a1f39b7db7498c in /"},{"created":"2016-01-15T18:06:41.282540103Z","created_by":"/bin/sh -c #(nop) CMD [\"sh\"]"},{"created":"2016-07-21T06:14:20.151595901Z","author":"Dawn Chen \u003cdawnchen@google.com\u003e","created_by":"/bin/sh -c #(nop) MAINTAINER Dawn Chen \u003cdawnchen@google.com\u003e"},{"created":"2016-07-21T06:14:20.629667506Z","author":"Dawn Chen \u003cdawnchen@google.com\u003e","created_by":"/bin/sh -c #(nop) EXPOSE 2379/tcp 2380/tcp 4001/tcp 7001/tcp"},{"created":"2016-08-10T06:33:47.01604452Z","author":"Dawn Chen \u003cdawnchen@google.com\u003e","created_by":"/bin/sh -c #(nop) COPY multi:706b1bbcebb521830420b655a1ea7fe8cfabc2e90d8804a618926df98558efac in /usr/local/bin/"}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:2c84284818d186d88a16ac7fa731d4b71ba69ecfe11b4ce00413366833cb2403","sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef","sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef","sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef","sha256:5e47621858b3629202b1db1e24abbe4046124c002bbe943bc7ff6502933146c4"]}}[guohao@localhost image-tools]$ uname -a
Linux localhost.localdomain 4.7.2-201.fc24.x86_64 #1 SMP Fri Aug 26 15:58:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Formated:

[guohao@localhost image-tools]$ cat etcd-oci/blobs/sha256/79ac26bcdd8013a398c7b54506d25cd7c738ba061b362fd1ed56cde4d6152a26  | python -m json.tool
{
    "architecture": "amd64",
    "author": "Dawn Chen <dawnchen@google.com>",
    "config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "sh"
        ],
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "ExposedPorts": {
            "2379/tcp": {},
            "2380/tcp": {},
            "4001/tcp": {},
            "7001/tcp": {}
        },
        "Hostname": "aded96b43f48",
        "Image": "3a9a9956eb76a35a3bccaf0b4de38d2ef8262b58cf0df6206fbd1c63f27bfcd3",
        "Labels": {},
        "MacAddress": "",
        "NetworkDisabled": false,
        "OnBuild": [],
        "OpenStdin": false,
        "PortSpecs": null,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "VolumeDriver": "",
        "Volumes": null,
        "WorkingDir": ""
    },
    "container": "78991c8b805f5e57b54e05566640485309acdd6c3292ce23294b08a80e587014",
    "container_config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "/bin/sh",
            "-c",
            "#(nop) COPY multi:706b1bbcebb521830420b655a1ea7fe8cfabc2e90d8804a618926df98558efac in /usr/local/bin/"
        ],
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        ],
        "ExposedPorts": {
            "2379/tcp": {},
            "2380/tcp": {},
            "4001/tcp": {},
            "7001/tcp": {}
        },
        "Hostname": "aded96b43f48",
        "Image": "3a9a9956eb76a35a3bccaf0b4de38d2ef8262b58cf0df6206fbd1c63f27bfcd3",
        "Labels": {},
        "MacAddress": "",
        "NetworkDisabled": false,
        "OnBuild": [],
        "OpenStdin": false,
        "PortSpecs": null,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "VolumeDriver": "",
        "Volumes": null,
        "WorkingDir": ""
    },
    "created": "2016-08-10T06:33:47.01604452Z",
    "docker_version": "1.7.1",
    "history": [
        {
            "created": "2016-01-15T18:06:40.707908287Z",
            "created_by": "/bin/sh -c #(nop) ADD file:a62b361be92f978752150570261ddc6fc21b025e3a28418820a1f39b7db7498c in /"
        },
        {
            "created": "2016-01-15T18:06:41.282540103Z",
            "created_by": "/bin/sh -c #(nop) CMD [\"sh\"]"
        },
        {
            "author": "Dawn Chen <dawnchen@google.com>",
            "created": "2016-07-21T06:14:20.151595901Z",
            "created_by": "/bin/sh -c #(nop) MAINTAINER Dawn Chen <dawnchen@google.com>"
        },
        {
            "author": "Dawn Chen <dawnchen@google.com>",
            "created": "2016-07-21T06:14:20.629667506Z",
            "created_by": "/bin/sh -c #(nop) EXPOSE 2379/tcp 2380/tcp 4001/tcp 7001/tcp"
        },
        {
            "author": "Dawn Chen <dawnchen@google.com>",
            "created": "2016-08-10T06:33:47.01604452Z",
            "created_by": "/bin/sh -c #(nop) COPY multi:706b1bbcebb521830420b655a1ea7fe8cfabc2e90d8804a618926df98558efac in /usr/local/bin/"
        }
    ],
    "os": "linux",
    "rootfs": {
        "diff_ids": [
            "sha256:2c84284818d186d88a16ac7fa731d4b71ba69ecfe11b4ce00413366833cb2403",
            "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
            "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
            "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
            "sha256:5e47621858b3629202b1db1e24abbe4046124c002bbe943bc7ff6502933146c4"
        ],
        "type": "layers"
    }
}

Signed-off-by: Sn0rt Sn0rt@abc.shop.edu.cn

@@ -21,7 +21,7 @@ It also contains a file that is used to identify the layout version:

This is an example image layout:

```
```shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This language specification if for the shell language, but the following example is a shell session. It has both shell-language input (which the shell you add formats correctly) and unformatted output (which the shell you add also attempts to format). As an example:

$ echo "in this case, these are not shell keywords"
in this case, these are not shell keywords

I'd rather leave these as language-agnostic blobs to avoid confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console is the right directive.

@wking I'd recommend at least looking at the github markdown docs before giving direction on a PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know shell is wrong for shell sessions, because I've made that mistake before myself. Looking at the Linguist docs, they have a separate ShellSession for these:

$ echo "in this case, these are not shell keywords"
in this case, these are not shell keywords

Which is better than the shell version I posted earlier because the stdout in and case are not highlighted. Linguist is using atom/language-shellscript.

```
$ cat ./refs/v1.0
{"size": 4096, "digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", "mediaType": "application/vnd.oci.image.manifest.list.v1+json"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm agnostic about whether we pretty-print JSON output or not, although if we do I prefer jq ;).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jq is the current json de jour. I agree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on jq

Copy link
Contributor

@philips philips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly on this but jq is the right thing to use in 2016

```
$ cat ./refs/v1.0
{"size": 4096, "digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f", "mediaType": "application/vnd.oci.image.manifest.list.v1+json"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on jq

@Sn0rt
Copy link
Contributor Author

Sn0rt commented Nov 23, 2016

fixed.
updated to jq.

{
"size": 4096,
"digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f",
"mediaType": "application/vnd.oci.image.manifest.list.v1+json"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jq will use two-space indents by default.

@@ -24,7 +24,7 @@ The image layout MUST also contain a file that is used to identify the layout ve

This is an example image layout:

```
```shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sn0rt can you make this change?

Signed-off-by: Sn0rt <sn0rt@abc.shop.edu.cn>
@Sn0rt
Copy link
Contributor Author

Sn0rt commented Nov 28, 2016

PTAL

@philips
Copy link
Contributor

philips commented Nov 30, 2016

LGTM

Approved with PullApprove

1 similar comment
@vbatts
Copy link
Member

vbatts commented Dec 1, 2016

LGTM

Approved with PullApprove

@vbatts vbatts merged commit 9fa0543 into opencontainers:master Dec 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants