Dump etcd keys into dotenv file or docker env file
Clone or download
sorah v0.6.0
- Handle '401 The event in requested index is outdated and cleared'

- exponential backoff when retrying
Latest commit 2b4f5ae May 20, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Add bin/etcenv, lib/etcenv/cli.rb Apr 6, 2015
lib v0.6.0 May 20, 2016
scripts bin/* -> scripts Apr 1, 2015
spec use X-Etcd-Index for initial watch May 20, 2016
.gitignore initial Apr 1, 2015
.rspec initial Apr 1, 2015
.travis.yml enable travis-ci Apr 8, 2015
Gemfile initial Apr 1, 2015
LICENSE.txt initial Apr 1, 2015
README.md enable travis-ci Apr 8, 2015
Rakefile initial Apr 1, 2015
etcenv.gemspec Support sorah/etcvault Apr 13, 2015


Etcenv: Dump etcd keys into dotenv file or docker env file

Build Status


$ gem install etcenv

Simple Usage

Create directory and keys on etcd

etcdctl mkdir /my-app
etcdctl set /my-app/AWESOME_SERVICE_CREDENTIAL xxxxxx

Run etcenv


This will output generated .env file to STDOUT.

$ etcenv /my-app


$ etcenv -o .env /my-app
$ cat .env

to save as file.

Continuously update

Etcenv also supports watching etcd server. In --watch mode, Etcenv updates dotenv file when value gets updated:

$ etcenv --watch -o .env /my-env

Also you can start it as daemon:

$ etcenv --watch --daemon /path/to/pidfile.pid -o .env /my-env

For docker

Use --docker flag to generate file for docker's --env-file option.

In docker mode, etcenv evaluates ${...} expansion like dotenv do.


etcd options

  • --etcd: URL of etcd to connect to. Path in URL will be ignored.
  • --etcd-ca-file: Path to CA certificate file (PEM) of etcd server.
  • --etcd-cert-file: Path to client certificate file for etcd.
  • --etcd-key-file: Path to private key file of client certificate file for etcd.

Advanced usage

Include other directory's variables

Set directory path to .include. Directories can be specified multiple, separated by comma.

etcdctl mkdir /common
etcdctl set /common/COMMON_SECRET xxx
etcdctl set /my-app/.include /common

Also, you can omit path of parent directory:

etcdctl mkdir /envs/common
etcdctl set /envs/common/COMMON_SECRET xxx

etcdctl mkdir /envs/my-app
etcdctl set /envs/my-app/.include common
  • .include will be applied recursively (up to 10 times by default). If .include is looping, it'll be an error.
  • For multiple .include, value for same key may be overwritten.
    • If a includes b,c and b includes d, result for a will be: d, b, c, then a.


After checking out the repo, run scripts/setup to install dependencies. Then, run scripts/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.


  1. Fork it ( https://github.com/sorah/etcenv/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request