Etcdenv provide a convenient way to populate environments variables from one your etcd directory
Easy! You can just download the binary from the command line:
- Linux
curl -sL https://github.com/upfluence/etcdenv/releases/download/v0.0.1/etcdenv-linux-amd64-0.0.1 > etcdenv- OSX
curl -sL https://github.com/upfluence/etcdenv/releases/download/v0.0.1/etcdenv-darwin-amd64-0.0.1 > etcdenvIf you would prefer compile the binary (assuming buildtools and Go are installed) :
git clone git@github.com:upfluence/etcdenv.git
cd etcdenv
go get github.com/tools/godep
GOPATH=`pwd`/Godeps/_workspace go build -o etcdenv .| Option | Default | Description |
|---|---|---|
server, s |
http://127.0.0.1:4001 | Location of the etcd server |
namespace, n |
/environments/production | Etcd directory where the environment variables are fetched. You can watch multiple namespaces by using a comma-separated list (/environments/production,/environments/global) |
shutdown-behaviour, b |
exit | Strategy to apply when the process exit, further information into the next paragraph |
watched, w |
"" |
A comma-separated list of environment variables triggering the command restart when they change |
restart:etcdenvrerun the command when the wrapped process exitsexit: Theetcdenvprocess exits with the same exit status as the wrapped process'skeepalive: Theetcdenvprocess will stay alive and keep looking for etcd changes to re-run the command
The CLI interface supports all of the options detailed above.
Assuming a etcd server is launched on your machine
You can print env variables fetched from the / directory of your local node of etcd
$ curl -XPOST -d "value=bar" http://127.0.0.1:4001/v2/keys/FOO
$ etcdenv -n / -r false printenv
# ... your local environment variables
FOO=bar
$You can also follow the changes of the directory
$ curl -XPOST -d "value=bar" http://127.0.0.1:4001/v2/keys/FOO
$ etcdenv -n / printenv &
# ... your local environment variables
FOO=bar
$ curl -XPOST -d "value=buz" http://127.0.0.1:4001/v2/keys/FOO
2014/12/29 00:30:00 Restarted
# ... your local environment variables
FOO=buzTo watch a set of keys only
$ curl -XPOST -d "value=google.com" http://127.0.0.1:4001/v2/keys/GOOGLE_URL
$ etcdenv -n / -w "FOO,GOOGLE_URL" printenv &
# ... your local environment variables
GOOGLE_URL=google.com
$ curl -XPOST -d "value=foo" http://127.0.0.1:4001/v2/keys/BAR
# ... the running command does not restart
$ curl -XPOST -d "value=baz" http://127.0.0.1:4001/v2/keys/FOO
# ... your local environment variables
FOO=baz