sourcegraph / src-cli

Sourcegraph CLI
https://sourcegraph.com
Apache License 2.0
267 stars 57 forks source link

docker/info use format JSON #1008

Closed Dasio closed 11 months ago

Dasio commented 12 months ago

This partially fix https://github.com/sourcegraph/src-cli/issues/855

Test plan

I have run unit tests. Also tried it locally with my podman. Still getting some error regarding volumes and tmp files. But that seems more related to podman itself probably.

I need someone to test it also with docker. If it's still work.

Dasio commented 12 months ago

Docker doesn't have format=json, but we can use Go template {{ json .}} for both podman and docker

mrnugget commented 12 months ago

Docker doesn't have format=json, but we can use Go template {{ json .}} for both podman and docker

It does, no?

φ docker info --format json
{"ID":"fdd17e44-fa14-44a6-bcea-675088894c15","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":2,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","extfs"],["Supports d_type","true"],["Using metacopy","false"],["Native Overlay Diff","true"],["userxattr","false"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":43,"OomKillDisable":false,"NGoroutines":64,"SystemTime":"2023-07-20T09:41:46.116258384Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","CgroupVersion":"2","NEventsListener":9,"KernelVersion":"5.15.49-linuxkit-pr","OperatingSystem":"Docker Desktop","OSVersion":"","OSType":"linux","Architecture":"aarch64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true},"hubproxy.docker.internal:5555":{"Name":"hubproxy.docker.internal:5555","Mirrors":[],"Secure":false,"Official":false}},"Mirrors":null},"NCPU":5,"MemTotal":8337481728,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"http.docker.internal:3128","HttpsProxy":"http.docker.internal:3128","NoProxy":"hubproxy.docker.internal","Name":"docker-desktop","Labels":[],"ExperimentalBuild":false,"ServerVersion":"24.0.2","Runtimes":{"io.containerd.runc.v2":{"path":"runc"},"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"3dce8eb055cbb6872793272b4f20ed16117344f8","Expected":"3dce8eb055cbb6872793272b4f20ed16117344f8"},"RuncCommit":{"ID":"v1.1.7-0-g860f061","Expected":"v1.1.7-0-g860f061"},"InitCommit":{"ID":"de40ad0","Expected":"de40ad0"},"SecurityOptions":["name=seccomp,profile=builtin","name=cgroupns"],"Warnings":null,"ClientInfo":{"Debug":false,"Version":"24.0.2","GitCommit":"cb74dfc","GoVersion":"go1.20.4","Os":"darwin","Arch":"arm64","BuildTime":"Thu May 25 21:51:16 2023","Context":"desktop-linux","Plugins":[{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.10.5","ShortDescription":"Docker Buildx","Name":"buildx","Path":"/Users/thorstenball/.docker/cli-plugins/docker-buildx","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-buildx"]},{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v2.18.1","ShortDescription":"Docker Compose","Name":"compose","Path":"/Users/thorstenball/.docker/cli-plugins/docker-compose","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-compose"]},{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.1.0","ShortDescription":"Docker Dev Environments","Name":"dev","Path":"/Users/thorstenball/.docker/cli-plugins/docker-dev","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-dev"]},{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.2.19","ShortDescription":"Manages Docker extensions","Name":"extension","Path":"/Users/thorstenball/.docker/cli-plugins/docker-extension","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-extension"]},{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.1.0-beta.4","ShortDescription":"Creates Docker-related starter files for your project","Name":"init","Path":"/Users/thorstenball/.docker/cli-plugins/docker-init","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-init"]},{"SchemaVersion":"0.1.0","Vendor":"Anchore Inc.","Version":"0.6.0","ShortDescription":"View the packaged-based Software Bill Of Materials (SBOM) for an image","URL":"https://github.com/docker/sbom-cli-plugin","Name":"sbom","Path":"/Users/thorstenball/.docker/cli-plugins/docker-sbom","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-sbom"]},{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.26.0","ShortDescription":"Docker Scan","Name":"scan","Path":"/Users/thorstenball/.docker/cli-plugins/docker-scan","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-scan"]},{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.12.0","ShortDescription":"Command line tool for Docker Scout","Name":"scout","Path":"/Users/thorstenball/.docker/cli-plugins/docker-scout","ShadowedPaths":["/usr/local/lib/docker/cli-plugins/docker-scout"]}],"Warnings":null}}
Dasio commented 12 months ago

Hm, my colleague tried it and it output just json nothing more.

His docker version output:

Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:03:23 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:15 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Maybe old version?

https://docs.docker.com/go/formatting/ here is no reference to json just -format='{{json .}}'

mrnugget commented 12 months ago

If it's version dependent, then this would be a breaking change, I guess, right?

Dasio commented 12 months ago

With -format='{{json .}}' it should be alright.

mrnugget commented 12 months ago

Yeah, that works.