From acead1c14d84880f76f9d7797e369de2c760af2c Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Fri, 4 Nov 2016 14:04:10 -0700 Subject: [PATCH 01/19] Testing new dock init --- dock_init.sh | 18 +++++++++++++++++ init.sh | 55 +++++++++++++++----------------------------------- lib/upstart.sh | 19 +++++++++++++++++ util/run.sh | 6 +++--- 4 files changed, 56 insertions(+), 42 deletions(-) create mode 100644 dock_init.sh diff --git a/dock_init.sh b/dock_init.sh new file mode 100644 index 0000000..19f043b --- /dev/null +++ b/dock_init.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# new bash first init script + +export DOCK_INIT_BASE=/opt/runnable/dock-init +source "${DOCK_INIT_BASE}/util/run.sh" +source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" +source "${DOCK_INIT_BASE}/lib/consul.sh" +source "${DOCK_INIT_BASE}/lib/dock.sh" +source "${DOCK_INIT_BASE}/lib/upstart.sh" + +# Setup the exit trap and rollbar +dock::cleanup::set_exit_trap +rollbar::init +consul::connect +consul::get_environment +consul::configure_consul_template + +upstart::start diff --git a/init.sh b/init.sh index 6dc5c45..8843c52 100644 --- a/init.sh +++ b/init.sh @@ -10,9 +10,7 @@ # @author Ryan Sandor Richards export DOCK_INIT_BASE=/opt/runnable/dock-init -export CONSUL_HOSTNAME export HOST_IP=$(hostname -i) -export environment="" if [ -z "${CONSUL_PORT+x}" ]; then export CONSUL_PORT=8500 @@ -21,46 +19,25 @@ else fi source "${DOCK_INIT_BASE}/lib/consul.sh" +source "${DOCK_INIT_BASE}/lib/aws.sh" +source "${DOCK_INIT_BASE}/lib/dock.sh" +source "${DOCK_INIT_BASE}/lib/container.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" -source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -source "${DOCK_INIT_BASE}/lib/util/backoff.sh" - -# Executes a command using an ssh agent with the id_rsa_runnabledock key -# @param $1 action Comand to execute -ssh_execute() { - local action="$1" - ssh-agent bash -c "ssh-add key/id_rsa_runnabledock; $action" -} - -# Automatically updates dock-init to the version given in consul, if needed. -# After consul has been updated this executes the main script. -auto_update() { - log::info "Updating dock-init" - consul::connect - - log::trace 'Fetching dock-init version from consul...' - local version=$(consul::get '/dock-init/version') - log::info "dock-init version found: $version" - - log::trace "moving to dock init base directory ($DOCK_INIT_BASE)" - cd "$DOCK_INIT_BASE" - - log::trace "fetching all from repository" - if [[ "$FETCH_ORIGIN_ALL" != "" ]]; then - ssh_execute "git fetch origin $version" - else - ssh_execute "git fetch origin" - fi - - log::info "Checking out dock-init version: $version" - ssh_execute "git checkout $version" -} # Initializes the dock main() { - source "${DOCK_INIT_BASE}/lib/dock.sh" - dock::init + consul::connect + consul::get_environment + consul::configure_consul_template + aws::get_org_id + dock::set_hostname + dock::set_config_org + dock::generate_certs + dock::generate_etc_hosts + dock::set_registry_host + dock::remove_docker_key_file + container::start + log::info "Init Done!" } -# Attempt to auto-update then initialize the dock -backoff auto_update && main +main diff --git a/lib/upstart.sh b/lib/upstart.sh index 03f97a3..3e3d89d 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -10,6 +10,9 @@ source "${DOCK_INIT_BASE}/lib/util/backoff.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" +export SWARM_VERSION="latest" +export REGISTRY_VERSION="latest" + # Generates upstart scripts for the dock upstart::generate_scripts() { log::info "Generating Upstart Scripts" @@ -148,6 +151,20 @@ upstart::pull_image_builder() { fi } +# Pulls the docker registry container +upstart::pull_registry_container() { + local version="${REGISTRY_VERSION}" + log::info "Pull registry:latest container" + docker pull "registry:${latest}" +} + +# Pulls the docker swarm container +upstart::pull_swarm_container() { + local version="${SWARM_VERSION}" + log::info "Pull swarm:${version} container" + docker pull "swarm:${version}" +} + # Starts all services needed for the dock upstart::start() { log::info "Upstarting dock" @@ -155,6 +172,8 @@ upstart::start() { upstart::start_docker backoff upstart::pull_image_builder backoff upstart::upstart_services_with_backoff_params + upstart::pull_registry_container + upstart::pull_swarm_container } # Stops all dock services diff --git a/util/run.sh b/util/run.sh index 1b26d8b..8f7e0e8 100755 --- a/util/run.sh +++ b/util/run.sh @@ -12,8 +12,8 @@ export LOG_LEVEL=trace export FETCH_ORIGIN_ALL=true # Stop any already running services from a previous test -source ./lib/upstart.sh -upstart::stop +# source ./lib/upstart.sh +# upstart::stop # Run the dock start script -bash /opt/runnable/dock-init/init.sh +# bash /opt/runnable/dock-init/init.sh From cfab4f470398dacf0555f55e34fe9199e7e46d4a Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Fri, 4 Nov 2016 17:45:44 -0700 Subject: [PATCH 02/19] More edits --- lib/container.sh | 7 +++++-- lib/dock_init.sh | 18 ++++++++++++++++++ lib/upstart.sh | 6 +++--- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 lib/dock_init.sh diff --git a/lib/container.sh b/lib/container.sh index 75312d8..c33d13a 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -9,10 +9,13 @@ source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" source "${DOCK_INIT_BASE}/lib/vault.sh" +export REGISTRY_VERSION=2.3.1 +export SWARM_VERSION=1.2.0 + # Starts the docker swarm container container::_start_swarm_container() { local name="swarm" - local version="$(consul::get ${name}/version)" + local version="${SWARM_VERSION}" log::info "Starting swarm:${version} container" local docker_logs @@ -35,7 +38,7 @@ container::_start_swarm_container() { # Starts the docker registry container container::_start_registry_container() { local name="registry" - local version="$(consul::get ${name}/version)" + local version="${REGISTRY_VERSION}" log::info "Starting registry:${version} container" local region="$(consul::get s3/region)" diff --git a/lib/dock_init.sh b/lib/dock_init.sh new file mode 100644 index 0000000..19f043b --- /dev/null +++ b/lib/dock_init.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# new bash first init script + +export DOCK_INIT_BASE=/opt/runnable/dock-init +source "${DOCK_INIT_BASE}/util/run.sh" +source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" +source "${DOCK_INIT_BASE}/lib/consul.sh" +source "${DOCK_INIT_BASE}/lib/dock.sh" +source "${DOCK_INIT_BASE}/lib/upstart.sh" + +# Setup the exit trap and rollbar +dock::cleanup::set_exit_trap +rollbar::init +consul::connect +consul::get_environment +consul::configure_consul_template + +upstart::start diff --git a/lib/upstart.sh b/lib/upstart.sh index 3e3d89d..aa02f0a 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -10,8 +10,8 @@ source "${DOCK_INIT_BASE}/lib/util/backoff.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -export SWARM_VERSION="latest" -export REGISTRY_VERSION="latest" +export REGISTRY_VERSION=2.3.1 +export SWARM_VERSION=1.2.0 # Generates upstart scripts for the dock upstart::generate_scripts() { @@ -155,7 +155,7 @@ upstart::pull_image_builder() { upstart::pull_registry_container() { local version="${REGISTRY_VERSION}" log::info "Pull registry:latest container" - docker pull "registry:${latest}" + docker pull "registry:${version}" } # Pulls the docker swarm container From 057be97e9e6e74674c9b95e772ba0f5cc08f030e Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Mon, 7 Nov 2016 15:16:23 -0800 Subject: [PATCH 03/19] Working builds --- init.sh | 4 ---- lib/container.sh | 3 +++ lib/dock_init.sh | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/init.sh b/init.sh index 8843c52..6c2b106 100644 --- a/init.sh +++ b/init.sh @@ -32,10 +32,6 @@ main() { aws::get_org_id dock::set_hostname dock::set_config_org - dock::generate_certs - dock::generate_etc_hosts - dock::set_registry_host - dock::remove_docker_key_file container::start log::info "Init Done!" } diff --git a/lib/container.sh b/lib/container.sh index c33d13a..f4fa9e7 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -74,6 +74,9 @@ container::_start_registry_container() { # Starts all container services needed for the dock container::start() { log::info "Starting container services" + service docker stop + rm /var/run/docker.pid + service docker start backoff container::_start_registry_container # swarm should be started last so we know everything is up backoff container::_start_swarm_container diff --git a/lib/dock_init.sh b/lib/dock_init.sh index 19f043b..d9e44e0 100644 --- a/lib/dock_init.sh +++ b/lib/dock_init.sh @@ -2,6 +2,7 @@ # new bash first init script export DOCK_INIT_BASE=/opt/runnable/dock-init +export HOST_IP=$(hostname -i) source "${DOCK_INIT_BASE}/util/run.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" source "${DOCK_INIT_BASE}/lib/consul.sh" @@ -14,5 +15,6 @@ rollbar::init consul::connect consul::get_environment consul::configure_consul_template - +dock::remove_docker_key_file +dock::generate_certs upstart::start From 20ff5b521035c104248ad30e3ec41379fc199062 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Mon, 7 Nov 2016 16:35:02 -0800 Subject: [PATCH 04/19] Let dock.sh do all of the work --- lib/dock.sh | 8 ++--- lib/dock_init.sh | 76 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/lib/dock.sh b/lib/dock.sh index fdb1b6c..6e868ab 100644 --- a/lib/dock.sh +++ b/lib/dock.sh @@ -110,18 +110,14 @@ dock::init() { consul::connect consul::get_environment consul::configure_consul_template - aws::get_org_id # Now that we have everything we need and consul is ready, initialize the dock - dock::set_hostname - dock::set_config_org - dock::generate_certs dock::generate_etc_hosts dock::set_registry_host dock::remove_docker_key_file + dock::generate_certs upstart::start - container::start # Give the all clear message! - log::info "Init Done!" + log::info "Dock Pool Init Done!" } diff --git a/lib/dock_init.sh b/lib/dock_init.sh index d9e44e0..6dc5c45 100644 --- a/lib/dock_init.sh +++ b/lib/dock_init.sh @@ -1,20 +1,66 @@ #!/bin/bash -# new bash first init script + +# Entry-point script for dock initialization. Simply includes the `lib/dock.sh` +# library and calls the master initialization function. +# +# NOTE This script will automatically update the `lib/` directory before +# the dock is initialized. This means that this script itself will not be +# automatically updated. To do so a new AMI must be baked. +# +# @author Ryan Sandor Richards export DOCK_INIT_BASE=/opt/runnable/dock-init +export CONSUL_HOSTNAME export HOST_IP=$(hostname -i) -source "${DOCK_INIT_BASE}/util/run.sh" -source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" +export environment="" + +if [ -z "${CONSUL_PORT+x}" ]; then + export CONSUL_PORT=8500 +else + export CONSUL_PORT +fi + source "${DOCK_INIT_BASE}/lib/consul.sh" -source "${DOCK_INIT_BASE}/lib/dock.sh" -source "${DOCK_INIT_BASE}/lib/upstart.sh" - -# Setup the exit trap and rollbar -dock::cleanup::set_exit_trap -rollbar::init -consul::connect -consul::get_environment -consul::configure_consul_template -dock::remove_docker_key_file -dock::generate_certs -upstart::start +source "${DOCK_INIT_BASE}/lib/util/log.sh" +source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" +source "${DOCK_INIT_BASE}/lib/util/backoff.sh" + +# Executes a command using an ssh agent with the id_rsa_runnabledock key +# @param $1 action Comand to execute +ssh_execute() { + local action="$1" + ssh-agent bash -c "ssh-add key/id_rsa_runnabledock; $action" +} + +# Automatically updates dock-init to the version given in consul, if needed. +# After consul has been updated this executes the main script. +auto_update() { + log::info "Updating dock-init" + consul::connect + + log::trace 'Fetching dock-init version from consul...' + local version=$(consul::get '/dock-init/version') + log::info "dock-init version found: $version" + + log::trace "moving to dock init base directory ($DOCK_INIT_BASE)" + cd "$DOCK_INIT_BASE" + + log::trace "fetching all from repository" + if [[ "$FETCH_ORIGIN_ALL" != "" ]]; then + ssh_execute "git fetch origin $version" + else + ssh_execute "git fetch origin" + fi + + log::info "Checking out dock-init version: $version" + ssh_execute "git checkout $version" +} + +# Initializes the dock +main() { + source "${DOCK_INIT_BASE}/lib/dock.sh" + dock::init +} + +# Attempt to auto-update then initialize the dock +backoff auto_update && main From a6338fb01d930c6f148dd23bc4ef6a9b442b0910 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Mon, 7 Nov 2016 19:02:46 -0800 Subject: [PATCH 05/19] Changes to not terminate --- lib/dock_init.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/dock_init.sh b/lib/dock_init.sh index 6dc5c45..9444a00 100644 --- a/lib/dock_init.sh +++ b/lib/dock_init.sh @@ -10,9 +10,13 @@ # @author Ryan Sandor Richards export DOCK_INIT_BASE=/opt/runnable/dock-init -export CONSUL_HOSTNAME +export CONSUL_HOSTNAME=10.4.5.144 export HOST_IP=$(hostname -i) -export environment="" +export CONSUL_PORT=8500 +export DONT_DELETE_KEYS=true +export USE_EXIT=true +export LOG_LEVEL=trace +export FETCH_ORIGIN_ALL=true if [ -z "${CONSUL_PORT+x}" ]; then export CONSUL_PORT=8500 From 9ed5ba782f95a4d4d5e08e52ee394ab8d469d792 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Tue, 8 Nov 2016 11:23:43 -0800 Subject: [PATCH 06/19] Adding cadvisor and node-exporter --- lib/container.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++---- lib/upstart.sh | 26 +++++++------------ 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/lib/container.sh b/lib/container.sh index f4fa9e7..9792459 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -9,13 +9,10 @@ source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" source "${DOCK_INIT_BASE}/lib/vault.sh" -export REGISTRY_VERSION=2.3.1 -export SWARM_VERSION=1.2.0 - # Starts the docker swarm container container::_start_swarm_container() { local name="swarm" - local version="${SWARM_VERSION}" + local version="$(consul::get ${name}/version)" log::info "Starting swarm:${version} container" local docker_logs @@ -38,7 +35,7 @@ container::_start_swarm_container() { # Starts the docker registry container container::_start_registry_container() { local name="registry" - local version="${REGISTRY_VERSION}" + local version="$(consul::get ${name}/version)" log::info "Starting registry:${version} container" local region="$(consul::get s3/region)" @@ -71,6 +68,62 @@ container::_start_registry_container() { fi } +container::_start_cadvisor_container() { + local name="google/cadvisor" + local version="$(consul::get ${name}/version)" + + log::info "Starting ${name}:${version} container" + local docker_logs + docker_logs=$(docker run \ + --name=cadvisor \ + --detach=true \ + --restart=always \ + --volume=/:/rootfs:ro \ + --volume=/var/run:/var/run:rw \ + --volume=/sys:/sys:ro \ + --volume=/var/lib/docker/:/var/lib/docker:ro \ + --publish=29007:8080 \ + --memory=100mb \ + --memory-reservation=50mb \ + "${name}:${version}") + + if [[ "$?" -gt "0" ]]; then + local data='{"version":'"${version}"', "output":'"${docker_logs}"'}' + rollbar::report_error \ + "Dock-Init: Cannot Run ${name} Container" \ + "Starting ${name} Container is failing." \ + "${data}" + return 1 + fi +} + +container::_start_node_exporter_container() { + local name="prom/node-exporter" + local version="$(consul::get ${name}/version)" + + log::info "Starting ${name}:${version} container" + local docker_logs + docker_logs=$(docker run \ + --name=node-exporter \ + --detach=true \ + --restart=always \ + --net=host \ + --memory=100mb \ + --memory-reservation=50mb \ + "${name}:${version}" \ + --collectors.enabled=conntrack,diskstats,filefd,filesystem,loadavg,meminfo,netdev,netstat,stat,time \ + --web.listen-address=:29006) + + if [[ "$?" -gt "0" ]]; then + local data='{"version":'"${version}"', "output":'"${docker_logs}"'}' + rollbar::report_error \ + "Dock-Init: Cannot Run ${name} Container" \ + "Starting ${name} Container is failing." \ + "${data}" + return 1 + fi +} + # Starts all container services needed for the dock container::start() { log::info "Starting container services" @@ -78,6 +131,9 @@ container::start() { rm /var/run/docker.pid service docker start backoff container::_start_registry_container + backoff container::_start_cadvisor_container + backoff container::_start_node_exporter_container + # swarm should be started last so we know everything is up backoff container::_start_swarm_container } @@ -87,4 +143,5 @@ container::stop() { log::info "Stopping all dock container services" docker ps | awk '/swarm/ { print $1 }' | xargs docker kill docker ps | awk '/registry/ { print $1 }' | xargs docker kill + docker ps | awk '/cadvisor/ { print $1 }' | xargs docker kill } diff --git a/lib/upstart.sh b/lib/upstart.sh index aa02f0a..e3b551f 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -10,9 +10,6 @@ source "${DOCK_INIT_BASE}/lib/util/backoff.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -export REGISTRY_VERSION=2.3.1 -export SWARM_VERSION=1.2.0 - # Generates upstart scripts for the dock upstart::generate_scripts() { log::info "Generating Upstart Scripts" @@ -151,18 +148,11 @@ upstart::pull_image_builder() { fi } -# Pulls the docker registry container -upstart::pull_registry_container() { - local version="${REGISTRY_VERSION}" - log::info "Pull registry:latest container" - docker pull "registry:${version}" -} - -# Pulls the docker swarm container -upstart::pull_swarm_container() { - local version="${SWARM_VERSION}" - log::info "Pull swarm:${version} container" - docker pull "swarm:${version}" +upstart::pull_docker_image() { + local name="${1}" + local version="$(consul::get $name/version)" + log::info "Pull ${name}:latest container" + docker pull "${name}:${version}" } # Starts all services needed for the dock @@ -172,8 +162,10 @@ upstart::start() { upstart::start_docker backoff upstart::pull_image_builder backoff upstart::upstart_services_with_backoff_params - upstart::pull_registry_container - upstart::pull_swarm_container + upstart::pull_docker_container registry + upstart::pull_docker_container swarm + upstart::pull_docker_container google/cadvisor + upstart::pull_docker_container prom/node-exporter } # Stops all dock services From f51afa325e10b338cc79d2241d85f40c1854544a Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Tue, 8 Nov 2016 17:05:40 -0800 Subject: [PATCH 07/19] testing --- lib/upstart.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/upstart.sh b/lib/upstart.sh index e3b551f..61f43c8 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -162,10 +162,10 @@ upstart::start() { upstart::start_docker backoff upstart::pull_image_builder backoff upstart::upstart_services_with_backoff_params - upstart::pull_docker_container registry - upstart::pull_docker_container swarm - upstart::pull_docker_container google/cadvisor - upstart::pull_docker_container prom/node-exporter + upstart::pull_docker_image registry + upstart::pull_docker_image swarm + upstart::pull_docker_image google/cadvisor + upstart::pull_docker_image prom/node-exporter } # Stops all dock services From dcd7db3c4bb592ebcd0538628f4ae5015ab6e30d Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Fri, 11 Nov 2016 09:43:12 -0800 Subject: [PATCH 08/19] Ready for primetime --- init.sh | 1 + lib/container.sh | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/init.sh b/init.sh index 6c2b106..116ccb4 100644 --- a/init.sh +++ b/init.sh @@ -29,6 +29,7 @@ main() { consul::connect consul::get_environment consul::configure_consul_template + dock::generate_certs aws::get_org_id dock::set_hostname dock::set_config_org diff --git a/lib/container.sh b/lib/container.sh index 9792459..c062245 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -127,8 +127,6 @@ container::_start_node_exporter_container() { # Starts all container services needed for the dock container::start() { log::info "Starting container services" - service docker stop - rm /var/run/docker.pid service docker start backoff container::_start_registry_container backoff container::_start_cadvisor_container From eac6af73f0d136b238e60b4365a1be9cdb66d347 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Fri, 11 Nov 2016 14:16:57 -0800 Subject: [PATCH 09/19] Lets go --- init.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/init.sh b/init.sh index 116ccb4..2b8a893 100644 --- a/init.sh +++ b/init.sh @@ -10,7 +10,13 @@ # @author Ryan Sandor Richards export DOCK_INIT_BASE=/opt/runnable/dock-init +export CONSUL_HOSTNAME=10.4.5.144 export HOST_IP=$(hostname -i) +export CONSUL_PORT=8500 +export DONT_DELETE_KEYS=true +export USE_EXIT=true +export LOG_LEVEL=trace +export FETCH_ORIGIN_ALL=true if [ -z "${CONSUL_PORT+x}" ]; then export CONSUL_PORT=8500 From e09ea25cb732e857a827a6d1bc50bfe315167aca Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Fri, 11 Nov 2016 18:32:16 -0800 Subject: [PATCH 10/19] Sleep --- lib/container.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/container.sh b/lib/container.sh index c062245..213edb2 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -128,6 +128,7 @@ container::_start_node_exporter_container() { container::start() { log::info "Starting container services" service docker start + sleep 5 backoff container::_start_registry_container backoff container::_start_cadvisor_container backoff container::_start_node_exporter_container From 8e06fd78fa8358355683d6273e7190b3f524c294 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Mon, 14 Nov 2016 11:08:17 -0800 Subject: [PATCH 11/19] Removed dock_init, restarting swarm --- dock_init.sh | 18 ------------------ lib/container.sh | 3 ++- 2 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 dock_init.sh diff --git a/dock_init.sh b/dock_init.sh deleted file mode 100644 index 19f043b..0000000 --- a/dock_init.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# new bash first init script - -export DOCK_INIT_BASE=/opt/runnable/dock-init -source "${DOCK_INIT_BASE}/util/run.sh" -source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -source "${DOCK_INIT_BASE}/lib/consul.sh" -source "${DOCK_INIT_BASE}/lib/dock.sh" -source "${DOCK_INIT_BASE}/lib/upstart.sh" - -# Setup the exit trap and rollbar -dock::cleanup::set_exit_trap -rollbar::init -consul::connect -consul::get_environment -consul::configure_consul_template - -upstart::start diff --git a/lib/container.sh b/lib/container.sh index 213edb2..8d93505 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -128,13 +128,14 @@ container::_start_node_exporter_container() { container::start() { log::info "Starting container services" service docker start - sleep 5 + sleep 10 backoff container::_start_registry_container backoff container::_start_cadvisor_container backoff container::_start_node_exporter_container # swarm should be started last so we know everything is up backoff container::_start_swarm_container + docker ps | awk '/swarm/ { print $1 }' | xargs docker restart } # Stops all dock container services From 31e33b3460017c97a4b1f1ca255f67eecd18de29 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Tue, 15 Nov 2016 19:10:44 -0800 Subject: [PATCH 12/19] Added regular interval checks for docker running --- init.sh | 9 +++++++-- lib/container.sh | 4 ++-- lib/upstart.sh | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/init.sh b/init.sh index 2b8a893..59db22c 100644 --- a/init.sh +++ b/init.sh @@ -10,9 +10,7 @@ # @author Ryan Sandor Richards export DOCK_INIT_BASE=/opt/runnable/dock-init -export CONSUL_HOSTNAME=10.4.5.144 export HOST_IP=$(hostname -i) -export CONSUL_PORT=8500 export DONT_DELETE_KEYS=true export USE_EXIT=true export LOG_LEVEL=trace @@ -24,6 +22,12 @@ else export CONSUL_PORT fi +if [ -z "${CONSUL_HOSTNAME+x}" ]; then + export CONSUL_HOSTNAME=10.4.5.144 +else + export CONSUL_HOSTNAME +fi + source "${DOCK_INIT_BASE}/lib/consul.sh" source "${DOCK_INIT_BASE}/lib/aws.sh" source "${DOCK_INIT_BASE}/lib/dock.sh" @@ -35,6 +39,7 @@ main() { consul::connect consul::get_environment consul::configure_consul_template + backoff upstart::upstart_services_with_backoff_params dock::generate_certs aws::get_org_id dock::set_hostname diff --git a/lib/container.sh b/lib/container.sh index 8d93505..19f48d6 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -7,6 +7,7 @@ source "${DOCK_INIT_BASE}/lib/consul.sh" source "${DOCK_INIT_BASE}/lib/util/backoff.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" +source "${DOCK_INIT_BASE}/lib/upstart.sh" source "${DOCK_INIT_BASE}/lib/vault.sh" # Starts the docker swarm container @@ -127,8 +128,7 @@ container::_start_node_exporter_container() { # Starts all container services needed for the dock container::start() { log::info "Starting container services" - service docker start - sleep 10 + upstart::start_docker backoff container::_start_registry_container backoff container::_start_cadvisor_container backoff container::_start_node_exporter_container diff --git a/lib/upstart.sh b/lib/upstart.sh index 61f43c8..6b3562f 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -105,7 +105,7 @@ upstart::start_docker() { log::info "Waiting for Docker" local attempt=1 - local timeout=1 + local timeout=.5 while [ ! -e /var/run/docker.sock ] do log::info "Docker Sock N/A ($attempt)" @@ -115,7 +115,6 @@ upstart::start_docker() { rollbar::report_warning "${title}" "${message}" "$data" sleep $timeout attempt=$(( attempt + 1 )) - timeout=$(( timeout * 2 )) done } @@ -126,6 +125,7 @@ upstart::upstart_services_with_backoff_params() { upstart::upstart_named_service "krain" $attempt upstart::upstart_named_service "charon" $attempt upstart::upstart_service "datadog-agent" $attempt + upstart::upstart_service "docker" $attempt } # Pulls the latest docker image for the runnable image builder From 82b56d8a393579c6a7dc0f9f4eda309979af1d74 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Wed, 16 Nov 2016 10:55:46 -0800 Subject: [PATCH 13/19] Removed unnecessary test --- init.sh | 1 - test/upstart.sh | 19 ------------------- 2 files changed, 20 deletions(-) diff --git a/init.sh b/init.sh index 59db22c..43ffa68 100644 --- a/init.sh +++ b/init.sh @@ -39,7 +39,6 @@ main() { consul::connect consul::get_environment consul::configure_consul_template - backoff upstart::upstart_services_with_backoff_params dock::generate_certs aws::get_org_id dock::set_hostname diff --git a/test/upstart.sh b/test/upstart.sh index 18f8843..b1c6bc8 100644 --- a/test/upstart.sh +++ b/test/upstart.sh @@ -26,25 +26,6 @@ describe 'upstart.sh' rollbar::clear_trap::restore end - describe 'upstart::upstart_services_with_backoff_params' - it 'should start all our services' - local storage="" - serviceStub() { storage+="$@ "; } - stub::exec upstart::upstart_named_service serviceStub - stub::exec upstart::upstart_service serviceStub - - local attempt=8 - upstart::upstart_services_with_backoff_params $attempt - - local expected="krain 8 charon 8 datadog-agent 8 " - - assert equal "$expected" "$storage" - - upstart::upstart_named_service::restore - upstart::upstart_service::restore - end - end - describe 'upstart::pull_image_builder' local image_builder_version='v1.2.3' stub rollbar::report_warning From 58f1b15e8c5c3cd6490d031407f22493f31d9c34 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Thu, 17 Nov 2016 18:56:56 -0800 Subject: [PATCH 14/19] Cleaned up for PR --- lib/dock.sh | 8 ++++-- lib/dock_init.sh | 70 ------------------------------------------------ lib/upstart.sh | 12 --------- util/run.sh | 6 ++--- 4 files changed, 9 insertions(+), 87 deletions(-) delete mode 100644 lib/dock_init.sh diff --git a/lib/dock.sh b/lib/dock.sh index 6e868ab..fdb1b6c 100644 --- a/lib/dock.sh +++ b/lib/dock.sh @@ -110,14 +110,18 @@ dock::init() { consul::connect consul::get_environment consul::configure_consul_template + aws::get_org_id # Now that we have everything we need and consul is ready, initialize the dock + dock::set_hostname + dock::set_config_org + dock::generate_certs dock::generate_etc_hosts dock::set_registry_host dock::remove_docker_key_file - dock::generate_certs upstart::start + container::start # Give the all clear message! - log::info "Dock Pool Init Done!" + log::info "Init Done!" } diff --git a/lib/dock_init.sh b/lib/dock_init.sh deleted file mode 100644 index 9444a00..0000000 --- a/lib/dock_init.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash - -# Entry-point script for dock initialization. Simply includes the `lib/dock.sh` -# library and calls the master initialization function. -# -# NOTE This script will automatically update the `lib/` directory before -# the dock is initialized. This means that this script itself will not be -# automatically updated. To do so a new AMI must be baked. -# -# @author Ryan Sandor Richards - -export DOCK_INIT_BASE=/opt/runnable/dock-init -export CONSUL_HOSTNAME=10.4.5.144 -export HOST_IP=$(hostname -i) -export CONSUL_PORT=8500 -export DONT_DELETE_KEYS=true -export USE_EXIT=true -export LOG_LEVEL=trace -export FETCH_ORIGIN_ALL=true - -if [ -z "${CONSUL_PORT+x}" ]; then - export CONSUL_PORT=8500 -else - export CONSUL_PORT -fi - -source "${DOCK_INIT_BASE}/lib/consul.sh" -source "${DOCK_INIT_BASE}/lib/util/log.sh" -source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -source "${DOCK_INIT_BASE}/lib/util/backoff.sh" - -# Executes a command using an ssh agent with the id_rsa_runnabledock key -# @param $1 action Comand to execute -ssh_execute() { - local action="$1" - ssh-agent bash -c "ssh-add key/id_rsa_runnabledock; $action" -} - -# Automatically updates dock-init to the version given in consul, if needed. -# After consul has been updated this executes the main script. -auto_update() { - log::info "Updating dock-init" - consul::connect - - log::trace 'Fetching dock-init version from consul...' - local version=$(consul::get '/dock-init/version') - log::info "dock-init version found: $version" - - log::trace "moving to dock init base directory ($DOCK_INIT_BASE)" - cd "$DOCK_INIT_BASE" - - log::trace "fetching all from repository" - if [[ "$FETCH_ORIGIN_ALL" != "" ]]; then - ssh_execute "git fetch origin $version" - else - ssh_execute "git fetch origin" - fi - - log::info "Checking out dock-init version: $version" - ssh_execute "git checkout $version" -} - -# Initializes the dock -main() { - source "${DOCK_INIT_BASE}/lib/dock.sh" - dock::init -} - -# Attempt to auto-update then initialize the dock -backoff auto_update && main diff --git a/lib/upstart.sh b/lib/upstart.sh index 6b3562f..47028e7 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -125,7 +125,6 @@ upstart::upstart_services_with_backoff_params() { upstart::upstart_named_service "krain" $attempt upstart::upstart_named_service "charon" $attempt upstart::upstart_service "datadog-agent" $attempt - upstart::upstart_service "docker" $attempt } # Pulls the latest docker image for the runnable image builder @@ -148,13 +147,6 @@ upstart::pull_image_builder() { fi } -upstart::pull_docker_image() { - local name="${1}" - local version="$(consul::get $name/version)" - log::info "Pull ${name}:latest container" - docker pull "${name}:${version}" -} - # Starts all services needed for the dock upstart::start() { log::info "Upstarting dock" @@ -162,10 +154,6 @@ upstart::start() { upstart::start_docker backoff upstart::pull_image_builder backoff upstart::upstart_services_with_backoff_params - upstart::pull_docker_image registry - upstart::pull_docker_image swarm - upstart::pull_docker_image google/cadvisor - upstart::pull_docker_image prom/node-exporter } # Stops all dock services diff --git a/util/run.sh b/util/run.sh index 8f7e0e8..1b26d8b 100755 --- a/util/run.sh +++ b/util/run.sh @@ -12,8 +12,8 @@ export LOG_LEVEL=trace export FETCH_ORIGIN_ALL=true # Stop any already running services from a previous test -# source ./lib/upstart.sh -# upstart::stop +source ./lib/upstart.sh +upstart::stop # Run the dock start script -# bash /opt/runnable/dock-init/init.sh +bash /opt/runnable/dock-init/init.sh From 699e62fca564b90bf486edc37c194fca100e61bd Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Mon, 21 Nov 2016 16:17:17 -0800 Subject: [PATCH 15/19] Remove unused and disastrous function declaration --- lib/upstart.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/upstart.sh b/lib/upstart.sh index 47028e7..87a9459 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -10,16 +10,6 @@ source "${DOCK_INIT_BASE}/lib/util/backoff.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -# Generates upstart scripts for the dock -upstart::generate_scripts() { - log::info "Generating Upstart Scripts" - rollbar::fatal_trap \ - "Dock-Init: Failed to Generate Upstart Script" \ - "Failed to generate the upstart scripts." - upstart::generate_scripts - rollbar::clear_trap -} - # Configures the template for a given service # @param $1 name Name of the service # @param $2 path Path to the servic From 32588a74373c52a345b82e664c06b41bfe9bc980 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Mon, 21 Nov 2016 17:11:00 -0800 Subject: [PATCH 16/19] Fixed test --- test/container.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/container.sh b/test/container.sh index 597b393..cdf7405 100644 --- a/test/container.sh +++ b/test/container.sh @@ -140,6 +140,8 @@ describe 'container.sh' stub container::_start_cadvisor_container stub container::_start_node_exporter_container stub container::_start_swarm_container + stub upstart::start_docker + stub docker it 'should start all required containers' container::start @@ -147,6 +149,7 @@ describe 'container.sh' container::_start_cadvisor_container::called container::_start_node_exporter_container::called container::_start_swarm_container::called + upstart::start_docker::called container::_start_registry_container::restore container::_start_cadvisor_container::restore From 22fa18aab747e0eca1f8ead756fa0469057b301d Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Tue, 22 Nov 2016 17:32:17 -0800 Subject: [PATCH 17/19] added comment to swarm restart command --- lib/container.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/container.sh b/lib/container.sh index ff13550..43f85b9 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -139,7 +139,10 @@ container::start() { # swarm should be started last so we know everything is up backoff container::_start_swarm_container - docker ps | awk '/swarm/ { print $1 }' | xargs docker restart + # currently @henrymollman does not understand why restarting swarm works + # but without this line docker-listener will time out getting events + # and the stream will close. this is an intermittent error however + docker restart swarm } # Stops all dock container services From a4c0b9b90003dcab055ab4876df6b869fb8fe5a5 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Tue, 22 Nov 2016 18:09:47 -0800 Subject: [PATCH 18/19] Ready for PR --- init.sh | 9 ---- lib/dock.sh | 84 --------------------------------- lib/upstart.sh | 122 ------------------------------------------------ test/upstart.sh | 63 ------------------------- 4 files changed, 278 deletions(-) delete mode 100644 test/upstart.sh diff --git a/init.sh b/init.sh index 43ffa68..fc874c8 100644 --- a/init.sh +++ b/init.sh @@ -2,19 +2,10 @@ # Entry-point script for dock initialization. Simply includes the `lib/dock.sh` # library and calls the master initialization function. -# -# NOTE This script will automatically update the `lib/` directory before -# the dock is initialized. This means that this script itself will not be -# automatically updated. To do so a new AMI must be baked. -# # @author Ryan Sandor Richards export DOCK_INIT_BASE=/opt/runnable/dock-init export HOST_IP=$(hostname -i) -export DONT_DELETE_KEYS=true -export USE_EXIT=true -export LOG_LEVEL=trace -export FETCH_ORIGIN_ALL=true if [ -z "${CONSUL_PORT+x}" ]; then export CONSUL_PORT=8500 diff --git a/lib/dock.sh b/lib/dock.sh index fdb1b6c..99074b8 100644 --- a/lib/dock.sh +++ b/lib/dock.sh @@ -9,38 +9,11 @@ # @author Bryan Kendall # @module dock -source "${DOCK_INIT_BASE}/lib/aws.sh" source "${DOCK_INIT_BASE}/lib/cert.sh" -source "${DOCK_INIT_BASE}/lib/consul.sh" -source "${DOCK_INIT_BASE}/lib/container.sh" -source "${DOCK_INIT_BASE}/lib/upstart.sh" - source "${DOCK_INIT_BASE}/lib/util/backoff.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -# An "on exit" trap to clean up sensitive keys and files on the dock itself. -# Note that this will have no effect if the `DONT_DELETE_KEYS` environment has -# been set (useful for testing) -dock::cleanup::exit_trap() { - # Delete the keys unless the `DO_NOT_DELETE` flag is set - if [[ "${DONT_DELETE_KEYS}" == "" ]]; then - log::info '[CLEANUP TRAP] Removing Keys' - rm -f "${CERT_PATH}"/ca-key.pem \ - "${CERT_PATH}"/pass \ - "${DOCK_INIT_BASE}"/consul-resources/template-config.hcl \ - "${DOCK_INIT_BASE}"/consul-resources/vault/**/auth-token \ - "${DOCK_INIT_BASE}"/consul-resources/vault/**/token-* \ - "${DOCK_INIT_BASE}"/key/rollbar.token - fi -} - -# Sets the cleanup trap for the entire script -dock::cleanup::set_exit_trap() { - log::info "Setting key cleanup trap" - trap 'dock::cleanup::exit_trap' EXIT -} - # Sets the value of `$ORG_ID` as the org label in the docker configuration dock::set_config_org() { log::info "Setting organization id in docker configuration" @@ -68,60 +41,3 @@ dock::generate_certs() { backoff dock::generate_certs_backoff } -# Generates the correct /etc/hosts file for the dock -dock::generate_etc_hosts() { - log::info "Generating /etc/hosts" - - rollbar::fatal_trap \ - "Dock-Init: Failed to Add Host Registry Entry" \ - "Consul-Template was unable to realize the registry template." - - local template='' - template+="$DOCK_INIT_BASE/consul-resources/templates/hosts-registry.ctmpl" - template+=":$DOCK_INIT_BASE/hosts-registry.txt" - consul-template \ - -config="${DOCK_INIT_BASE}"/consul-resources/template-config.hcl \ - -once \ - -template="${template}" - - rollbar::clear_trap -} - -# Sets the correct registry.runnable.com host -dock::set_registry_host() { - local registry_host=$(cat "$DOCK_INIT_BASE/hosts-registry.txt") - log::info "Set registry host: $registry_host" - echo "$registry_host" >> /etc/hosts -} - -# Remove docker key file so it generates a unique id -dock::remove_docker_key_file() { - log::info "Removing docker key.json" - rm -f /etc/docker/key.json -} - -# Master function for performing all tasks and initializing the dock -dock::init() { - # Setup the exit trap and rollbar - dock::cleanup::set_exit_trap - rollbar::init - - # Connect to and configure consul then collect various information we need - consul::connect - consul::get_environment - consul::configure_consul_template - aws::get_org_id - - # Now that we have everything we need and consul is ready, initialize the dock - dock::set_hostname - dock::set_config_org - dock::generate_certs - dock::generate_etc_hosts - dock::set_registry_host - dock::remove_docker_key_file - upstart::start - container::start - - # Give the all clear message! - log::info "Init Done!" -} diff --git a/lib/upstart.sh b/lib/upstart.sh index 87a9459..48c8483 100644 --- a/lib/upstart.sh +++ b/lib/upstart.sh @@ -5,85 +5,9 @@ # @author Ryan Sandor Richards # @author Bryan Kendall -source "${DOCK_INIT_BASE}/lib/consul.sh" -source "${DOCK_INIT_BASE}/lib/util/backoff.sh" source "${DOCK_INIT_BASE}/lib/util/log.sh" source "${DOCK_INIT_BASE}/lib/util/rollbar.sh" -# Configures the template for a given service -# @param $1 name Name of the service -# @param $2 path Path to the servic -upstart::configure_service() { - local name="${1}" - log::trace "Configuring $name" - rollbar::fatal_trap \ - "Consul-Template: Failed to Render $name Config" \ - "Consule-Template was unable to realize the given template." - - local template_path="$DOCK_INIT_BASE/consul-resources/templates/services" - template_path+="/$name.conf.ctmpl" - template_path+=":/etc/init/$name.conf" - - consul-template \ - -config="$DOCK_INIT_BASE/consul-resources/template-config.hcl" \ - -once \ - -template="$template_path" - echo "manual" > /etc/init/"$name".override - - rollbar::clear_trap -} - -# Generates upstart scripts for thoses services that require environment info -# from consul -upstart::generate_scripts() { - log::info "Configuring Upstart Scripts" - upstart::configure_service "charon" - log::trace "Done Generating Upstart Scripts" -} - -# Updates a service to the consul version, installs packages, then restarts it. -# @param $1 Name of the service -upstart::upstart_named_service() { - local name="${1}" - local attempt="${2}" - local data='{"attempt":'"${attempt}"'}' - local version="$(consul::get ${name}/version)" - local key_path="$DOCK_INIT_BASE/key/id_rsa_runnabledock" - - rollbar::warning_trap \ - "$name: Cannot Upstart Services" \ - "Attempting to upstart the services and failing." \ - "${data}" - - log::info "Updating and restarting $name @ $version" && - cd "/opt/runnable/$name" && - ssh-agent bash -c "ssh-add $key_path; git fetch origin" && - git checkout "$version" && - ssh-agent bash -c "ssh-add $key_path; USERPROFILE=/home/ubuntu npm install --production" && - service "$name" restart - - rollbar::clear_trap -} - -# Starts a service installed on the machine. -# @param $1 Name of the service -# @param $2 Attempt number -upstart::upstart_service() { - local name="${1}" - local attempt="${2}" - local data='{"attempt":'"${attempt}"'}' - - rollbar::warning_trap \ - "$name: Cannot Upstart Service" \ - "Attempting to upstart the service and failing." \ - "${data}" - - log::info "Starting $name" - service "$name" restart - - rollbar::clear_trap -} - # Start dockers (due to manual override now set in /etc/init) upstart::start_docker() { log::info "Starting Docker" @@ -107,49 +31,3 @@ upstart::start_docker() { attempt=$(( attempt + 1 )) done } - -# Upstarts services that are supposed to be running on the dock. -# @param $1 attempt Attempt number. -upstart::upstart_services_with_backoff_params() { - local attempt="${1}" - upstart::upstart_named_service "krain" $attempt - upstart::upstart_named_service "charon" $attempt - upstart::upstart_service "datadog-agent" $attempt -} - -# Pulls the latest docker image for the runnable image builder -# @param $1 attempt The current attempt for pulling image builder -upstart::pull_image_builder() { - local attempt="${1}" - local name="image-builder" - local version="$(consul::get $name/version)" - - log::info "Pulling image-builder:$version (${attempt})" - docker pull "registry.runnable.com/runnable/image-builder:$version" - - if [[ "$?" -gt "0" ]]; then - local data='{"attempt":'"${attempt}"'}' - rollbar::report_warning \ - "Dock-Init: Cannot Upstart Services" \ - "Attempting to upstart the services and failing." \ - "${data}" - return 1 - fi -} - -# Starts all services needed for the dock -upstart::start() { - log::info "Upstarting dock" - upstart::generate_scripts - upstart::start_docker - backoff upstart::pull_image_builder - backoff upstart::upstart_services_with_backoff_params -} - -# Stops all dock services -upstart::stop() { - log::info "Stopping all dock upstart services" - service krain stop - service charon stop - service docker stop -} diff --git a/test/upstart.sh b/test/upstart.sh deleted file mode 100644 index b1c6bc8..0000000 --- a/test/upstart.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -# Unit tests for the `lib/upstart.sh` module. -# @author Anandkumar Patel - -source "$DOCK_INIT_BASE/lib/container.sh" -source "$DOCK_INIT_BASE/lib/upstart.sh" -source "$DOCK_INIT_BASE/test/fixtures/shtub.sh" - -describe 'upstart.sh' - stub log::info - - describe 'upstart::upstart_service' - stub rollbar::warning_trap - stub rollbar::clear_trap - - it 'should start the given service' - stub service - local service_name='foobar' - upstart::upstart_service "$service_name" - service::called_with "$service_name restart" - service::restore - end - - rollbar::warning_trap::restore - rollbar::clear_trap::restore - end - - describe 'upstart::pull_image_builder' - local image_builder_version='v1.2.3' - stub rollbar::report_warning - stub docker - stub::returns consul::get "$image_builder_version" - - it 'should attempt to pull image builder' - local registry="registry.runnable.com/runnable/image-builder" - upstart::pull_image_builder 1 - consul::get::called_with "image-builder/version" - docker::called_with "pull $registry:$image_builder_version" - end - - it 'should return 1 on pull failure' - docker::errors - upstart::pull_image_builder 1 - assert equal "$?" "1" - end - - it 'should report a warning on pull failure' - docker::errors - upstart::pull_image_builder 222 - rollbar::report_warning::called_with \ - "Dock-Init: Cannot Upstart Services" \ - "Attempting to upstart the services and failing." \ - '{"attempt":222}' - end - - # docker::restore - rollbar::report_warning::restore - consul::get::restore - end - - log::info::restore -end # upstart.sh From 3c04329d707db39031ca5a8c0fb1c66b3afc2300 Mon Sep 17 00:00:00 2001 From: Henry Mollman Date: Wed, 23 Nov 2016 10:25:59 -0800 Subject: [PATCH 19/19] PR Comments --- lib/container.sh | 8 ++++---- test/container.sh | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/container.sh b/lib/container.sh index 43f85b9..0544ed7 100644 --- a/lib/container.sh +++ b/lib/container.sh @@ -13,7 +13,7 @@ source "${DOCK_INIT_BASE}/lib/vault.sh" # Starts the docker swarm container container::_start_swarm_container() { local name="swarm" - local version="$(consul::get ${name}/version)" + local version="1.2.5" log::info "Starting swarm:${version} container" local docker_logs @@ -38,7 +38,7 @@ container::_start_swarm_container() { # Starts the docker registry container container::_start_registry_container() { local name="registry" - local version="$(consul::get ${name}/version)" + local version="2.3.1" log::info "Starting ${name}:${version} container" local region="$(consul::get s3/region)" @@ -75,7 +75,7 @@ container::_start_registry_container() { container::_start_cadvisor_container() { local name="google/cadvisor" - local version="$(consul::get ${name}/version)" + local version="v0.24.1" log::info "Starting ${name}:${version} container" local docker_logs @@ -104,7 +104,7 @@ container::_start_cadvisor_container() { container::_start_node_exporter_container() { local name="prom/node-exporter" - local version="$(consul::get ${name}/version)" + local version="0.12.0" log::info "Starting ${name}:${version} container" local docker_logs diff --git a/test/container.sh b/test/container.sh index cdf7405..11e469a 100644 --- a/test/container.sh +++ b/test/container.sh @@ -155,5 +155,6 @@ describe 'container.sh' container::_start_cadvisor_container::restore container::_start_node_exporter_container::restore container::_start_swarm_container::restore + upstart::start_docker::restore end # end container::start end # container.sh