From: Sam Date: Wed, 2 Apr 2014 00:46:24 +0000 (+1100) Subject: Added a rebuild command to simplify rebuilding containers X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=680dd4ea7b220827ed93952c8238c4bccb585708;p=discourse_docker.git Added a rebuild command to simplify rebuilding containers --- diff --git a/launcher b/launcher index c536ea8..dbba133 100755 --- a/launcher +++ b/launcher @@ -26,6 +26,7 @@ usage () { echo " ssh: Start a bash shell in a running container" echo " logs: Docker logs for container" echo " bootstrap: Bootstrap a container for the config based on a template" + echo " rebuild: Rebuild a container (destroy old, bootstrap, start new)" exit 1 } @@ -238,52 +239,55 @@ run_start(){ } -case "$command" in - bootstrap) +run_bootstrap(){ + get_ssh_pub_key - get_ssh_pub_key + # Is the image available? + # If not, pull it here so the user is aware what's happening. + docker history $image >/dev/null 2>&1 || docker pull $image - # Is the image available? - # If not, pull it here so the user is aware what's happening. - docker history $image >/dev/null 2>&1 || docker pull $image + set_template_info - set_template_info + base_image=`cat $config_file | docker run --rm -i -a stdin -a stdout $image ruby -e \ + "require 'yaml'; puts YAML.load(STDIN.readlines.join)['base_image']"` - base_image=`cat $config_file | docker run --rm -i -a stdin -a stdout $image ruby -e \ - "require 'yaml'; puts YAML.load(STDIN.readlines.join)['base_image']"` + update_pups=`cat $config_file | docker run --rm -i -a stdin -a stdout $image ruby -e \ + "require 'yaml'; puts YAML.load(STDIN.readlines.join)['update_pups']"` - update_pups=`cat $config_file | docker run --rm -i -a stdin -a stdout $image ruby -e \ - "require 'yaml'; puts YAML.load(STDIN.readlines.join)['update_pups']"` + if [[ ! X"" = X"$base_image" ]]; then + image=$base_image + fi - if [[ ! X"" = X"$base_image" ]]; then - image=$base_image - fi + set_volumes - set_volumes + rm -f $cidbootstrap - rm -f $cidbootstrap + run_command="cd /pups &&" + if [[ ! "false" = $update_pups ]]; then + run_command="$run_command git pull &&" + fi + run_command="$run_command /pups/bin/pups --stdin" - run_command="cd /pups &&" - if [[ ! "false" = $update_pups ]]; then - run_command="$run_command git pull &&" - fi - run_command="$run_command /pups/bin/pups --stdin" + echo $run_command - echo $run_command + env=("${env[@]}" "-e" "SSH_PUB_KEY=$ssh_pub_key") - env=("${env[@]}" "-e" "SSH_PUB_KEY=$ssh_pub_key") + (exec echo "$input" | docker run "${env[@]}" -e DOCKER_HOST_IP=$docker_ip --cidfile $cidbootstrap -i -a stdin -a stdout -a stderr $volumes $image \ + /bin/bash -c "$run_command") \ + || (docker rm `cat $cidbootstrap` && rm $cidbootstrap) - (exec echo "$input" | docker run "${env[@]}" -e DOCKER_HOST_IP=$docker_ip --cidfile $cidbootstrap -i -a stdin -a stdout -a stderr $volumes $image \ - /bin/bash -c "$run_command") \ - || (docker rm `cat $cidbootstrap` && rm $cidbootstrap) + [ ! -e $cidbootstrap ] && echo "FAILED TO BOOTSTRAP" && exit 1 - [ ! -e $cidbootstrap ] && echo "FAILED TO BOOTSTRAP" && exit 1 + sleep 5 - sleep 5 + docker commit `cat $cidbootstrap` $local_discourse/$config || echo 'FAILED TO COMMIT' + docker rm `cat $cidbootstrap` && rm $cidbootstrap +} - docker commit `cat $cidbootstrap` $local_discourse/$config || echo 'FAILED TO COMMIT' - docker rm `cat $cidbootstrap` && rm $cidbootstrap +case "$command" in + bootstrap) + run_bootstrap echo "Successfully bootstrapped, to startup use ./launcher start $config" exit 0 ;; @@ -329,6 +333,24 @@ case "$command" in exit 0 ;; + rebuild) + if [ -e $cidfile ] + then + echo "Stopping old container" + docker stop -t 10 `cat $cidfile` + fi + + run_bootstrap + + if [ -e $cidfile ] + then + docker rm `cat $cidfile` && rm $cidfile + fi + + run_start + exit 0 + ;; + destroy) if [ -e $cidfile ]