X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=launcher;h=4e615927503187c33d970fc27142d7ad0238e080;hb=2f7a204e0ed810526dc792c1ac00d508766e03a0;hp=bf7b9f1870e04c8475c8e6e522cea240a4cb63b2;hpb=fa9acf1a5847be7df47f550f7a3b2556bedaa340;p=discourse_docker.git diff --git a/launcher b/launcher index bf7b9f1..4e61592 100755 --- a/launcher +++ b/launcher @@ -13,6 +13,7 @@ usage () { echo " run: Run the given command with the config in the context of the last bootstrapped image" echo " rebuild: Rebuild a container (destroy old, bootstrap, start new)" echo " cleanup: Remove all containers that have stopped for > 24 hours" + echo " start-cmd: Generate docker command used to start container" echo echo "Options:" echo " --skip-prereqs Don't check launcher prerequisites" @@ -80,8 +81,8 @@ git_rec_version='1.8.0' config_file=containers/"$config".yml cidbootstrap=cids/"$config"_bootstrap.cid local_discourse=local_discourse -image=discourse/base:2.0.20181031 -docker_path=`which docker.io || which docker` +image="discourse/base:2.0.20190321-0122" +docker_path=`which docker.io 2> /dev/null || which docker` git_path=`which git` if [ "${SUPERVISED}" = "true" ]; then @@ -226,7 +227,7 @@ check_prereqs() { echo if [[ $REPLY =~ ^[Yy]$ ]] then - docker system prune + $docker_path system prune -af echo "If the cleanup was successful, you may try again now" fi exit 1 @@ -425,7 +426,7 @@ RUBY p e end end - puts ports.map {|p| "-p\n#{p}"}.join("\n") + puts ports.map { |p| p.to_s.include?(':') ? "-p\n#{p}" : "--expose\n#{p}" }.join("\n") RUBY tmp_input_file=$(mktemp) @@ -450,6 +451,8 @@ RUBY echo "YAML syntax error. Please check your containers/*.yml config files." exit 1 fi + + merge_user_args } if [ -z $docker_path ]; then @@ -534,32 +537,43 @@ set_boot_command() { fi } +merge_user_args() { + local docker_args + + docker_args=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \ + "require 'yaml'; puts YAML.load(STDIN.readlines.join)['docker_args']"` + + if [[ -n "$docker_args" ]]; then + user_args="$user_args $docker_args" + fi +} + run_start() { - existing=`$docker_path ps | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'` - echo $existing - if [ ! -z $existing ] + if [ -z "$START_CMD_ONLY" ] then - echo "Nothing to do, your container has already started!" - exit 0 - fi + existing=`$docker_path ps | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'` + echo $existing + if [ ! -z $existing ] + then + echo "Nothing to do, your container has already started!" + exit 0 + fi - existing=`$docker_path ps -a | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'` - if [ ! -z $existing ] - then - echo "starting up existing container" - ( - set -x - $docker_path start $config - ) - exit 0 + existing=`$docker_path ps -a | awk '{ print $1, $(NF) }' | grep " $config$" | awk '{ print $1 }'` + if [ ! -z $existing ] + then + echo "starting up existing container" + ( + set -x + $docker_path start $config + ) + exit 0 + fi fi host_run - docker_args=`cat $config_file | $docker_path run $user_args --rm -i -a stdout -a stdin $image ruby -e \ - "require 'yaml'; puts YAML.load(STDIN.readlines.join)['docker_args']"` - set_template_info set_volumes set_links @@ -596,9 +610,14 @@ run_start() { mac_address="--mac-address $($docker_path run $user_args -i --rm -a stdout -a stderr $image /bin/sh -c "echo $hostname | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/'")" fi + if [ ! -z "$START_CMD_ONLY" ] ; then + docker_path="true" + fi + set -x + $docker_path run --shm-size=512m $links $attach_on_run $restart_policy "${env[@]}" "${labels[@]}" -h "$hostname" \ - -e DOCKER_HOST_IP="$docker_ip" --name $config -t "${ports[@]}" $volumes $mac_address $docker_args $user_args \ + -e DOCKER_HOST_IP="$docker_ip" --name $config -t "${ports[@]}" $volumes $mac_address $user_args \ $run_image $boot_command ) @@ -724,6 +743,12 @@ case "$command" in exit 0 ;; + start-cmd) + START_CMD_ONLY="1" + run_start + exit 0; + ;; + start) run_start exit 0