pygmystack / pygmy

the pygmy stack is a container stack for local development
MIT License
25 stars 12 forks source link

#505: Cleanup output and provide a json formatter for the status command #506

Closed fubarhouse closed 7 months ago

fubarhouse commented 8 months ago

Proposed solution to #505.

Thank you for reaching out @sonnykt & @AlexSkrypnyk - I would love some feedback on this one if you can spare the chance. I'll give it some time and merge but if you have any feedback now is the best time to provide it.

This change is to better support the script-ability of the status command for people that are using this in automation.

Changes

Future

This change opens up the gate for other commands to return json output - so if this is of interest to you just open a ticket.

Output examples for feedback

JSON Formatted

~/GolandProjects/pygmy $ go run main.go status --json | jq
{
  "port_availability": [
    "amazeeio-dnsmasq is able to start on port 6053",
    "amazeeio-mailhog is able to start on port 1025",
    "amazeeio-haproxy is able to start on port 80",
    "amazeeio-haproxy is able to start on port 443"
  ],
  "service_status": {
    "amazeeio-dnsmasq": {
      "container": "amazeeio-dnsmasq",
      "image": "ghcr.io/pygmystack/dnsmasq:pr-2",
      "state": "not running"
    },
    "amazeeio-haproxy": {
      "container": "amazeeio-haproxy",
      "image": "ghcr.io/pygmystack/haproxy:pr-12",
      "state": "not running"
    },
    "amazeeio-mailhog": {
      "container": "amazeeio-mailhog",
      "image": "ghcr.io/pygmystack/mailhog:pr-3",
      "state": "not running"
    },
    "amazeeio-ssh-agent": {
      "container": "amazeeio-ssh-agent",
      "image": "ghcr.io/pygmystack/ssh-agent:pr-2",
      "state": "not running"
    }
  },
  "networks": null,
  "resolvers": [
    "Resolv Linux Resolver is not properly connected"
  ],
  "volumes": null,
  "ssh_messages": null,
  "url_validations": null
}
~/GolandProjects/pygmy $ go run main.go status --json | jq
{
  "port_availability": null,
  "service_status": {
    "amazeeio-dnsmasq": {
      "container": "amazeeio-dnsmasq",
      "image": "ghcr.io/pygmystack/dnsmasq:pr-2",
      "state": "running"
    },
    "amazeeio-haproxy": {
      "container": "amazeeio-haproxy",
      "image": "ghcr.io/pygmystack/haproxy:pr-12",
      "state": "running"
    },
    "amazeeio-mailhog": {
      "container": "amazeeio-mailhog",
      "image": "ghcr.io/pygmystack/mailhog:pr-3",
      "state": "running"
    },
    "amazeeio-ssh-agent": {
      "container": "amazeeio-ssh-agent",
      "image": "ghcr.io/pygmystack/ssh-agent:pr-2",
      "state": "running"
    }
  },
  "networks": null,
  "resolvers": [
    "Resolv Linux Resolver is properly connected"
  ],
  "volumes": null,
  "ssh_messages": [
    "U4096 SHA256:hc7fU47+m7ABUTvCNpr4Kbf236ZKVpQ5oId2Hx3A/kk /home/karl/.ssh/id_rsa (RSA)"
  ],
  "url_validations": [
    " - http://mailhog.docker.amazee.io\n",
    " - http://docker.amazee.io/stats\n"
  ]
}

Without JSON formatter

~/GolandProjects/pygmy $ go run main.go status            
Using config file: /home/karl/.pygmy.yml
[*] amazeeio-dnsmasq is able to start on port 6053
[*] amazeeio-mailhog is able to start on port 1025
[*] amazeeio-haproxy is able to start on port 80
[*] amazeeio-haproxy is able to start on port 443
[ ] amazeeio-mailhog is not running
[ ] amazeeio-haproxy is not running
[ ] amazeeio-ssh-agent is not running
[ ] amazeeio-dnsmasq is not running
[ ] Resolv Linux Resolver is not properly connected
~/GolandProjects/pygmy $ go run main.go status
Using config file: /home/karl/.pygmy.yml
[*] amazeeio-mailhog: Running as container amazeeio-mailhog
[*] amazeeio-haproxy: Running as container amazeeio-haproxy
[*] amazeeio-dnsmasq: Running as container amazeeio-dnsmasq
[*] amazeeio-ssh-agent: Running as container amazeeio-ssh-agent
[*] Resolv Linux Resolver is properly connected
U4096 SHA256:hc7fU47+m7ABUTvCNpr4Kbf236ZKVpQ5oId2Hx3A/kk /home/karl/.ssh/id_rsa (RSA)
 - http://mailhog.docker.amazee.io
 - http://docker.amazee.io/stats
AlexSkrypnyk commented 8 months ago

@fubarhouse Thank you so much for working on this! This new feature looks great and will be useful for embedding pygmy statuses into scripted build process.

AlexSkrypnyk commented 7 months ago

@fubarhouse Is there a known timeframe around merging this? I would love to use this functionality in my project.

fubarhouse commented 7 months ago

Ideally I was just waiting for feedback but that has already happened - the plan now is to give it a final pass and merge in the next week. I'll cut a minor release as well to help with distribution.