5 config_file="$config".yml
6 cidfile=cids/"$config".cid
7 cidbootstrap=cids/"$config"_boostrap.cid
8 image=samsaffron/discourse
9 docker_path=`which docker`
12 echo "Usage: launcher COMMAND CONFIG"
14 echo " start: Start/initialize a container"
15 echo " stop: Stop a running container"
16 echo " restart: Restart a container"
17 echo " destroy: Stop and remove a container"
18 echo " ssh: Start a bash shell in a running container"
19 echo " logs: Docker logs for container"
20 echo " bootstrap: Bootstrap a container for the config base on an image"
26 echo "Docker is not installed, make sure you are running on the 3.8 kernel"
27 echo "The best supported Docker release is Ubuntu 12.04.03 for it run the following"
29 echo "sudo apt-get update"
30 echo "sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring"
34 echo "sudo sh -c \"wget -qO- https://get.docker.io/gpg | apt-key add -\""
35 echo "sudo sh -c \"echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list\""
36 echo "sudo apt-get update"
37 echo "sudo apt-get install lxc-docker"
43 volumes=`cat $config_file | docker run -rm -i -a stdout -a stdin samsaffron/discourse ruby -e \
44 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['volumes'].map{|v| '-v ' << v['volume']['host'] << ':' << v['volume']['guest'] << ' '}.join"`
47 [ -z $docker_path ] && {
56 if [ ! -e $config_file ]
58 echo "Config file was not found, ensure $config_file exists"
65 read -r -d '' ruby <<RUBY
67 puts YAML.load(STDIN.readlines.join)["template"]
70 template=`cat $config_file| docker run -rm -i -a stdin -a stdout samsaffron/discourse ruby -e "$ruby"`
72 input=$(cat $config_file)
73 [ ! -z $template ] && {
74 input="$input _FILE_SEPERATOR_ $(cat $template)"
79 exec echo "$input" | docker run -cidfile $cidbootstrap -i -a stdin -a stdout -a stderr $volumes samsaffron/discourse /pups/bin/pups --stdin
81 docker commit `cat $cidbootstrap` samsaffron/discourse $config
82 docker rm `cat $cidbootstrap` && rm $cidbootstrap
93 address="`docker port $cid 22`"
94 split=(${address//:/ })
95 exec ssh root@${split[0]} -p ${split[1]}
105 docker stop -t 10 `cat $cidfile`
117 docker logs `cat $cidfile`
126 echo "No cid found, creating a new container"
127 ports=`cat $config_file | docker run -rm -i -a stdout -a stdin samsaffron/discourse ruby -e \
128 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| '-p ' << p.to_s << ' '}.join"`
132 docker run -name $config -cidfile $cidfile $ports -d $volumes samsaffron/discourse:$config /usr/bin/runsvdir -P /etc/service
135 echo "cid found, ensuring container is started"
136 docker start `cat $cidfile`
145 echo "destroying container $cidfile"
146 docker stop -t 10 `cat $cidfile`
147 docker rm `cat $cidfile` && rm $cidfile
150 echo "nothing to destroy cidfile does not exist"