5 config_file
=containers
/"$config".yml
6 cidfile
=cids
/"$config".cid
7 cidbootstrap
=cids
/"$config"_boostrap.cid
8 local_discourse
=local_discourse
9 image
=samsaffron
/discourse
10 docker_path
=`which docker`
13 echo "Usage: launcher COMMAND CONFIG"
15 echo " start: Start/initialize a container"
16 echo " stop: Stop a running container"
17 echo " restart: Restart a container"
18 echo " destroy: Stop and remove a container"
19 echo " ssh: Start a bash shell in a running container"
20 echo " logs: Docker logs for container"
21 echo " bootstrap: Bootstrap a container for the config based on a template"
27 echo "Docker is not installed, make sure you are running on the 3.8 kernel"
28 echo "The best supported Docker release is Ubuntu 12.04.03 for it run the following"
30 echo "sudo apt-get update"
31 echo "sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring"
35 echo "sudo sh -c \"wget -qO- https://get.docker.io/gpg | apt-key add -\""
36 echo "sudo sh -c \"echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list\""
37 echo "sudo apt-get update"
38 echo "sudo apt-get install lxc-docker"
44 volumes
=`cat $config_file | docker run -rm -i -a stdout -a stdin $image ruby -e \
45 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['volumes'].map{|v| '-v ' << v['volume']['host'] << ':' << v['volume']['guest'] << ' '}.join"`
48 [ -z $docker_path ] && {
57 if [ ! -e $config_file ]
59 echo "Config file was not found, ensure $config_file exists"
66 templates
=`cat $config_file | docker run -rm -i -a stdin -a stdout $image ruby -e \
67 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['templates']"`
69 arrTemplates
=(${templates// / })
70 config_data
=$
(cat $config_file)
73 for template
in "${arrTemplates[@]}"
75 [ ! -z $template ] && {
76 input
="$input _FILE_SEPERATOR_ $(cat $template)"
80 # we always want our config file last so it takes priority
81 input
="$input _FILE_SEPERATOR_ $config_data"
87 (exec echo "$input" | docker run
-cidfile $cidbootstrap -i -a stdin
-a stdout
-a stderr
$volumes $image \
88 /bin
/bash
-c 'cd /pups && git pull && /pups/bin/pups --stdin') \
89 ||
(docker
rm `cat $cidbootstrap` && rm $cidbootstrap)
91 [ ! -e $cidbootstrap ] && echo "FAILED TO BOOTSTRAP" && exit 1
95 docker commit
`cat $cidbootstrap` $local_discourse/$config ||
echo 'FAILED TO COMMIT'
96 docker
rm `cat $cidbootstrap` && rm $cidbootstrap
98 echo "Successfully bootstrappd, to starup use ./launcher start $config"
109 address
="`docker port $cid 22`"
110 split=(${address//:/ })
111 exec ssh root@
${split[0]} -p ${split[1]}
121 docker stop
-t 10 `cat $cidfile`
133 docker logs
`cat $cidfile`
142 echo "No cid found, creating a new container"
143 ports
=`cat $config_file | docker run -rm -i -a stdout -a stdin $image ruby -e \
144 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| '-p ' << p.to_s << ' '}.join"`
148 docker run
-name $config -cidfile $cidfile $ports -d $volumes $local_discourse/$config /usr
/bin
/runsvdir
-P /etc
/service
151 echo "cid found, ensuring container is started"
152 docker start
`cat $cidfile`
161 echo "destroying container $cidfile"
162 docker stop
-t 10 `cat $cidfile`
163 docker
rm `cat $cidfile` && rm $cidfile
166 echo "nothing to destroy cidfile does not exist"