mantl / consul-cli

Command line interface to Consul HTTP API
Apache License 2.0
251 stars 67 forks source link

consul-cli should use $CONSUL_HTTP_ADDR for the --consul flag when set #38

Closed ckeeney closed 8 years ago

ckeeney commented 8 years ago

It would be ideal to be able to set cli params via environment variables. When you run consul-cli, it would check for an arg passed in as a cli param. If none was passed in, it would look for an environment variable, if none is set, it would use the default value defined in the docs.

At the very least this should observe environment variables like CONSUL_HTTP_ADDR that are already being used by consul itself.

ChrisAubuchon commented 8 years ago

consul-cli will use the CONSUL_HTTP_* environment variables (except for, currently, CONSUL_HTTP_ADDR). I'll have to add that to consul-cli instead of relying on the API.

ckeeney commented 8 years ago

OK Thanks Chris. I will edit the title of this issue to be more appropriate. CONSUL_HTTP_ADDR was actually the only one I needed, so I didn't try the rest.

ChrisAubuchon commented 8 years ago

Commit https://github.com/CiscoCloud/consul-cli/commit/83f3b13e869ccd357d89751fef29bce611d6718e should take care of CONSUL_HTTP_ADDR

ckeeney commented 8 years ago

Yep, I confirmed it works using the latest docker image.

Thanks.

ckeeney commented 8 years ago

Sorry I didn't realize I can close issues myself. Closing this now.

ckeeney commented 8 years ago

@ChrisAubuchon can you guys perform a new release of the project to include this change?

ckeeney commented 8 years ago

I may have been mistaken when I confirmed this issue was resolved. I'm not sure what I did wrong, but it doesn't seem to be working:

$ echo $CONSUL_HTTP_ADDR
test:4444
$ consul-cli agent members
Error: Get http://127.0.0.1:8500/v1/agent/members: dial tcp 127.0.0.1:8500: getsockopt: connection refused
Get http://127.0.0.1:8500/v1/agent/members: dial tcp 127.0.0.1:8500: getsockopt: connection refused
$ docker pull ciscocloud/consul-cli
Using default tag: latest
latest: Pulling from ciscocloud/consul-cli

Digest: sha256:050d58ff3cb0f3ec2b88b7531981653f1357576fa718fb3f90dc953e6cbff280
Status: Image is up to date for ciscocloud/consul-cli:latest
$ docker run ciscocloud/consul-cli agent members
Error: Get http://127.0.0.1:8500/v1/agent/members: dial tcp 127.0.0.1:8500: getsockopt: connection refused
Get http://127.0.0.1:8500/v1/agent/members: dial tcp 127.0.0.1:8500: getsockopt: connection refused
$ echo $CONSUL_HTTP_ADDR                        
test:4444

I pulled from dockerhub and also cloned and installed from master and both exhibit this behavior.

ChrisAubuchon commented 8 years ago

docker doesn't pass the environment variables to the container. They need to be set in the docker command line. https://docs.docker.com/engine/reference/run/#/env-environment-variables

ckeeney commented 8 years ago

Sorry that was a silly oversight. Thanks for the clarification.

mschirrmeister commented 8 years ago

Any ETA on when a new release comes out that includes the fix for CONSUL_HTTP_ADDR?