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`
12 docker_ip
=`/sbin/ifconfig | \
13 grep -B1 "inet addr" | \
14 awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' | \
16 awk -F: '{ print $3 }';`
20 echo "Usage: launcher COMMAND CONFIG"
22 echo " start: Start/initialize a container"
23 echo " stop: Stop a running container"
24 echo " restart: Restart a container"
25 echo " destroy: Stop and remove a container"
26 echo " ssh: Start a bash shell in a running container"
27 echo " logs: Docker logs for container"
28 echo " bootstrap: Bootstrap a container for the config based on a template"
34 echo "Docker is not installed, make sure you are running on the 3.8 kernel"
35 echo "The best supported Docker release is Ubuntu 12.04.03 for it run the following"
37 echo "sudo apt-get update"
38 echo "sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring"
42 echo "sudo sh -c \"wget -qO- https://get.docker.io/gpg | apt-key add -\""
43 echo "sudo sh -c \"echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list\""
44 echo "sudo apt-get update"
45 echo "sudo apt-get install lxc-docker"
51 volumes
=`cat $config_file | docker run -rm -i -a stdout -a stdin $image ruby -e \
52 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['volumes'].map{|v| '-v ' << v['volume']['host'] << ':' << v['volume']['guest'] << ' '}.join"`
55 [ -z $docker_path ] && {
64 if [ ! -e $config_file ]
66 echo "Config file was not found, ensure $config_file exists"
73 templates
=`cat $config_file | docker run -rm -i -a stdin -a stdout $image ruby -e \
74 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['templates']"`
76 arrTemplates
=(${templates// / })
77 config_data
=$
(cat $config_file)
80 for template
in "${arrTemplates[@]}"
82 [ ! -z $template ] && {
83 input
="$input _FILE_SEPERATOR_ $(cat $template)"
87 # we always want our config file last so it takes priority
88 input
="$input _FILE_SEPERATOR_ $config_data"
94 (exec echo "$input" | docker run
-e DOCKER_HOST_IP
=$docker_ip -cidfile $cidbootstrap -i -a stdin
-a stdout
-a stderr
$volumes $image \
95 /bin
/bash
-c 'cd /pups && git pull && /pups/bin/pups --stdin') \
96 ||
(docker
rm `cat $cidbootstrap` && rm $cidbootstrap)
98 [ ! -e $cidbootstrap ] && echo "FAILED TO BOOTSTRAP" && exit 1
102 docker commit
`cat $cidbootstrap` $local_discourse/$config ||
echo 'FAILED TO COMMIT'
103 docker
rm `cat $cidbootstrap` && rm $cidbootstrap
105 echo "Successfully bootstrappd, to starup use ./launcher start $config"
116 address
="`docker port $cid 22`"
117 split=(${address//:/ })
118 exec ssh root@
${split[0]} -p ${split[1]}
128 docker stop
-t 10 `cat $cidfile`
140 docker logs
`cat $cidfile`
149 echo "No cid found, creating a new container"
150 ports
=`cat $config_file | docker run -rm -i -a stdout -a stdin $image ruby -e \
151 "require 'yaml'; puts YAML.load(STDIN.readlines.join)['expose'].map{|p| '-p ' << p.to_s << ' '}.join"`
155 docker run
-e DOCKER_HOST_IP
=$docker_ip -name $config -cidfile $cidfile $ports \
156 -d $volumes $local_discourse/$config /usr
/bin
/runsvdir
-P /etc
/service
160 echo "cid found, ensuring container is started"
161 docker start
`cat $cidfile`
170 echo "destroying container $cidfile"
171 docker stop
-t 10 `cat $cidfile`
172 docker
rm `cat $cidfile` && rm $cidfile
175 echo "nothing to destroy cidfile does not exist"