From 8049193f3853c9b35f161e59ffc664ba49032ad9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 14:57:57 -0400 Subject: [PATCH 1/9] fix read call --- commands | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands b/commands index 1287c01..1354337 100755 --- a/commands +++ b/commands @@ -62,7 +62,7 @@ case "$1" in dokku_log_warn "To proceed, type \"$SERVICE\"" echo "" - read -p "> " service_name + read -rp "> " service_name if [[ "$service_name" != "$SERVICE" ]]; then dokku_log_warn "Confirmation did not match $SERVICE. Aborted." exit 1 From 3ce4c6570506da1e9cd7e8e4072dc347c5d30fb6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 14:58:02 -0400 Subject: [PATCH 2/9] quote docker pull call --- commands | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands b/commands index 1354337..36a28c9 100755 --- a/commands +++ b/commands @@ -25,7 +25,7 @@ case "$1" in SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS" if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then - docker pull $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed" + docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed" fi mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory" From 6067516ea7a1e4d7c1ee915347b50b14db1f1a20 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 14:58:11 -0400 Subject: [PATCH 3/9] ensure we don't expand PLUGIN_DATA_ROOT --- commands | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands b/commands index 36a28c9..8972f7f 100755 --- a/commands +++ b/commands @@ -15,7 +15,7 @@ if [[ ! -d $PLUGIN_DATA_ROOT ]]; then fi if [[ -d "$PLUGIN_DATA_ROOT/*" ]]; then - rm -rf "$PLUGIN_DATA_ROOT/*" + rm -rf "${PLUGIN_DATA_ROOT:?}/*" fi case "$1" in From d6582fe3b0879d42d982b4151bec2b396e2ea16c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 14:58:54 -0400 Subject: [PATCH 4/9] use config functions properly --- functions | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/functions b/functions index 446a1d7..a786222 100755 --- a/functions +++ b/functions @@ -75,7 +75,7 @@ service_link() { local SERVICE_URL=$(service_url "$SERVICE") local SERVICE_NAME=$(get_service_name "$SERVICE") local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" - local EXISTING_CONFIG=$(dokku config "$APP") + local EXISTING_CONFIG=$(config_all "$APP") local LINK=$(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1) || true local DEFAULT_ALIAS=$(echo "$EXISTING_CONFIG" | grep "${PLUGIN_DEFAULT_ALIAS}_URL") || true local SERVICE_ALIAS=$(service_alias "$SERVICE") @@ -92,7 +92,7 @@ service_link() { ALIAS=$(service_alternative_alias "$EXISTING_CONFIG") fi dokku docker-options:add "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_ALIAS" - dokku config:set "$APP" "${ALIAS}_URL=$SERVICE_URL" + config_set "$APP" "${ALIAS}_URL=$SERVICE_URL" } service_alternative_alias() { @@ -285,7 +285,7 @@ service_unlink() { update_plugin_scheme_for_app "$APP" local SERVICE_URL=$(service_url "$SERVICE") local SERVICE_NAME=$(get_service_name "$SERVICE") - local EXISTING_CONFIG=$(dokku config "$APP") + local EXISTING_CONFIG=$(config_all "$APP") local SERVICE_ALIAS=$(service_alias "$SERVICE") local LINK=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true @@ -293,13 +293,12 @@ service_unlink() { remove_from_links_file "$SERVICE" "$APP" dokku docker-options:remove "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_ALIAS" - dokku config:unset "$APP" "${LINK[*]}" + config_unset "$APP" "${LINK[*]}" } service_url() { local SERVICE="$1" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" - local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")" local SERVICE_ALIAS="$(service_alias "$SERVICE")" echo "$PLUGIN_SCHEME://mysql:$PASSWORD@$SERVICE_ALIAS:${PLUGIN_DATASTORE_PORTS[0]}/$SERVICE" @@ -338,7 +337,7 @@ promote() { local SERVICE="$1" local APP="$2" local PLUGIN_DEFAULT_CONFIG_VAR="${PLUGIN_DEFAULT_ALIAS}_URL" - local EXISTING_CONFIG=$(dokku config "$APP") + local EXISTING_CONFIG=$(config_all "$APP") update_plugin_scheme_for_app "$APP" local SERVICE_URL=$(service_url "$SERVICE") local CONFIG_VARS=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true @@ -357,7 +356,9 @@ promote() { fi local PROMOTE_URL=$(get_url_from_config "$EXISTING_CONFIG" "${CONFIG_VARS[0]}") NEW_CONFIG_VARS+="$PLUGIN_DEFAULT_CONFIG_VAR=$PROMOTE_URL" - dokku config:set "$APP" $NEW_CONFIG_VARS + + # shellcheck disable=SC2086 + config_set "$APP" $NEW_CONFIG_VARS } remove_from_links_file() { From 6cebc4c92ee31a2044532d23c4675e7a9249c701 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 14:59:10 -0400 Subject: [PATCH 5/9] shellcheck disable --- functions | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/functions b/functions index a786222..739f477 100755 --- a/functions +++ b/functions @@ -123,6 +123,7 @@ service_logs() { DOKKU_LOGS_ARGS="--tail 100" fi + # shellcheck disable=SC2086 docker logs $DOKKU_LOGS_ARGS "$ID" } @@ -189,7 +190,9 @@ service_port_unpause() { local EXPOSED_NAME="${SERVICE_NAME}.ambassador" local PORT_FILE="$SERVICE_ROOT/PORT" local LOG_FAIL="$2" + # shellcheck disable=SC2068 local PORTS=(${@:3}) + # shellcheck disable=SC2068 PORTS=(${PORTS[@]:-$(get_random_ports ${#PLUGIN_DATASTORE_PORTS[@]})}) local ID=$(cat "$SERVICE_ROOT/ID") @@ -204,7 +207,8 @@ service_port_unpause() { echo "${PORTS[@]}" > "$PORT_FILE" - docker run -d --link "$SERVICE_NAME:mysql" --name "$EXPOSED_NAME" $(docker_ports_options "${PORTS[@]}") --restart always --label dokku=ambassador --label dokku.ambassador=mysql svendowideit/ambassador > /dev/null + # shellcheck disable=SC2046 + docker run -d --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" --name "$EXPOSED_NAME" $(docker_ports_options "${PORTS[@]}") --restart always --label dokku=ambassador --label "dokku.ambassador=$PLUGIN_COMMAND_PREFIX" svendowideit/ambassador > /dev/null if [[ "$LOG_FAIL" == "true" ]]; then dokku_log_info1 "Service $SERVICE exposed on port(s) ${PORTS[*]}" fi From 4bddb3954c93af16eadfff972abceede19d1aaa2 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 14:59:20 -0400 Subject: [PATCH 6/9] trim whitespace from url --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 739f477..2b9cdc1 100755 --- a/functions +++ b/functions @@ -334,7 +334,7 @@ service_version() { get_url_from_config() { local EXISTING_CONFIG="$1" local CONFIG_VAR="$2" - echo "$EXISTING_CONFIG" | grep "$CONFIG_VAR" | sed "s/$CONFIG_VAR:\s*//" + echo "$EXISTING_CONFIG" | grep "$CONFIG_VAR" | sed "s/$CONFIG_VAR:\s*//" | xargs } promote() { From 14c5dc8ebe81b8abdfe09b86762188918d5dad52 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 14:59:51 -0400 Subject: [PATCH 7/9] use an extension for sed calls on os x --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index 2b9cdc1..44a33a6 100755 --- a/functions +++ b/functions @@ -373,7 +373,7 @@ remove_from_links_file() { mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory" touch "$LINKS_FILE" - sed -i "/^$APP\$/d" "$LINKS_FILE" + sed -i.bak "/^$APP\$/d" "$LINKS_FILE" && rm "$LINKS_FILE.bak" sort "$LINKS_FILE" -u -o "$LINKS_FILE" } From b448a83c1ef9646817223cd3bc6bc68e2c289d84 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 15:00:01 -0400 Subject: [PATCH 8/9] quote SERVICE_NAME value --- functions | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/functions b/functions index 44a33a6..d300fa5 100755 --- a/functions +++ b/functions @@ -33,7 +33,7 @@ verify_service_name() { service_alias() { local SERVICE="$1" - local SERVICE_NAME=$(get_service_name "$SERVICE") + local SERVICE_NAME="$(get_service_name "$SERVICE")" echo "$SERVICE_NAME" | tr ._ - } @@ -73,7 +73,7 @@ service_link() { local SERVICE="$1" update_plugin_scheme_for_app "$APP" local SERVICE_URL=$(service_url "$SERVICE") - local SERVICE_NAME=$(get_service_name "$SERVICE") + local SERVICE_NAME="$(get_service_name "$SERVICE")" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local EXISTING_CONFIG=$(config_all "$APP") local LINK=$(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1) || true @@ -186,7 +186,7 @@ service_port_unexpose() { service_port_unpause() { local SERVICE="$1" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" - local SERVICE_NAME=$(get_service_name "$SERVICE") + local SERVICE_NAME="$(get_service_name "$SERVICE")" local EXPOSED_NAME="${SERVICE_NAME}.ambassador" local PORT_FILE="$SERVICE_ROOT/PORT" local LOG_FAIL="$2" @@ -225,7 +225,7 @@ service_start() { local SERVICE="$1" local QUIET="$2" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" - local SERVICE_NAME=$(get_service_name "$SERVICE") + local SERVICE_NAME="$(get_service_name "$SERVICE")" local ID=$(docker ps -f status=running | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true if [[ -n $ID ]]; then [[ -z $QUIET ]] && dokku_log_warn "Service is already started" @@ -252,7 +252,7 @@ service_start() { service_create_container() { local SERVICE="$1" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" - local SERVICE_NAME=$(get_service_name "$SERVICE") + local SERVICE_NAME="$(get_service_name "$SERVICE")" local ROOTPASSWORD=$(cat "$SERVICE_ROOT/ROOTPASSWORD") local PASSWORD=$(cat "$SERVICE_ROOT/PASSWORD") @@ -269,7 +269,7 @@ service_create_container() { service_stop() { local SERVICE="$1" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; - local SERVICE_NAME=$(get_service_name "$SERVICE") + local SERVICE_NAME="$(get_service_name "$SERVICE")" local ID=$(docker ps -f status=running | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true [[ -z $ID ]] && dokku_log_warn "Service is already stopped" && return 0 @@ -288,7 +288,7 @@ service_unlink() { local SERVICE="$1" update_plugin_scheme_for_app "$APP" local SERVICE_URL=$(service_url "$SERVICE") - local SERVICE_NAME=$(get_service_name "$SERVICE") + local SERVICE_NAME="$(get_service_name "$SERVICE")" local EXISTING_CONFIG=$(config_all "$APP") local SERVICE_ALIAS=$(service_alias "$SERVICE") local LINK=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true From 2d7a1ab5b2d7747b314d8a2172173b122f91b50a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 8 May 2016 15:00:09 -0400 Subject: [PATCH 9/9] update shellcheck ignores --- Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 93a7332..2b6ee66 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,10 @@ ci-dependencies: shellcheck bats lint: # these are disabled due to their expansive existence in the codebase. we should clean it up though - # SC2046: Quote this to prevent word splitting. - https://github.com/koalaman/shellcheck/wiki/SC2046 - # SC2068: Double quote array expansions, otherwise they're like $* and break on spaces. - https://github.com/koalaman/shellcheck/wiki/SC2068 - # SC2086: Double quote to prevent globbing and word splitting - https://github.com/koalaman/shellcheck/wiki/SC2086 + # SC1090: Can't follow non-constant source. Use a directive to specify location. + # SC2155: Declare and assign separately to avoid masking return values. @echo linting... - @$(QUIET) find ./ -maxdepth 1 -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2046,SC2068,SC2086 + @$(QUIET) find ./ -maxdepth 1 -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC1090,SC2155 unit-tests: @echo running unit tests...