add a special env var DOCKER_HOST_IP to all images
[discourse_docker.git] / launcher
index 1031f14b2cb533564a068b55ad517bac3088f2c1..83a8e7a9011a69df30e2a68b2d01135b5675e013 100755 (executable)
--- a/launcher
+++ b/launcher
@@ -2,13 +2,20 @@
 
 command=$1
 config=$2
-config_file="$config".yml
+config_file=containers/"$config".yml
 cidfile=cids/"$config".cid
 cidbootstrap=cids/"$config"_boostrap.cid
 local_discourse=local_discourse
 image=samsaffron/discourse
 docker_path=`which docker`
 
+docker_ip=`/sbin/ifconfig | \
+                grep -B1 "inet addr" | \
+                awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' | \
+                grep docker0 | \
+                awk -F: '{ print $3 }';`
+
+
 usage () {
   echo "Usage: launcher COMMAND CONFIG"
   echo "Commands:"
@@ -18,7 +25,7 @@ usage () {
   echo "    destroy:    Stop and remove a container"
   echo "    ssh:        Start a bash shell in a running container"
   echo "    logs:       Docker logs for container"
-  echo "    bootstrap:  Bootstrap a container for the config base on an image"
+  echo "    bootstrap:  Bootstrap a container for the config based on a template"
   exit 1
 }
 
@@ -67,8 +74,8 @@ case "$command" in
         "require 'yaml'; puts YAML.load(STDIN.readlines.join)['templates']"`
 
       arrTemplates=(${templates// / })
-      input=$(cat $config_file)
-
+      config_data=$(cat $config_file)
+      input="hack: true"
 
       for template in "${arrTemplates[@]}"
       do
@@ -77,11 +84,14 @@ case "$command" in
         }
       done
 
+      # we always want our config file last so it takes priority
+      input="$input _FILE_SEPERATOR_ $config_data"
+
       set_volumes
 
       rm -f $cidbootstrap
 
-      (exec echo "$input" | docker run -cidfile $cidbootstrap -i -a stdin -a stdout -a stderr $volumes $image \
+      (exec echo "$input" | docker run -e DOCKER_HOST_IP=$docker_ip -cidfile $cidbootstrap -i -a stdin -a stdout -a stderr $volumes $image \
          /bin/bash -c 'cd /pups && git pull && /pups/bin/pups --stdin') \
          || (docker rm `cat $cidbootstrap` && rm $cidbootstrap)
 
@@ -142,7 +152,9 @@ case "$command" in
 
            set_volumes
 
-           docker run -name $config -cidfile $cidfile $ports -d $volumes $local_discourse/$config /usr/bin/runsvdir -P /etc/service
+           docker run -e DOCKER_HOST_IP=$docker_ip -name $config -cidfile $cidfile $ports \
+                      -d $volumes $local_discourse/$config /usr/bin/runsvdir -P /etc/service
+
            exit 0
          else
            echo "cid found, ensuring container is started"