pygmystack / pygmy

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

Pick next available ports if default ones are in use #373

Closed rsau closed 2 years ago

rsau commented 2 years ago

Is your feature request related to a problem? Please describe.

I also use lando for local development. If I start pygmy first, it uses 80, 443 by default as expected. Now when I start lando later it also tries 80, 443 first but if they are assigned to other process, it picks next available which is fine.

In a scenario where I start lando first and pygmy after, pygmy fails to start because it has been hard coded to use 80, 443. Is there a way to make pygmy also picks next available port if port is already in use.

Describe the solution you'd like

Keep the default as 80, 443 but check port availability and pick next available port instead of throwing error

Describe alternatives you've considered I exported config using pygmy export and changed ports in the config but still get error. It is reading config file which is evident from yaml warnings but doesn't read ports info.
It is posible that pygmy discards the exported config file due to yaml errors and falls back to defaults but there is no explicit message about that.


* 'Networks[amazeeio-network].Created' expected a map, got 'string'
* 'Networks[amazeeio-network].Labels[pygmy]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[name:amazeeio-network]'
* 'Services[amazeeio-dnsmasq].Config.Labels[pygmy]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[defaults:true enable:true name:amazeeio-dnsmasq weight:13]'
* 'Services[amazeeio-haproxy].Config.Labels[pygmy]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[defaults:true enable:true name:amazeeio-haproxy network:amazeeio-network url:http://docker.amazee.io/stats weight:14]'
* 'Services[amazeeio-mailhog].Config.Labels[pygmy]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[defaults:true enable:true name:amazeeio-mailhog network:amazeeio-network url:http://mailhog.docker.amazee.io weight:15]'
* 'Services[amazeeio-ssh-agent-add-key].Config.Labels[pygmy]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[defaults:true discrete:true enable:true name:amazeeio-ssh-agent-add-key network:amazeeio-network output:false purpose:addkeys weight:31]'
* 'Services[amazeeio-ssh-agent].Config.Labels[pygmy]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[defaults:true enable:true name:amazeeio-ssh-agent network:amazeeio-network output:false purpose:sshagent weight:30]'
[ ] amazeeio-haproxy is not able to start on port 80: listen tcp :80: bind: address already in use
[ ] amazeeio-haproxy is not able to start on port 443: listen tcp :443: bind: address already in use
Please address the above issues before you attempt to start Pygmy again.

Previously I used https://github.com/amazeeio/amazeeio-docker-windows/blob/master/docker-compose.yml but it looks like project is abandoned. It is pretty easy to override ports at https://github.com/amazeeio/amazeeio-docker-windows/blob/master/docker-compose.yml#L16

Thanks

tobybellwood commented 2 years ago

hi @rsau - here is a sample config to run on a different port (in this case 8080) - as long as you're running the more recent pygmy (formerly pygmy-go)

$ cat ~/.pygmy.yml
services:
  amazeeio-haproxy:
    HostConfig:
      PortBindings:
        80/tcp:
          - HostPort: 8080
        443/tcp:
          - HostPort: 443
rsau commented 2 years ago

Thank you @tobybellwood for quick response.

It worked. I installed pygmy via brew so it has latest release.

it looks like if I export config and make changes to port, it fails to read that file

Is there a chance that in future it picks next available ports automatically? Issue can be closed otherwise.

I'll create another issue for bug about exported config file generating yaml warning/errors.

When I had changed the above values in exported config earlier, pygmy didn't pick them up.

tobybellwood commented 2 years ago

yup - I'm not sure why it doesn't like the export, but a ticket would help us track it.

I know we've looked at alternate/fallback port configuration before, I'll see where that is up to.

fubarhouse commented 2 years ago

A dynamic port for specified containers is completely feasible and wouldn't take a lot of time to implement.

Exported config should inherit custom changes, but I can look into that as well.

rsau commented 2 years ago

Created #374 and closing this one.