├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── envconsul-config.hcl └── envconsul-launch /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | MAINTAINER Michael Hamrah 4 | 5 | RUN \ 6 | apt-get update && \ 7 | apt-get install -y curl unzip net-tools netcat && \ 8 | curl -L -o ./consul.zip https://github.com/hashicorp/envconsul/releases/download/v0.6.0/envconsul_0.6.0_linux_amd64.zip && \ 9 | unzip ./consul.zip && \ 10 | cp ./envconsul /usr/bin/ && \ 11 | apt-get clean && \ 12 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* *.gz 13 | 14 | ADD envconsul-config.hcl /etc/envconsul-config.hcl 15 | ADD envconsul-launch /usr/bin/envconsul-launch 16 | 17 | RUN chmod +x /usr/bin/envconsul-launch 18 | 19 | ENTRYPOINT ["envconsul-launch"] 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Michael Hamrah 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | docker-envconsul 2 | ================ 3 | 4 | A docker container for envconsul, available via ```PATH``` at ```/usr/bin```. Intended for use as a base image for applications wanting to use envconsul. 5 | 6 | Published to the docker registry as ```mhamrah/envconsul``` 7 | 8 | There is also a launcher script in the path, ```envconsul-launch```, which does a few things for you: 9 | 10 | * Sets the ```-consul``` flag to the ```$CONSUL``` env variable if set, otherwise the gateway ip, assuming consul is running on the host computer on port 8500 11 | * Sanitizes and Upcases keys 12 | * Sets a wait timeout range of 2 to 8 seconds for rolling updates after a key change 13 | * Falls back with a warning to your command line parameter should consul not be available, running the second command line argument passed to the container. 14 | 15 | You can use ```envconsul-launch``` the same way as ```envconsul```. Command line parameters are passed via ```$*```. 16 | 17 | ```envconsul-launch``` is set as the entrypoint, so you can simply pass in your key and command like so: 18 | 19 | ``` 20 | docker run -i -t --rm mhamrah/envconsul CONSUL_KEY env 21 | ``` 22 | 23 | 24 | -------------------------------------------------------------------------------- /envconsul-config.hcl: -------------------------------------------------------------------------------- 1 | sanitize = true 2 | upcase = true 3 | wait = "2s:8s" 4 | -------------------------------------------------------------------------------- /envconsul-launch: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ -z "$CONSUL" ]; then 4 | ROUTE=$(route -n | grep 'UG[ \t ]' | awk '{print $2}') 5 | CONSUL=${ROUTE} 6 | fi 7 | 8 | nc -z $CONSUL 8500 9 | rc=$? 10 | 11 | if [ $rc != 0 ]; then 12 | echo "WARNING! Consul not available, running locally." 13 | $2 14 | else 15 | /usr/bin/envconsul -consul=${CONSUL}:8500 -config /etc/envconsul-config.hcl $* 16 | fi 17 | --------------------------------------------------------------------------------