Created
February 25, 2014 16:21
-
-
Save bketelsen/9212213 to your computer and use it in GitHub Desktop.
bash script to start N docker containers, stop old versions, and update confd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ] | |
then | |
echo "usage : gophercon.sh 3 -- start three new instances" | |
exit -1 | |
fi | |
echo "Getting currently running gophercon containers" | |
OLDPORTS=( `docker ps | grep gophercon | awk '{print $1}'` ) | |
echo "starting new containers" | |
for i in `seq 1 $1` ; do | |
echo "inside loop $1" | |
JOB=`docker run -d -p 80 quay.io/bketelsen/gophercon | cut -c1-12` | |
echo $JOB | |
PORT=`docker inspect $JOB | grep HostPort | cut -d '"' -f 4 | head -1` | |
curl http://127.0.0.1:4001/v2/keys/gophercon/upstream/$JOB -XPUT -d value="127.0.0.1:$PORT" | |
done | |
echo "removing old containers" | |
for i in ${OLDPORTS[@]} | |
do | |
etcdctl rm /gophercon/upstream/$i | |
confd -onetime | |
docker kill $i | |
done |
Yes!
Oh, this is confd:master, not the last release, you'll need to build from source until Kelsey makes a new release.
next steps? maybe put this in an nginx/confd combined container, make confd run as a daemon beside nginx
could easily make the docker image a shell argument too
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script starts N new containers of the gophercon docker image, registers them with etcd, removes old containers, and restarts nginx (through confd's script)
This script assumes the following:
thoughts/comments/improvements on my crappy first bash script?
Worth a blog post?