diff --git a/bootstrap.sh b/bootstrap.sh index 5be729bde..74dbae1e8 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $TRACE ]] && set -x +set -eo pipefail +[[ $TRACE ]] && set -x # A script to bootstrap dokku. # It expects to be run on Ubuntu 14.04 via 'sudo' @@ -15,7 +16,7 @@ ensure-environment() { local FREE_MEMORY echo "Preparing to install $DOKKU_TAG from $DOKKU_REPO..." - hostname -f > /dev/null 2>&1 || { + hostname -f >/dev/null 2>&1 || { echo "This installation script requires that you have a hostname set for the instance. Please set a hostname for 127.0.0.1 in your /etc/hosts" exit 1 } @@ -31,14 +32,14 @@ install-requirements() { echo "--> Ensuring we have the proper dependencies" case "$DOKKU_DISTRO" in - debian|ubuntu) + debian | ubuntu) if ! dpkg -l | grep -q software-properties-common; then - apt-get update -qq > /dev/null + apt-get update -qq >/dev/null apt-get -qq -y install software-properties-common fi - add-apt-repository universe > /dev/null - apt-get update -qq > /dev/null + add-apt-repository universe >/dev/null + apt-get update -qq >/dev/null ;; esac } @@ -47,7 +48,7 @@ install-dokku() { if [[ -n $DOKKU_BRANCH ]]; then install-dokku-from-source "origin/$DOKKU_BRANCH" elif [[ -n $DOKKU_TAG ]]; then - local DOKKU_SEMVER="${DOKKU_TAG//v}" + local DOKKU_SEMVER="${DOKKU_TAG//v/}" major=$(echo "$DOKKU_SEMVER" | awk '{split($0,a,"."); print a[1]}') minor=$(echo "$DOKKU_SEMVER" | awk '{split($0,a,"."); print a[2]}') patch=$(echo "$DOKKU_SEMVER" | awk '{split($0,a,"."); print a[3]}') @@ -101,10 +102,10 @@ install-dokku-from-source() { install-dokku-from-package() { case "$DOKKU_DISTRO" in - debian|ubuntu) + debian | ubuntu) install-dokku-from-deb-package "$@" ;; - centos|rhel) + centos | rhel) install-dokku-from-rpm-package "$@" ;; *) @@ -134,7 +135,7 @@ install-dokku-from-deb-package() { fi echo "--> Initial apt-get update" - apt-get update -qq > /dev/null + apt-get update -qq >/dev/null apt-get -qq -y install apt-transport-https echo "--> Installing docker" @@ -151,7 +152,7 @@ install-dokku-from-deb-package() { add-apt-repository -y ppa:nginx/stable fi - OS_ID="$(lsb_release -cs 2> /dev/null || echo "trusty")" + OS_ID="$(lsb_release -cs 2>/dev/null || echo "trusty")" if ! in-array "$DOKKU_DISTRO" "debian" "ubuntu"; then DOKKU_DISTRO="ubuntu" OS_ID="trusty" @@ -172,14 +173,14 @@ install-dokku-from-deb-package() { echo "--> Installing dokku" wget -nv -O - https://packagecloud.io/gpg.key | apt-key add - echo "deb https://packagecloud.io/dokku/dokku/$DOKKU_DISTRO/ $OS_ID main" | tee /etc/apt/sources.list.d/dokku.list - apt-get update -qq > /dev/null + apt-get update -qq >/dev/null - [[ -n $DOKKU_VHOST_ENABLE ]] && echo "dokku dokku/vhost_enable boolean $DOKKU_VHOST_ENABLE" | sudo debconf-set-selections - [[ -n $DOKKU_WEB_CONFIG ]] && echo "dokku dokku/web_config boolean $DOKKU_WEB_CONFIG" | sudo debconf-set-selections - [[ -n $DOKKU_HOSTNAME ]] && echo "dokku dokku/hostname string $DOKKU_HOSTNAME" | sudo debconf-set-selections + [[ -n $DOKKU_VHOST_ENABLE ]] && echo "dokku dokku/vhost_enable boolean $DOKKU_VHOST_ENABLE" | sudo debconf-set-selections + [[ -n $DOKKU_WEB_CONFIG ]] && echo "dokku dokku/web_config boolean $DOKKU_WEB_CONFIG" | sudo debconf-set-selections + [[ -n $DOKKU_HOSTNAME ]] && echo "dokku dokku/hostname string $DOKKU_HOSTNAME" | sudo debconf-set-selections [[ -n $DOKKU_SKIP_KEY_FILE ]] && echo "dokku dokku/skip_key_file boolean $DOKKU_SKIP_KEY_FILE" | sudo debconf-set-selections - [[ -n $DOKKU_KEY_FILE ]] && echo "dokku dokku/key_file string $DOKKU_KEY_FILE" | sudo debconf-set-selections - [[ -n $DOKKU_NGINX_ENABLE ]] && echo "dokku dokku/nginx_enable string $DOKKU_NGINX_ENABLE" | sudo debconf-set-selections + [[ -n $DOKKU_KEY_FILE ]] && echo "dokku dokku/key_file string $DOKKU_KEY_FILE" | sudo debconf-set-selections + [[ -n $DOKKU_NGINX_ENABLE ]] && echo "dokku dokku/nginx_enable string $DOKKU_NGINX_ENABLE" | sudo debconf-set-selections if [[ -n $DOKKU_CHECKOUT ]]; then # shellcheck disable=SC2086 diff --git a/contrib/dokku-update b/contrib/dokku-update index fcf707c10..9e7e601e3 100755 --- a/contrib/dokku-update +++ b/contrib/dokku-update @@ -79,11 +79,11 @@ main() { arch) yaourt -Syyua ;; - debian|ubuntu) - apt-get update -qq > /dev/null + debian | ubuntu) + apt-get update -qq >/dev/null apt-get -qq -y --force-yes dist-upgrade ;; - centos|opensuse|rhel) + centos | opensuse | rhel) dokku-log-warn "Updating this operating system is not supported" ;; *) @@ -94,7 +94,7 @@ main() { # update all plugins dokku-log-info "Updating all plugins" - for PLUGIN_NAME in $(dokku plugin:list | grep enabled | awk '$1=$1' | cut -d' ' -f1); do + for PLUGIN_NAME in $(dokku plugin:list | grep enabled | awk '$1=$1' | cut -d' ' -f1); do dokku-update-plugin "$PLUGIN_NAME" done dokku plugin:install diff --git a/contrib/dokku_client.sh b/contrib/dokku_client.sh index 1b4b71b2f..b74f954a5 100755 --- a/contrib/dokku_client.sh +++ b/contrib/dokku_client.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x export DOKKU_PORT=${DOKKU_PORT:=22} export DOKKU_HOST=${DOKKU_HOST:=} @@ -48,7 +49,7 @@ fn-dokku-host() { declare DOKKU_GIT_REMOTE="$1" DOKKU_HOST="$2" if [[ -z "$DOKKU_HOST" ]]; then - if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then + if [[ -d .git ]] || git rev-parse --git-dir >/dev/null 2>&1; then DOKKU_HOST=$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | head -n 1 | cut -f1 -d' ' | cut -f2 -d '@' | cut -f1 -d':' 2>/dev/null || true) fi fi @@ -67,7 +68,7 @@ main() { for arg in "$@"; do if [[ "$skip" == "true" ]]; then - next_index=$(( next_index + 1 )) + next_index=$((next_index + 1)) skip=false continue fi @@ -92,13 +93,13 @@ main() { cmd_set=true fi fi - next_index=$(( next_index + 1 )) + next_index=$((next_index + 1)) done DOKKU_REMOTE_HOST="$(fn-dokku-host "$DOKKU_GIT_REMOTE" "$DOKKU_HOST")" if [[ -z "$APP" ]]; then - if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then + if [[ -d .git ]] || git rev-parse --git-dir >/dev/null 2>&1; then set +e APP=$(git remote -v 2>/dev/null | grep -Ei "dokku@$DOKKU_REMOTE_HOST" | head -n 1 | cut -f2 -d'@' | cut -f1 -d' ' | cut -f2 -d':' 2>/dev/null) set -e @@ -112,14 +113,14 @@ main() { if [[ -z "$APP_ARG" ]]; then APP=$(fn-random-name) counter=0 - while ssh -p "$DOKKU_PORT" "dokku@$DOKKU_REMOTE_HOST" apps 2>/dev/null| grep -q "$APP"; do + while ssh -p "$DOKKU_PORT" "dokku@$DOKKU_REMOTE_HOST" apps 2>/dev/null | grep -q "$APP"; do if [[ $counter -ge 100 ]]; then echo "Error: could not reasonably generate a new app name. try cleaning up some apps..." ssh -p "$DOKKU_PORT" "dokku@$DOKKU_REMOTE_HOST" apps exit 1 else APP=$(random_name) - counter=$((counter+1)) + counter=$((counter + 1)) fi done else diff --git a/contrib/release b/contrib/release index dc7ed0767..832c7a227 100755 --- a/contrib/release +++ b/contrib/release @@ -68,7 +68,7 @@ fn-extract-package() { [[ "$IS_RELEASE" == "true" ]] && NAME="dokku:build-release" log-info "(extract-package) writing ${PACKAGE_NAME} to correct path" - docker run --rm --entrypoint cat "$NAME" "/tmp/${PACKAGE_NAME}" > "${ROOT_DIR}/build/${PACKAGE_NAME}" + docker run --rm --entrypoint cat "$NAME" "/tmp/${PACKAGE_NAME}" >"${ROOT_DIR}/build/${PACKAGE_NAME}" return "$?" } @@ -366,8 +366,8 @@ main() { git checkout -- plugins/*/plugin.toml fi - echo "build/dokku_${NEXT_VERSION}_amd64.deb" > build/deb-filename - echo "build/dokku-${NEXT_VERSION}-1.x86_64.rpm" > build/rpm-filename + echo "build/dokku_${NEXT_VERSION}_amd64.deb" >build/deb-filename + echo "build/dokku-${NEXT_VERSION}-1.x86_64.rpm" >build/rpm-filename } main "$@" diff --git a/contrib/release-dokku-update b/contrib/release-dokku-update index 03e075cfa..6f999ac5b 100755 --- a/contrib/release-dokku-update +++ b/contrib/release-dokku-update @@ -47,7 +47,7 @@ fn-extract-package() { fi log-info "(extract-package) writing ${PACKAGE_NAME} to correct path" - docker run --rm --entrypoint cat dokku-update:build "/tmp/${PACKAGE_NAME}" > "${ROOT_DIR}/build/${PACKAGE_NAME}" + docker run --rm --entrypoint cat dokku-update:build "/tmp/${PACKAGE_NAME}" >"${ROOT_DIR}/build/${PACKAGE_NAME}" return "$?" } @@ -70,7 +70,7 @@ fn-publish-package() { EXIT_CODE="$ex" fi done - + DIST=debian OS_IDS=("wheezy" "jessie" "stretch" "buster") for OS_ID in "${OS_IDS[@]}"; do diff --git a/contrib/release-herokuish b/contrib/release-herokuish index e2c9b2cc6..9a3bc96b3 100755 --- a/contrib/release-herokuish +++ b/contrib/release-herokuish @@ -47,7 +47,7 @@ fn-extract-package() { fi log-info "(extract-package) writing ${PACKAGE_NAME} to correct path" - docker run --rm --entrypoint cat herokuish:build "/tmp/${PACKAGE_NAME}" > "${ROOT_DIR}/build/${PACKAGE_NAME}" + docker run --rm --entrypoint cat herokuish:build "/tmp/${PACKAGE_NAME}" >"${ROOT_DIR}/build/${PACKAGE_NAME}" return "$?" } @@ -70,7 +70,7 @@ fn-publish-package() { EXIT_CODE="$ex" fi done - + DIST=debian OS_IDS=("wheezy" "jessie" "stretch" "buster") for OS_ID in "${OS_IDS[@]}"; do diff --git a/contrib/release-plugin b/contrib/release-plugin index 98d8e2c9e..83aaffa8b 100755 --- a/contrib/release-plugin +++ b/contrib/release-plugin @@ -57,7 +57,7 @@ main() { local CURRENT_VERSION FILENAME NEXT_VERSION ORG_REPO_NAME REPO_NAME major minor patch if [[ -z "$RELEASE" ]]; then - cat<<'EOF' + cat <<'EOF' requirements: - this is run in a plugin folder @@ -97,9 +97,9 @@ EOF while true; do read -rp "Do you wish to continue? " yn case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) echo "Please answer yes or no.";; + [Yy]*) break ;; + [Nn]*) exit ;; + *) echo "Please answer yes or no." ;; esac done fi @@ -131,19 +131,19 @@ EOF patch=$(echo "$CURRENT_VERSION" | awk '{split($0,a,"."); print a[3]}') if [[ "$RELEASE" == "major" ]]; then - major=$((major + 1)); + major=$((major + 1)) minor="0" patch="0" elif [[ "$RELEASE" == "minor" ]]; then - minor=$((minor + 1)); + minor=$((minor + 1)) patch="0" elif [[ "$RELEASE" == "patch" ]]; then - patch=$((patch + 1)); + patch=$((patch + 1)) else log-error "Invalid release type specified" return 1 fi - NEXT_VERSION="${major}.${minor}.${patch}" + NEXT_VERSION="${major}.${minor}.${patch}" fn-replace-version "$CURRENT_VERSION" "$NEXT_VERSION" plugin.toml git add plugin.toml @@ -163,7 +163,7 @@ EOF DOKKU_PLUGIN_S3_PATH="${DOKKU_PLUGIN_S3_PATH}/" fi - fn-github-download-release "$ORG_REPO_NAME" "$NEXT_VERSION" > "${TMP_WORK_DIR}/${FILENAME}" + fn-github-download-release "$ORG_REPO_NAME" "$NEXT_VERSION" >"${TMP_WORK_DIR}/${FILENAME}" aws s3 cp "${TMP_WORK_DIR}/${FILENAME}" "s3://${DOKKU_PLUGIN_S3_BUCKET}/${DOKKU_PLUGIN_S3_PATH}${FILENAME}" --acl public-read fi } diff --git a/debian/config b/debian/config index eab3ea415..664060915 100755 --- a/debian/config +++ b/debian/config @@ -1,5 +1,6 @@ #!/bin/bash -set -eo pipefail; [[ $TRACE ]] && set -x +set -eo pipefail +[[ $TRACE ]] && set -x if [[ -e /usr/share/debconf/confmodule ]]; then # shellcheck disable=SC1091 @@ -14,7 +15,7 @@ db_go || true db_get "dokku/web_config" if [ $RET = "true" ]; then - exit 0 + exit 0 fi db_input "high" "dokku/nginx_enable" || true diff --git a/debian/postinst b/debian/postinst index 78aa58a91..789cbb50a 100755 --- a/debian/postinst +++ b/debian/postinst @@ -1,5 +1,6 @@ #!/bin/bash -set -eo pipefail; [[ $TRACE ]] && set -x +set -eo pipefail +[[ $TRACE ]] && set -x if [[ -e /usr/share/debconf/confmodule ]]; then # shellcheck disable=SC1091 @@ -26,10 +27,10 @@ call-sshcommand() { } case "$1" in - abort-upgrade|abort-remove|abort-deconfigure) - ;; + abort-upgrade | abort-remove | abort-deconfigure) ;; - configure) + \ + configure) mandb [ ! -x /usr/bin/docker.io ] || ln -sf /usr/bin/docker.io /usr/local/bin/docker modprobe aufs || echo "WARNING: Restart server to finish installing dokku!" @@ -55,7 +56,7 @@ case "$1" in elif [ -f ${DOKKU_LIB_ROOT}/plugins/$plugin/.core ]; then rm -rf ${DOKKU_LIB_ROOT}/plugins/$plugin elif [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then - mv ${DOKKU_LIB_ROOT}/plugins/$plugin ${DOKKU_LIB_ROOT}/plugins/available; + mv ${DOKKU_LIB_ROOT}/plugins/$plugin ${DOKKU_LIB_ROOT}/plugins/available fi done @@ -66,7 +67,7 @@ case "$1" in echo "Skipping enable of nginx-vhosts plugin" continue elif [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then - ln -s ${DOKKU_LIB_ROOT}/core-plugins/available/$plugin ${DOKKU_LIB_ROOT}/plugins/available/$plugin; + ln -s ${DOKKU_LIB_ROOT}/core-plugins/available/$plugin ${DOKKU_LIB_ROOT}/plugins/available/$plugin PLUGIN_PATH=${DOKKU_LIB_ROOT}/core-plugins plugn enable $plugin PLUGIN_PATH=${DOKKU_LIB_ROOT}/plugins plugn enable $plugin fi @@ -75,7 +76,7 @@ case "$1" in chown dokku:dokku -R ${DOKKU_LIB_ROOT}/plugins ${DOKKU_LIB_ROOT}/core-plugins echo "Ensure proper sshcommand path" - echo '/usr/bin/dokku' > "${DOKKU_ROOT}/.sshcommand" + echo '/usr/bin/dokku' >"${DOKKU_ROOT}/.sshcommand" if [[ -f .ssh/authorized_keys ]]; then sed -i.bak 's#/usr/local/bin/dokku#/usr/bin/dokku#' "${DOKKU_ROOT}/.ssh/authorized_keys" rm "${DOKKU_ROOT}/.ssh/authorized_keys" @@ -96,8 +97,8 @@ case "$1" in systemctl enable dokku-installer fi - installer_status="$(service dokku-installer status 2> /dev/null || true)" - if echo $installer_status | grep -Eq "(inactive|waiting)" > /dev/null; then + installer_status="$(service dokku-installer status 2>/dev/null || true)" + if echo $installer_status | grep -Eq "(inactive|waiting)" >/dev/null; then echo "Starting dokku-installer" service dokku-installer start || echo "Unable to start dokku-installer" fi @@ -114,19 +115,19 @@ case "$1" in else db_get "dokku/vhost_enable" if [ "$RET" = "true" ]; then - db_get "dokku/hostname" - echo "Setting VHOST contents to $RET" - echo "$RET" > "${DOKKU_ROOT}/VHOST" + db_get "dokku/hostname" + echo "Setting VHOST contents to $RET" + echo "$RET" >"${DOKKU_ROOT}/VHOST" fi fi db_get "dokku/hostname" - echo "$RET" > "${DOKKU_ROOT}/HOSTNAME" + echo "$RET" >"${DOKKU_ROOT}/HOSTNAME" if [ -z "${DEBCONF_RECONFIGURE}" ]; then db_get "dokku/key_file" if [ -f "$RET" ]; then - call-sshcommand acl-add dokku default < "$RET" || true + call-sshcommand acl-add dokku default <"$RET" || true fi fi ;; diff --git a/debian/postrm b/debian/postrm index f939ee55a..b37c0578d 100755 --- a/debian/postrm +++ b/debian/postrm @@ -1,5 +1,6 @@ #!/bin/bash -set -eo pipefail; [[ $TRACE ]] && set -x +set -eo pipefail +[[ $TRACE ]] && set -x if [[ -e /usr/share/debconf/confmodule ]]; then # shellcheck disable=SC1091 diff --git a/debian/preinst b/debian/preinst index dc3e4f1d3..c9a055344 100755 --- a/debian/preinst +++ b/debian/preinst @@ -1,5 +1,6 @@ #!/bin/bash -set -eo pipefail; [[ $TRACE ]] && set -x +set -eo pipefail +[[ $TRACE ]] && set -x if [[ -e /usr/share/debconf/confmodule ]]; then # shellcheck disable=SC1091 @@ -23,10 +24,13 @@ case "$1" in echo ' proxy_pass http://dokku-installer;' echo ' }' echo '}' - } >> $NGINX_CONF + } >>$NGINX_CONF rm -f /etc/nginx/sites-enabled/* - DOKKU_DISTRO="$(. /etc/os-release > /dev/null 2>&1 || true ; echo "$ID")" + DOKKU_DISTRO="$( + . /etc/os-release >/dev/null 2>&1 || true + echo "$ID" + )" case "$DOKKU_DISTRO" in debian) NGINX_INIT="/usr/sbin/invoke-rc.d" @@ -44,21 +48,21 @@ case "$1" in if [ -z "${DEBCONF_RECONFIGURE}" ] && [ "$RET" != "true" ]; then db_get "dokku/key_file" if [ ! -f "$RET" ]; then - echo "Error: keyfile '$RET' not found." - echo " you can enter a new keyfile path when you restart the installation." - db_reset "dokku/key_file" - exit 1 + echo "Error: keyfile '$RET' not found." + echo " you can enter a new keyfile path when you restart the installation." + db_reset "dokku/key_file" + exit 1 fi fi ;; - upgrade) - ;; + upgrade) ;; - abort-upgrade) - ;; + \ + abort-upgrade) ;; - *) + \ + *) echo "preinst called with unknown argument \`$1'" >&2 exit 1 ;; diff --git a/debian/prerm b/debian/prerm index c62cef9a0..4e84bdf31 100755 --- a/debian/prerm +++ b/debian/prerm @@ -1,34 +1,35 @@ #!/bin/bash -set -eo pipefail; [[ $TRACE ]] && set -x +set -eo pipefail +[[ $TRACE ]] && set -x readonly DOKKU_ROOT="${DOKKU_ROOT:-/home/dokku}" readonly DOKKU_LIB_ROOT="${DOKKU_LIB_PATH:-/var/lib/dokku}" ps_backtrace() { if [ $# -lt 1 ]; then - echo "Usage: $0 PID" > /dev/stderr + echo "Usage: $0 PID" >/dev/stderr exit 1 fi - declare -i pid=$1; - ppid=0; - header_modifier=""; - while : ; do + declare -i pid=$1 + ppid=0 + header_modifier="" + while :; do if [ $ppid -ne 0 ]; then - header_modifier=h; - fi; - ppid=$(ps -o ppid= $pid); - ps uww $header_modifier -p $pid; + header_modifier=h + fi + ppid=$(ps -o ppid= $pid) + ps uww $header_modifier -p $pid if [ $pid -eq 1 ]; then - break; - fi; - pid=$ppid; - done; + break + fi + pid=$ppid + done } main() { # HACK: Ensure that we only delete data when purging dokku from the system - if ps_backtrace $BASHPID 2> /dev/null | grep dpkg | grep -- "--purge" > /dev/null; then + if ps_backtrace $BASHPID 2>/dev/null | grep dpkg | grep -- "--purge" >/dev/null; then echo "Processing purge" echo "Destroying deployed applications" @@ -40,7 +41,7 @@ main() { echo "Disabling all core plugins" find ${DOKKU_LIB_ROOT}/core-plugins/available -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read -r plugin; do if [ ! -d ${DOKKU_LIB_ROOT}/plugins/available/$plugin ]; then - rm ${DOKKU_LIB_ROOT}/plugins/available/$plugin; + rm ${DOKKU_LIB_ROOT}/plugins/available/$plugin PLUGIN_PATH=${DOKKU_LIB_ROOT}/core-plugins plugn disable $plugin PLUGIN_PATH=${DOKKU_LIB_ROOT}/plugins plugn disable $plugin fi diff --git a/dokku b/dokku index 96222c23f..a3f994450 100755 --- a/dokku +++ b/dokku @@ -31,7 +31,10 @@ export DOKKU_HOST_ROOT=${DOKKU_HOST_ROOT:=$DOKKU_ROOT} export DOKKU_DISTRO # shellcheck disable=SC1091 -DOKKU_DISTRO=$(. /etc/os-release > /dev/null 2>&1 || true ; echo "$ID") +DOKKU_DISTRO=$( + . /etc/os-release >/dev/null 2>&1 || true + echo "$ID" +) export DOKKU_IMAGE=${DOKKU_IMAGE:="gliderlabs/herokuish"} export DOKKU_LIB_ROOT=${DOKKU_LIB_PATH:="/var/lib/dokku"} @@ -103,7 +106,7 @@ if [[ -n "$SSH_ORIGINAL_COMMAND" ]]; then fi fi -if ! dokku_auth "$@" ; then +if ! dokku_auth "$@"; then dokku_log_fail "Access denied" exit 1 fi @@ -112,25 +115,26 @@ execute_dokku_cmd() { declare desc="executes dokku sub-commands" local PLUGIN_NAME="$1" local PLUGIN_CMD=$PLUGIN_NAME - local implemented=0; local script + local implemented=0 + local script local argv=("$@") case "$PLUGIN_NAME" in - events|events:*) + events | events:*) local PLUGIN_NAME=${PLUGIN_NAME/events/20_events} ;; - nginx|nginx:*) + nginx | nginx:*) local PLUGIN_NAME=${PLUGIN_NAME/nginx/nginx-vhosts} ;; - deploy|delete|ls|run|cleanup) + deploy | delete | ls | run | cleanup) local PLUGIN_NAME="00_dokku-standard" ;; - trace|url|urls|report|version) + trace | url | urls | report | version) local PLUGIN_NAME="00_dokku-standard" ;; esac - if [[ "$(readlink -f "$PLUGIN_ENABLED_PATH/${PLUGIN_NAME%%:*}")" == *core-plugins* ]] ; then + if [[ "$(readlink -f "$PLUGIN_ENABLED_PATH/${PLUGIN_NAME%%:*}")" == *core-plugins* ]]; then [[ ${argv[0]} == "$PLUGIN_CMD" ]] && shift 1 if [[ ! -z $DOKKU_APP_NAME ]]; then if [[ "$PLUGIN_CMD" == config* ]] && [[ ${argv[1]} == "--no-restart" ]]; then @@ -154,9 +158,12 @@ execute_dokku_cmd() { implemented=1 fi - if [[ $implemented -eq 0 ]];then + if [[ $implemented -eq 0 ]]; then for script in $PLUGIN_ENABLED_PATH/*/commands; do - set +e; $script "$@" ; exit_code=$? ; set -e + set +e + $script "$@" + exit_code=$? + set -e if [[ "$exit_code" -eq "$DOKKU_NOT_IMPLEMENTED_EXIT" ]]; then continue fi @@ -175,18 +182,18 @@ execute_dokku_cmd() { } case "$1" in - help|'') + help | '') export LC_ALL=C # so sort will respect non alpha characters - ALL_PLUGIN_COMMANDS=$(find -L "$PLUGIN_PATH/enabled" -name commands 2> /dev/null || true) + ALL_PLUGIN_COMMANDS=$(find -L "$PLUGIN_PATH/enabled" -name commands 2>/dev/null || true) # build list of core plugin command files - for plugin_command in $ALL_PLUGIN_COMMANDS;do + for plugin_command in $ALL_PLUGIN_COMMANDS; do if [[ "$(readlink -f "$plugin_command")" == *core-plugins* ]]; then CORE_PLUGIN_COMMANDS+="$plugin_command " fi done # build list of non-core plugin command files - for plugin_command in $ALL_PLUGIN_COMMANDS;do + for plugin_command in $ALL_PLUGIN_COMMANDS; do if [[ "$(readlink -f "$plugin_command")" != *core-plugins* ]]; then COMMUNITY_PLUGIN_COMMANDS+="$plugin_command " fi @@ -200,7 +207,7 @@ case "$1" in dokku_log_quiet "Commands:" dokku_log_quiet "" - if [[ "$2" == "--all" ]] ; then + if [[ "$2" == "--all" ]]; then for core_plugin_command in $CORE_PLUGIN_COMMANDS; do $core_plugin_command help done | sort | column -c2 -t -s, @@ -213,7 +220,7 @@ case "$1" in else for core_plugin_command in $CORE_PLUGIN_COMMANDS; do $core_plugin_command help - # When done, sort, sed cuts arugments out of strings and colum make it pretty + # When done, sort, sed cuts arugments out of strings and colum make it pretty done | sort | sed -e '/^.*:/d' -e 's/\s[\[\<\-\(].*,/,/' | column -c2 -t -s, if [[ -n "$COMMUNITY_PLUGIN_COMMANDS" ]]; then dokku_log_quiet "" diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 12d024e66..718ff096b 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -1,13 +1,14 @@ #!/usr/bin/env bash [[ " help help:help run:help trace:help url:help urls:help version:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in - help|run:help|trace:help|url:help|urls:help|version:help) + help | run:help | trace:help | url:help | urls:help | version:help) [[ $(echo "$1" | sed '/.*:help/!d') ]] && help_topic="${1%\:help}" - help_content_func () { + help_content_func() { declare desc="return standard plugin help content" - cat< , Run a command in a new container using the current application image trace [on/off], Enable dokku tracing url , Show the first URL for an application (compatibility) @@ -17,10 +18,10 @@ case "$1" in help_content } - if [[ $help_topic ]] ; then - help_content_func | sed "/^\s*$help_topic\s/!d" | sort | sed '/^.*:/d' | column -c2 -t -s, + if [[ $help_topic ]]; then + help_content_func | sed "/^\s*$help_topic\s/!d" | sort | sed '/^.*:/d' | column -c2 -t -s, else - help_content_func + help_content_func fi ;; diff --git a/plugins/00_dokku-standard/docker-args-build b/plugins/00_dokku-standard/docker-args-build index f1e8ba58e..5d2a59924 100755 --- a/plugins/00_dokku-standard/docker-args-build +++ b/plugins/00_dokku-standard/docker-args-build @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/config/functions" app_user_docker_args() { diff --git a/plugins/00_dokku-standard/exec-app-json-scripts b/plugins/00_dokku-standard/exec-app-json-scripts index 0f222bc2a..c38ed2828 100755 --- a/plugins/00_dokku-standard/exec-app-json-scripts +++ b/plugins/00_dokku-standard/exec-app-json-scripts @@ -1,19 +1,21 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" get_phase_script() { declare desc="extracts app.json from app image and returns the appropriate json key/value" - local IMAGE="$1"; local PHASE_SCRIPT_KEY="$2" + local IMAGE="$1" + local PHASE_SCRIPT_KEY="$2" local GET_PHASE_SCRIPT_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_get_phase_script.XXXX") local APP_JSON_FILE="$GET_PHASE_SCRIPT_TMP_WORK_DIR/app.json" trap 'rm -rf "$GET_PHASE_SCRIPT_TMP_WORK_DIR" > /dev/null' RETURN INT TERM copy_from_image "$IMAGE" "app.json" "$GET_PHASE_SCRIPT_TMP_WORK_DIR" 2>/dev/null || true - if [[ -f "$APP_JSON_FILE" ]];then - local VALUE=$(get_json_value "scripts.dokku.${PHASE_SCRIPT_KEY}" < "$APP_JSON_FILE") + if [[ -f "$APP_JSON_FILE" ]]; then + local VALUE=$(get_json_value "scripts.dokku.${PHASE_SCRIPT_KEY}" <"$APP_JSON_FILE") else return 0 fi @@ -23,12 +25,14 @@ get_phase_script() { execute_script() { declare desc="executes appropriate phase script key from app.json" - local APP="$1"; local IMAGE_TAG="$2"; local PHASE_SCRIPT_KEY="$3" + local APP="$1" + local IMAGE_TAG="$2" + local PHASE_SCRIPT_KEY="$3" local IMAGE id IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") local SCRIPT_CMD=$(get_phase_script "$IMAGE" "$PHASE_SCRIPT_KEY" 2>/dev/null) - if [[ -n "$SCRIPT_CMD" ]];then + if [[ -n "$SCRIPT_CMD" ]]; then dokku_log_info1 "Running '$SCRIPT_CMD' in app container" local COMMAND COMMAND="set -eo pipefail; [[ \$DOKKU_TRACE ]] && set -x ; " @@ -44,7 +48,7 @@ execute_script() { COMMAND+=" rm -rf /tmp/cache ; " COMMAND+=" ln -sf /cache /tmp/cache ; " COMMAND+=" fi ; " - + if [[ "$SCRIPT_CMD" == /* ]]; then local SCRIPT_BIN="$(echo "$SCRIPT_CMD" | cut -d' ' -f1)" COMMAND+=" if [[ ! -x \"$SCRIPT_BIN\" ]]; then " @@ -52,7 +56,7 @@ execute_script() { COMMAND+=" exit 1 ; " COMMAND+=" fi " fi - + COMMAND+=" $SCRIPT_CMD || exit 1;" COMMAND+=" if [[ -d '/cache' ]]; then " COMMAND+=" echo removing installation cache... ; " @@ -65,7 +69,7 @@ execute_script() { local DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG") # strip --restart args from DOCKER_ARGS - local DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<< "$DOCKER_ARGS") + local DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<<"$DOCKER_ARGS") # eval args as array to respect escapes declare -a ARG_ARRAY @@ -79,7 +83,7 @@ execute_script() { id=$(docker run "$DOKKU_GLOBAL_RUN_ARGS" -e DOKKU_TRACE="$DOKKU_TRACE" --label=dokku_phase_script="${PHASE_SCRIPT_KEY}" -d -v "$CACHE_HOST_DIR:/cache" "${ARG_ARRAY[@]}" "$IMAGE" "$DOKKU_APP_SHELL" -c "$COMMAND") if test "$(docker wait "$id")" -eq 0; then dokku_container_log_verbose_quiet "$id" - if [[ "$PHASE_SCRIPT_KEY" != "postdeploy" ]];then + if [[ "$PHASE_SCRIPT_KEY" != "postdeploy" ]]; then if ! is_image_herokuish_based "$IMAGE"; then local DOKKU_DOCKERFILE_ENTRYPOINT=$(config_get "$APP" DOKKU_DOCKERFILE_ENTRYPOINT) local DOKKU_DOCKERFILE_CMD=$(config_get "$APP" DOKKU_DOCKERFILE_CMD) @@ -92,7 +96,7 @@ execute_script() { local DOCKER_COMMIT_ARGS="$DOCKER_COMMIT_ENTRYPOINT_CHANGE_ARG $DOCKER_COMMIT_CMD_CHANGE_ARG" fi # shellcheck disable=SC2086 - eval docker commit $DOCKER_COMMIT_ARGS "$id" "$IMAGE" > /dev/null + eval docker commit $DOCKER_COMMIT_ARGS "$id" "$IMAGE" >/dev/null fi else dokku_container_log_verbose_quiet "$id" diff --git a/plugins/00_dokku-standard/install b/plugins/00_dokku-standard/install index 5f708d796..61c80898d 100755 --- a/plugins/00_dokku-standard/install +++ b/plugins/00_dokku-standard/install @@ -1,20 +1,21 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x -if [[ ! -f "$DOKKU_ROOT/HOSTNAME" ]]; then - hostname -f > "$DOKKU_ROOT/HOSTNAME" +if [[ ! -f "$DOKKU_ROOT/HOSTNAME" ]]; then + hostname -f >"$DOKKU_ROOT/HOSTNAME" fi -if [[ ! -f "$DOKKU_ROOT/VHOST" ]]; then - [[ $(dig +short "$(< "$DOKKU_ROOT/HOSTNAME")") ]] && cp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/VHOST" +if [[ ! -f "$DOKKU_ROOT/VHOST" ]]; then + [[ $(dig +short "$(<"$DOKKU_ROOT/HOSTNAME")") ]] && cp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/VHOST" fi dokku_path="$(which dokku)" # temporary hack for https://github.com/dokku/dokku/issues/82 # redeploys all apps after a reboot -if [[ $(/sbin/init --version 2> /dev/null) =~ upstart ]]; then - cat< /etc/init/dokku-redeploy.conf +if [[ $(/sbin/init --version 2>/dev/null) =~ upstart ]]; then + cat </etc/init/dokku-redeploy.conf description "Dokku app redeploy service" start on filesystem and started docker @@ -26,8 +27,8 @@ end script EOF fi -if [[ $(systemctl 2> /dev/null) =~ -\.mount ]]; then - cat< /etc/systemd/system/dokku-redeploy.service +if [[ $(systemctl 2>/dev/null) =~ -\.mount ]]; then + cat </etc/systemd/system/dokku-redeploy.service [Unit] Description=Dokku app redeploy service Requires=docker.service @@ -47,7 +48,7 @@ EOF fi mkdir -p /etc/update-motd.d -cat< /etc/update-motd.d/99-dokku +cat </etc/update-motd.d/99-dokku #!/bin/sh if [ ! -f "/home/dokku/HOSTNAME" ]; then @@ -63,6 +64,6 @@ chmod +x /etc/update-motd.d/99-dokku chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" -if [[ -f "$DOKKU_ROOT/VHOST" ]]; then +if [[ -f "$DOKKU_ROOT/VHOST" ]]; then chown dokku:dokku "$DOKKU_ROOT/VHOST" fi diff --git a/plugins/00_dokku-standard/post-deploy b/plugins/00_dokku-standard/post-deploy index 50603555e..3cc3e2fba 100755 --- a/plugins/00_dokku-standard/post-deploy +++ b/plugins/00_dokku-standard/post-deploy @@ -1,12 +1,15 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/00_dokku-standard/exec-app-json-scripts" exec_app_json_scripts() { declare desc="core app.json scripts execution" local trigger="post-deploy app_json_scripts" - local APP="$1"; local IMAGE_TAG="$4"; local PHASE_SCRIPT_KEY="postdeploy" + local APP="$1" + local IMAGE_TAG="$4" + local PHASE_SCRIPT_KEY="postdeploy" dokku_log_info1 "Attempting to run scripts.dokku.$PHASE_SCRIPT_KEY from app.json (if defined)" execute_script "$APP" "$IMAGE_TAG" "$PHASE_SCRIPT_KEY" diff --git a/plugins/00_dokku-standard/pre-deploy b/plugins/00_dokku-standard/pre-deploy index 4570350ae..4c9d369af 100755 --- a/plugins/00_dokku-standard/pre-deploy +++ b/plugins/00_dokku-standard/pre-deploy @@ -1,12 +1,15 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/00_dokku-standard/exec-app-json-scripts" exec_app_json_scripts() { declare desc="core app.json scripts execution" local trigger="pre-deploy app_json_scripts" - local APP="$1"; local IMAGE_TAG="$2"; local PHASE_SCRIPT_KEY="predeploy" + local APP="$1" + local IMAGE_TAG="$2" + local PHASE_SCRIPT_KEY="predeploy" dokku_log_info1 "Attempting to run scripts.dokku.$PHASE_SCRIPT_KEY from app.json (if defined)" execute_script "$APP" "$IMAGE_TAG" "$PHASE_SCRIPT_KEY" diff --git a/plugins/00_dokku-standard/subcommands/cleanup b/plugins/00_dokku-standard/subcommands/cleanup index 82fad03a0..459bf3010 100755 --- a/plugins/00_dokku-standard/subcommands/cleanup +++ b/plugins/00_dokku-standard/subcommands/cleanup @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" dokku_cleanup_cmd() { @@ -11,5 +12,4 @@ dokku_cleanup_cmd() { docker_cleanup "$APP" "true" } - dokku_cleanup_cmd "$@" diff --git a/plugins/00_dokku-standard/subcommands/deploy b/plugins/00_dokku-standard/subcommands/deploy index 888165a4c..4d5fae244 100755 --- a/plugins/00_dokku-standard/subcommands/deploy +++ b/plugins/00_dokku-standard/subcommands/deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" shift 1 diff --git a/plugins/00_dokku-standard/subcommands/report b/plugins/00_dokku-standard/subcommands/report index 8c8ecf7aa..a8cad044b 100755 --- a/plugins/00_dokku-standard/subcommands/report +++ b/plugins/00_dokku-standard/subcommands/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" dokku_report_cmd() { diff --git a/plugins/00_dokku-standard/subcommands/run b/plugins/00_dokku-standard/subcommands/run index b5a4ec6cb..a8fc3b2fc 100755 --- a/plugins/00_dokku-standard/subcommands/run +++ b/plugins/00_dokku-standard/subcommands/run @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" diff --git a/plugins/00_dokku-standard/subcommands/trace b/plugins/00_dokku-standard/subcommands/trace index af9154c40..551293831 100755 --- a/plugins/00_dokku-standard/subcommands/trace +++ b/plugins/00_dokku-standard/subcommands/trace @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" dokku_trace_cmd() { @@ -12,7 +13,7 @@ dokku_trace_cmd() { if [[ "$2" == "on" ]]; then echo "Enabling dokku trace" - echo "export DOKKU_TRACE=1" > "$DOKKU_ROOT/.dokkurc/DOKKU_TRACE" + echo "export DOKKU_TRACE=1" >"$DOKKU_ROOT/.dokkurc/DOKKU_TRACE" fi if [[ "$2" == "off" ]]; then diff --git a/plugins/00_dokku-standard/subcommands/urls b/plugins/00_dokku-standard/subcommands/urls index 8e6f1f304..eaee51564 100755 --- a/plugins/00_dokku-standard/subcommands/urls +++ b/plugins/00_dokku-standard/subcommands/urls @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" dokku_urls_cmd() { diff --git a/plugins/00_dokku-standard/subcommands/version b/plugins/00_dokku-standard/subcommands/version index c151f94c8..046d97090 100755 --- a/plugins/00_dokku-standard/subcommands/version +++ b/plugins/00_dokku-standard/subcommands/version @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" dokku_version_cmd() { diff --git a/plugins/20_events/commands b/plugins/20_events/commands index fe67398de..7ed6da3cc 100755 --- a/plugins/20_events/commands +++ b/plugins/20_events/commands @@ -1,12 +1,13 @@ #!/usr/bin/env bash [[ " help events:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | events:help) - help_content_func () { + help_content_func() { declare desc="return events plugin help content" - cat<"$DOKKU_RSYSLOG_FILTER" < "$DOKKU_ROOT/.dokkurc/DOKKU_EVENTS" + echo "export DOKKU_EVENTS=1" >"$DOKKU_ROOT/.dokkurc/DOKKU_EVENTS" } events_on_cmd "$@" diff --git a/plugins/apps/commands b/plugins/apps/commands index 84cd4b172..79b1ab4ae 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help apps:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | apps:help) diff --git a/plugins/apps/functions b/plugins/apps/functions index 598dd87f2..9bf582bb3 100755 --- a/plugins/apps/functions +++ b/plugins/apps/functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -8,7 +9,7 @@ apps_create() { declare APP="$1" is_valid_app_name "$APP" - apps_exists "$APP" > /dev/null 2>&1 && dokku_log_fail "Name is already taken" + apps_exists "$APP" >/dev/null 2>&1 && dokku_log_fail "Name is already taken" mkdir -p "$DOKKU_ROOT/$APP" dokku_log_info1_quiet "Creating $APP... done" @@ -17,7 +18,7 @@ apps_create() { apps_destroy() { declare desc="destroys an app" - declare APP="$1"; + declare APP="$1" verify_app_name "$APP" local IMAGE_TAG=$(get_running_image_tag "$APP") @@ -54,7 +55,7 @@ apps_maybe_create() { declare desc="creates an app dir if allowed" declare APP="$1" - if ! apps_exists "$APP" > /dev/null 2>&1; then + if ! apps_exists "$APP" >/dev/null 2>&1; then DOKKU_GLOBAL_DISABLE_AUTOCREATE="$(config_get --global DOKKU_DISABLE_APP_AUTOCREATION || true)" if [[ "$DOKKU_GLOBAL_DISABLE_AUTOCREATE" == "true" ]]; then dokku_log_warn "App auto-creation disabled." diff --git a/plugins/apps/internal-functions b/plugins/apps/internal-functions index bc91a5d6b..a38e6fda0 100755 --- a/plugins/apps/internal-functions +++ b/plugins/apps/internal-functions @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-apps-report() { declare desc="displays the app report for one or more apps" @@ -30,7 +31,7 @@ cmd-apps-report() { cmd-apps-report-single() { declare APP="$1" INFO_FLAG="$2" local APP_DIR="$DOKKU_ROOT/$APP" - local use_echo; + local use_echo if [[ "$INFO_FLAG" == "true" ]]; then use_echo=true INFO_FLAG="" @@ -38,7 +39,7 @@ cmd-apps-report-single() { verify_app_name "$APP" local flag_map=( "--app-dir: $APP_DIR" - "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2> /dev/null || false)" + "--git-sha: $(GIT_DIR="$APP_DIR" git rev-parse --short HEAD 2>/dev/null || false)" "--deploy-source: $(: | plugn trigger deploy-source "$APP")" "--locked: $(apps_is_locked "$APP")" ) @@ -58,7 +59,8 @@ cmd-apps-report-single() { fi fi else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -76,10 +78,9 @@ cmd-apps-report-single() { fi } - apps_help_content_func() { declare desc="return apps plugin help content" - cat< , Clones an app apps:create , Create a new app @@ -94,7 +95,7 @@ help_content } apps_help_cmd() { - if [[ $1 = "apps:help" ]] ; then + if [[ $1 == "apps:help" ]]; then echo -e 'Usage: dokku apps[:COMMAND]' echo '' echo 'Manage Dokku apps' @@ -111,7 +112,7 @@ apps_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then apps_help_content_func else - cat< /dev/null + rm -rf "${DOKKU_ROOT:?}/$APP/" >/dev/null # then remove the folder and/or the symlink - rm -rf "${DOKKU_ROOT:?}/$APP" > /dev/null + rm -rf "${DOKKU_ROOT:?}/$APP" >/dev/null fi # shellcheck disable=SC2046 diff --git a/plugins/apps/pre-delete b/plugins/apps/pre-delete index f3cf812d6..92742e2e8 100755 --- a/plugins/apps/pre-delete +++ b/plugins/apps/pre-delete @@ -1,11 +1,16 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" apps_pre_delete() { declare desc="apps pre-delete plugin trigger" local trigger="apps_pre_delete" - local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG"); local CACHE_DIR="$DOKKU_ROOT/$APP/cache"; local CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$APP/cache" + local APP="$1" + local IMAGE_TAG="$2" + local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") + local CACHE_DIR="$DOKKU_ROOT/$APP/cache" + local CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$APP/cache" verify_app_name "$APP" if ! is_image_herokuish_based "$IMAGE"; then diff --git a/plugins/apps/report b/plugins/apps/report index ef68b67a0..22829f600 100755 --- a/plugins/apps/report +++ b/plugins/apps/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-apps-report-single "$@" diff --git a/plugins/apps/subcommands/clone b/plugins/apps/subcommands/clone index 7754b3903..a324e91a7 100755 --- a/plugins/apps/subcommands/clone +++ b/plugins/apps/subcommands/clone @@ -1,12 +1,14 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" apps_clone_cmd() { declare desc="clones an app" - declare cmd="apps:clone" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare cmd="apps:clone" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 declare OLD_APP="$1" NEW_APP="$2" local IGNORE_EXISTING=false local SKIP_REBUILD=false @@ -22,8 +24,8 @@ apps_clone_cmd() { is_valid_app_name "$OLD_APP" is_valid_app_name "$NEW_APP" - apps_exists "$OLD_APP" > /dev/null 2>&1 || dokku_log_fail "App does not exist" - if apps_exists "$NEW_APP" > /dev/null 2>&1; then + apps_exists "$OLD_APP" >/dev/null 2>&1 || dokku_log_fail "App does not exist" + if apps_exists "$NEW_APP" >/dev/null 2>&1; then if [[ "$IGNORE_EXISTING" == true ]]; then dokku_log_warn "Name is already taken" return @@ -36,9 +38,9 @@ apps_clone_cmd() { local NEW_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$NEW_APP/cache" apps_create "$NEW_APP" - pushd "$DOKKU_ROOT/$OLD_APP/." > /dev/null + pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null find ./* -not \( -name .cache \) | grep -v "./cache" | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP" - popd > /dev/null 2>&1 || pushd "/tmp" > /dev/null + popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP" if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then diff --git a/plugins/apps/subcommands/create b/plugins/apps/subcommands/create index 0f68a1a08..83d74d2d9 100755 --- a/plugins/apps/subcommands/create +++ b/plugins/apps/subcommands/create @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/apps/functions" apps_create_cmd() { diff --git a/plugins/apps/subcommands/default b/plugins/apps/subcommands/default index ac2c04ed3..0a0014418 100755 --- a/plugins/apps/subcommands/default +++ b/plugins/apps/subcommands/default @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" dokku_log_warn "Deprecated: Please use apps:list" diff --git a/plugins/apps/subcommands/destroy b/plugins/apps/subcommands/destroy index bfeb43862..dca12a426 100755 --- a/plugins/apps/subcommands/destroy +++ b/plugins/apps/subcommands/destroy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/functions" diff --git a/plugins/apps/subcommands/exists b/plugins/apps/subcommands/exists index 084334eb4..608a6d9c0 100755 --- a/plugins/apps/subcommands/exists +++ b/plugins/apps/subcommands/exists @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/apps/functions" apps_exists_cmd() { diff --git a/plugins/apps/subcommands/list b/plugins/apps/subcommands/list index b9573fac2..3da1d8e7b 100755 --- a/plugins/apps/subcommands/list +++ b/plugins/apps/subcommands/list @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" apps_list_cmd "$@" diff --git a/plugins/apps/subcommands/lock b/plugins/apps/subcommands/lock index a54ff4f98..bcbd1ce41 100755 --- a/plugins/apps/subcommands/lock +++ b/plugins/apps/subcommands/lock @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" @@ -7,7 +8,8 @@ apps_lock_cmd() { declare desc="locks an app for deployment" declare cmd="apps:lock" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1"; verify_app_name "$APP" + declare APP="$1" + verify_app_name "$APP" touch "$DOKKU_ROOT/$APP/.deploy.lock" || dokku_log_fail "Unable to create deploy lock" diff --git a/plugins/apps/subcommands/locked b/plugins/apps/subcommands/locked index 50bf5522b..ce27a2845 100755 --- a/plugins/apps/subcommands/locked +++ b/plugins/apps/subcommands/locked @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" @@ -7,10 +8,11 @@ apps_locked_cmd() { declare desc="checks if an app is locked for deployment" declare cmd="apps:locked" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1"; verify_app_name "$APP" + declare APP="$1" + verify_app_name "$APP" local LOCKED="$(apps_is_locked "$APP")" - if [[ "$LOCKED" != "true" ]] ; then + if [[ "$LOCKED" != "true" ]]; then dokku_log_fail_quiet "Deploy lock does not exist" fi diff --git a/plugins/apps/subcommands/rename b/plugins/apps/subcommands/rename index 2a95d1b26..5f5f2e051 100755 --- a/plugins/apps/subcommands/rename +++ b/plugins/apps/subcommands/rename @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -14,7 +15,7 @@ apps_rename_cmd() { local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache" local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache" - if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" > /dev/null 2>&1; then + if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache fi rm -rf "$OLD_CACHE_DIR" diff --git a/plugins/apps/subcommands/report b/plugins/apps/subcommands/report index 02bf6ff5b..a41a4fd30 100755 --- a/plugins/apps/subcommands/report +++ b/plugins/apps/subcommands/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-apps-report "$@" diff --git a/plugins/apps/subcommands/unlock b/plugins/apps/subcommands/unlock index 85165ca3f..fa3f95e06 100755 --- a/plugins/apps/subcommands/unlock +++ b/plugins/apps/subcommands/unlock @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/internal-functions" @@ -7,11 +8,12 @@ apps_unlock_cmd() { declare desc="unlocks an app for deployment" declare cmd="apps:unlock" [[ "$1" == "$cmd" ]] && shift 1 - declare APP="$1"; verify_app_name "$APP" + declare APP="$1" + verify_app_name "$APP" if [[ -f "$DOKKU_ROOT/$APP/.deploy.lock" ]]; then - dokku_log_warn "A deploy may be in progress." - dokku_log_warn "Removing the app lock will not stop in progress deploys." + dokku_log_warn "A deploy may be in progress." + dokku_log_warn "Removing the app lock will not stop in progress deploys." fi rm -f "$DOKKU_ROOT/$APP/.deploy.lock" || dokku_log_fail "Unable to remove deploy lock" diff --git a/plugins/build-env/pre-build-buildpack b/plugins/build-env/pre-build-buildpack index 19cd835e1..022e8f74d 100755 --- a/plugins/build-env/pre-build-buildpack +++ b/plugins/build-env/pre-build-buildpack @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -10,7 +11,7 @@ build_env_pre_build_buildpack() { local IMAGE id verify_app_name "$APP" - IMAGE=$(get_app_image_name "$APP"); + IMAGE=$(get_app_image_name "$APP") [[ -z $(config_get --global CURL_CONNECT_TIMEOUT) ]] && config_set --global CURL_CONNECT_TIMEOUT=90 [[ -z $(config_get --global CURL_TIMEOUT) ]] && config_set --global CURL_TIMEOUT=600 @@ -20,12 +21,12 @@ build_env_pre_build_buildpack() { # https://github.com/niteoweb/heroku-buildpack-buildout/blob/5879fa3418f7d8e079f1aa5816ba1adde73f4948/bin/compile#L34 id=$(config_bundle --merged "$APP" | docker run "$DOKKU_GLOBAL_RUN_ARGS" -i -a stdin "$IMAGE" /bin/bash -c "mkdir -p /tmp/env; cat | tar -x -C /tmp/env") test "$(docker wait "$id")" -eq 0 - docker commit "$id" "$IMAGE" > /dev/null + docker commit "$id" "$IMAGE" >/dev/null # create build env for 'old style' buildpacks and dokku plugins id=$(config_export app "$APP" --format envfile --merged | docker run "$DOKKU_GLOBAL_RUN_ARGS" -i -a stdin "$IMAGE" /bin/bash -c "cat >> /app/.env") test "$(docker wait "$id")" -eq 0 - docker commit "$id" "$IMAGE" > /dev/null + docker commit "$id" "$IMAGE" >/dev/null } build_env_pre_build_buildpack "$@" diff --git a/plugins/certs/commands b/plugins/certs/commands index 9e13305ab..17fa444fc 100755 --- a/plugins/certs/commands +++ b/plugins/certs/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help certs:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | certs:help) diff --git a/plugins/certs/functions b/plugins/certs/functions index a130c993e..5c89238eb 100755 --- a/plugins/certs/functions +++ b/plugins/certs/functions @@ -1,10 +1,12 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" is_ssl_enabled() { declare desc="returns 0 if ssl is enabled for given app" - local APP=$1; verify_app_name "$APP" + local APP=$1 + verify_app_name "$APP" local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" if [[ -e "$APP_SSL_PATH/server.crt" ]] && [[ -e "$APP_SSL_PATH/server.key" ]]; then @@ -16,11 +18,12 @@ is_ssl_enabled() { get_ssl_hostnames() { declare desc="returns a string of ssl hostnames extracted from an app's ssl certificate" - local APP=$1; verify_app_name "$APP" + local APP=$1 + verify_app_name "$APP" local SSL_PATH="$DOKKU_ROOT/$APP/tls" local SSL_HOSTNAME=$(openssl x509 -in "$SSL_PATH/server.crt" -noout -subject | tr '/' '\n' | grep CN= | cut -c4-) - local SSL_HOSTNAME_ALT=$(openssl x509 -in "$SSL_PATH/server.crt" -noout -text | grep --after-context=1 '509v3 Subject Alternative Name:' | tail -n 1 | sed -e "s/[[:space:]]*DNS://g" | tr ',' '\n' || true) + local SSL_HOSTNAME_ALT=$(openssl x509 -in "$SSL_PATH/server.crt" -noout -text | grep --after-context=1 '509v3 Subject Alternative Name:' | tail -n 1 | sed -e "s/[[:space:]]*DNS://g" | tr ',' '\n' || true) if [[ -n "$SSL_HOSTNAME_ALT" ]]; then local SSL_HOSTNAMES="${SSL_HOSTNAME}\n${SSL_HOSTNAME_ALT}" else diff --git a/plugins/certs/internal-functions b/plugins/certs/internal-functions index 864f07351..b6ae228e0 100755 --- a/plugins/certs/internal-functions +++ b/plugins/certs/internal-functions @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/certs/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-certs-report() { declare desc="displays an ssl report for one or more apps" @@ -51,7 +52,8 @@ cmd-certs-report-single() { dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -71,7 +73,7 @@ cmd-certs-report-single() { certs_help_content_func() { declare desc="return certs plugin help content" - cat<, [DEPRECATED] Alternative for certs:report certs:add CRT KEY, Add an ssl endpoint to an app. Can also import from a tarball on stdin certs:chain CRT [CRT ...], [NOT IMPLEMENTED] Print the ordered and complete chain for the given certificate @@ -86,7 +88,7 @@ help_content } certs_help_cmd() { - if [[ $1 = "certs:help" ]] ; then + if [[ $1 == "certs:help" ]]; then echo -e 'Usage: dokku certs[:COMMAND]' echo '' echo 'Manage Dokku apps SSL (TLS) certs.' @@ -96,7 +98,7 @@ certs_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then certs_help_content_func else - cat< /dev/null + pushd "$CERTS_SET_TMP_WORK_DIR" &>/dev/null trap 'popd &> /dev/null || true; rm -rf $CERTS_SET_TMP_WORK_DIR > /dev/null' RETURN tar xvf - <&0 diff --git a/plugins/certs/subcommands/default b/plugins/certs/subcommands/default index 9591bedae..44aa722dd 100755 --- a/plugins/certs/subcommands/default +++ b/plugins/certs/subcommands/default @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" dokku_log_warn "Deprecated: Please use certs:report" diff --git a/plugins/certs/subcommands/generate b/plugins/certs/subcommands/generate index bd2185d27..6c85c6768 100755 --- a/plugins/certs/subcommands/generate +++ b/plugins/certs/subcommands/generate @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/domains/functions" @@ -13,7 +14,7 @@ certs_generate_cmd() { if [[ ! -f "$APP_SSL_PATH/server.key" ]] && [[ ! -f "$APP_SSL_PATH/server.crt" ]]; then local CERTS_GENERATE_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_certs.XXXXXXXXX") - pushd "$CERTS_GENERATE_TMP_WORK_DIR" > /dev/null + pushd "$CERTS_GENERATE_TMP_WORK_DIR" >/dev/null trap 'popd &> /dev/null || true; rm -rf "$CERTS_GENERATE_TMP_WORK_DIR" > /dev/null' INT TERM EXIT openssl genrsa -out server.key 2048 @@ -22,7 +23,7 @@ certs_generate_cmd() { mkdir -p "$APP_SSL_PATH" dokku_log_info1 "Installing certificate and key..." - mv -f "$CERTS_GENERATE_TMP_WORK_DIR/server.crt" "$CERTS_GENERATE_TMP_WORK_DIR/server.csr" "$CERTS_GENERATE_TMP_WORK_DIR/server.key" "$APP_SSL_PATH" + mv -f "$CERTS_GENERATE_TMP_WORK_DIR/server.crt" "$CERTS_GENERATE_TMP_WORK_DIR/server.csr" "$CERTS_GENERATE_TMP_WORK_DIR/server.key" "$APP_SSL_PATH" chmod 750 "$APP_SSL_PATH" chmod 640 "$APP_SSL_PATH/server.crt" "$APP_SSL_PATH/server.csr" "$APP_SSL_PATH/server.key" plugn trigger post-certs-update "$APP" diff --git a/plugins/certs/subcommands/info b/plugins/certs/subcommands/info index 9591bedae..44aa722dd 100755 --- a/plugins/certs/subcommands/info +++ b/plugins/certs/subcommands/info @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" dokku_log_warn "Deprecated: Please use certs:report" diff --git a/plugins/certs/subcommands/remove b/plugins/certs/subcommands/remove index 8b38f1f78..aeb2235ec 100755 --- a/plugins/certs/subcommands/remove +++ b/plugins/certs/subcommands/remove @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" certs_remove_cmd() { @@ -7,7 +8,8 @@ certs_remove_cmd() { local cmd="certs:remove" [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" verify_app_name "$2" - local APP="$2"; local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + local APP="$2" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" if [[ -d "$APP_SSL_PATH" ]]; then dokku_log_info1 "Removing SSL endpoint from $APP" diff --git a/plugins/certs/subcommands/report b/plugins/certs/subcommands/report index b85fd69a2..054bbf7ca 100755 --- a/plugins/certs/subcommands/report +++ b/plugins/certs/subcommands/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/certs/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-certs-report "$@" diff --git a/plugins/checks/commands b/plugins/checks/commands index 0aed38a1b..850cb9e97 100755 --- a/plugins/checks/commands +++ b/plugins/checks/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help checks:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/checks/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | checks:help) diff --git a/plugins/checks/functions b/plugins/checks/functions index f50ccc444..df7b3f6c6 100755 --- a/plugins/checks/functions +++ b/plugins/checks/functions @@ -1,15 +1,17 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" is_app_proctype_checks_disabled() { declare desc="return true if app's proctype(s) checks are disabled" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local PROCTYPE="$2" status=false local DOKKU_CHECKS_DISABLED=$(config_get "$APP" DOKKU_CHECKS_DISABLED || true) - if [[ "$DOKKU_CHECKS_DISABLED" == "_all_" ]] || [[ "$(is_val_in_list "$PROCTYPE" "$DOKKU_CHECKS_DISABLED")" == "true" ]] ;then + if [[ "$DOKKU_CHECKS_DISABLED" == "_all_" ]] || [[ "$(is_val_in_list "$PROCTYPE" "$DOKKU_CHECKS_DISABLED")" == "true" ]]; then status=true fi @@ -18,11 +20,12 @@ is_app_proctype_checks_disabled() { is_app_proctype_checks_skipped() { declare desc="return true if app's proctype(s) checks are skipped" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local PROCTYPE="$2" status=false local DOKKU_CHECKS_SKIPPED=$(config_get "$APP" DOKKU_CHECKS_SKIPPED || true) - if [[ "$DOKKU_CHECKS_SKIPPED" == "_all_" ]] || [[ "$(is_val_in_list "$PROCTYPE" "$DOKKU_CHECKS_SKIPPED")" == "true" ]] ;then + if [[ "$DOKKU_CHECKS_SKIPPED" == "_all_" ]] || [[ "$(is_val_in_list "$PROCTYPE" "$DOKKU_CHECKS_SKIPPED")" == "true" ]]; then status=true fi diff --git a/plugins/checks/install b/plugins/checks/install index 28185822a..48caebe2e 100755 --- a/plugins/checks/install +++ b/plugins/checks/install @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" diff --git a/plugins/checks/internal-functions b/plugins/checks/internal-functions index 6cd3219a2..55ea99c69 100755 --- a/plugins/checks/internal-functions +++ b/plugins/checks/internal-functions @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/checks/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-checks-report() { declare desc="shows reports for an app" @@ -45,7 +46,8 @@ cmd-checks-report-single() { dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -65,7 +67,7 @@ cmd-checks-report-single() { checks_help_content_func() { declare desc="return checks plugin help content" - cat<, [DEPRECATED] Alternative for checks:report checks:disable [process-type(s)], Disable zero-downtime deployment for all processes (or comma-separated process-type list) ***WARNING: this will cause downtime during deployments*** checks:enable [process-type(s)], Enable zero-downtime deployment for all processes (or comma-separated process-type list) @@ -76,7 +78,7 @@ help_content } checks_help_cmd() { - if [[ $1 = "checks:help" ]] ; then + if [[ $1 == "checks:help" ]]; then echo -e 'Usage: dokku checks[:COMMAND]' echo '' echo 'Manage zero-downtime settings.' @@ -86,7 +88,7 @@ checks_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then checks_help_content_func else - cat</dev/null | awk -F: '{ print $2 }' || echo '') echo "$RUNNING_IMAGE_TAG" } @@ -254,7 +261,7 @@ is_image_herokuish_based() { declare desc="returns true if app image is based on herokuish" # circleci can't support --rm as they run lxc in lxc [[ ! -f "/home/ubuntu/.circlerc" ]] && local DOCKER_ARGS="--rm" - docker run "$DOKKU_GLOBAL_RUN_ARGS" --entrypoint="/bin/sh" $DOCKER_ARGS "$@" -c "test -f /exec" &> /dev/null + docker run "$DOKKU_GLOBAL_RUN_ARGS" --entrypoint="/bin/sh" $DOCKER_ARGS "$@" -c "test -f /exec" &>/dev/null } get_docker_version() { @@ -264,7 +271,8 @@ get_docker_version() { is_number() { declare desc="returns 0 if input is a number" - local NUMBER=$1; local NUM_RE='^[0-9]+$' + local NUMBER=$1 + local NUM_RE='^[0-9]+$' if [[ $NUMBER =~ $NUM_RE ]]; then return 0 else @@ -276,18 +284,20 @@ is_abs_path() { declare desc="returns 0 if input path is absolute" local TEST_PATH=$1 if [[ "$TEST_PATH" == /* ]]; then - return 0 - else - return 1 + return 0 + else + return 1 fi } parse_args() { declare desc="top-level cli arg parser" - local next_index=1; local skip=false; local args=("$@") + local next_index=1 + local skip=false + local args=("$@") for arg in "$@"; do if [[ "$skip" == "true" ]]; then - next_index=$(( next_index + 1 )) + next_index=$((next_index + 1)) skip=false continue fi @@ -302,24 +312,27 @@ parse_args() { --trace) export DOKKU_TRACE=1 ;; - --rm-container|--rm) + --rm-container | --rm) export DOKKU_RM_CONTAINER=1 ;; --force) export DOKKU_APPS_FORCE_DELETE=1 ;; --app) - export DOKKU_APP_NAME=${args[$next_index]}; skip=true + export DOKKU_APP_NAME=${args[$next_index]} + skip=true ;; esac - next_index=$(( next_index + 1 )) + next_index=$((next_index + 1)) done return 0 } copy_from_image() { declare desc="copy file from named image to destination" - local IMAGE="$1"; local SRC_FILE="$2"; local DST_DIR="$3" + local IMAGE="$1" + local SRC_FILE="$2" + local DST_DIR="$3" verify_app_name "$APP" if verify_image "$IMAGE"; then @@ -330,7 +343,7 @@ copy_from_image() { fi local CID=$(docker create "$DOKKU_GLOBAL_RUN_ARGS" "$IMAGE") docker cp "$CID:$SRC_FILE" "$DST_DIR" - docker rm -f "$CID" &> /dev/null + docker rm -f "$CID" &>/dev/null else return 1 fi @@ -338,9 +351,10 @@ copy_from_image() { get_app_container_ids() { declare desc="returns list of docker container ids for given app and optional container_type" - local APP="$1"; local CONTAINER_TYPE="$2" + local APP="$1" + local CONTAINER_TYPE="$2" verify_app_name "$APP" - [[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(< "$DOKKU_ROOT/$APP/CONTAINER") + [[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(<"$DOKKU_ROOT/$APP/CONTAINER") if [[ -n "$CONTAINER_TYPE" ]]; then local CONTAINER_PATTERN="$DOKKU_ROOT/$APP/CONTAINER.$CONTAINER_TYPE.*" @@ -356,7 +370,7 @@ get_app_container_ids() { local DOKKU_CID_FILE for DOKKU_CID_FILE in $CONTAINER_PATTERN; do local DOKKU_CIDS+=" " - local DOKKU_CIDS+=$(< "$DOKKU_CID_FILE") + local DOKKU_CIDS+=$(<"$DOKKU_CID_FILE") local DOKKU_CIDS+=" " done shopt -u nullglob @@ -389,7 +403,7 @@ get_app_running_container_types() { CONTAINER_TYPES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -print0 2>/dev/null | xargs -0)" if [[ -n "$CONTAINER_TYPES" ]]; then CONTAINER_TYPES="${CONTAINER_TYPES//$DOKKU_ROOT\/$APP\//}" - CONTAINER_TYPES="$(tr " " $'\n' <<< "$CONTAINER_TYPES" | awk -F. '{ print $2 }' | sort | uniq | xargs)" + CONTAINER_TYPES="$(tr " " $'\n' <<<"$CONTAINER_TYPES" | awk -F. '{ print $2 }' | sort | uniq | xargs)" fi echo "$CONTAINER_TYPES" @@ -398,7 +412,10 @@ get_app_running_container_types() { is_deployed() { declare desc="return 0 if given app has a running container" local APP="$1" - if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] || [[ $(ls "$DOKKU_ROOT/$APP"/CONTAINER.* &> /dev/null; echo $?) -eq 0 ]]; then + if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]] || [[ $( + ls "$DOKKU_ROOT/$APP"/CONTAINER.* &>/dev/null + echo $? + ) -eq 0 ]]; then return 0 else return 1 @@ -425,7 +442,7 @@ is_container_status() { declare desc="return 0 if given docker container id is in given state" local CID=$1 local TEMPLATE="{{.State.$2}}" - local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" 2> /dev/null || true) + local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" 2>/dev/null || true) if [[ "$CONTAINER_STATUS" == "true" ]]; then return 0 @@ -455,7 +472,10 @@ dokku_build() { declare desc="build phase" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP="$1"; local IMAGE_SOURCE_TYPE="$2"; local TMP_WORK_DIR="$3"; local IMAGE=$(get_app_image_name "$APP") + local APP="$1" + local IMAGE_SOURCE_TYPE="$2" + local TMP_WORK_DIR="$3" + local IMAGE=$(get_app_image_name "$APP") local cid verify_app_name "$APP" @@ -463,14 +483,14 @@ dokku_build() { local DOKKU_APP_HOST_CACHE_DIR="$DOKKU_HOST_ROOT/$APP/cache" eval "$(config_export app "$APP")" - pushd "$TMP_WORK_DIR" &> /dev/null + pushd "$TMP_WORK_DIR" &>/dev/null case "$IMAGE_SOURCE_TYPE" in herokuish) DOKKU_IMAGE="$(config_get "$APP" DOKKU_IMAGE || echo "$DOKKU_IMAGE")" cid=$(tar -c . | docker run "$DOKKU_GLOBAL_RUN_ARGS" -i -a stdin "$DOKKU_IMAGE" /bin/bash -c "mkdir -p /app && tar -xC /app") test "$(docker wait "$cid")" -eq 0 - docker commit "$cid" "$IMAGE" > /dev/null + docker commit "$cid" "$IMAGE" >/dev/null [[ -d $DOKKU_APP_CACHE_DIR ]] || mkdir -p "$DOKKU_APP_CACHE_DIR" plugn trigger pre-build-buildpack "$APP" @@ -482,7 +502,7 @@ dokku_build() { cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -v $DOKKU_APP_HOST_CACHE_DIR:/cache -e CACHE_PATH=/cache "${ARG_ARRAY[@]}" $IMAGE /build) docker attach "$cid" test "$(docker wait "$cid")" -eq 0 - docker commit "$cid" "$IMAGE" > /dev/null + docker commit "$cid" "$IMAGE" >/dev/null plugn trigger post-build-buildpack "$APP" ;; @@ -502,7 +522,7 @@ dokku_build() { [[ "$DOKKU_DOCKERFILE_CACHE_BUILD" == "false" ]] && DOKKU_DOCKER_BUILD_OPTS="$DOKKU_DOCKER_BUILD_OPTS --no-cache" local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$IMAGE_SOURCE_TYPE") # strip --volume and -v args from DOCKER_ARGS - local DOCKER_ARGS=$(sed -e "s/--volume=[[:graph:]]\+[[:blank:]]\?//g" -e "s/-v[[:blank:]]\?[[:graph:]]\+[[:blank:]]\?//g" <<< "$DOCKER_ARGS") + local DOCKER_ARGS=$(sed -e "s/--volume=[[:graph:]]\+[[:blank:]]\?//g" -e "s/-v[[:blank:]]\?[[:graph:]]\+[[:blank:]]\?//g" <<<"$DOCKER_ARGS") declare -a ARG_ARRAY eval "ARG_ARRAY=($DOCKER_ARGS)" @@ -522,7 +542,10 @@ dokku_release() { declare desc="release phase" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP="$1"; local IMAGE_SOURCE_TYPE="$2"; local IMAGE_TAG="$3"; local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + local APP="$1" + local IMAGE_SOURCE_TYPE="$2" + local IMAGE_TAG="$3" + local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") local cid verify_app_name "$APP" @@ -532,12 +555,12 @@ dokku_release() { if [[ -n $(config_export global) ]]; then cid=$(config_export global | docker run "$DOKKU_GLOBAL_RUN_ARGS" -i -a stdin "$IMAGE" /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/00-global-env.sh") test "$(docker wait "$cid")" -eq 0 - docker commit "$cid" "$IMAGE" > /dev/null + docker commit "$cid" "$IMAGE" >/dev/null fi if [[ -n $(config_export app "$APP") ]]; then cid=$(config_export app "$APP" | docker run "$DOKKU_GLOBAL_RUN_ARGS" -i -a stdin "$IMAGE" /bin/bash -c "mkdir -p /app/.profile.d && cat > /app/.profile.d/01-app-env.sh") test "$(docker wait "$cid")" -eq 0 - docker commit "$cid" "$IMAGE" > /dev/null + docker commit "$cid" "$IMAGE" >/dev/null fi plugn trigger post-release-buildpack "$APP" "$IMAGE_TAG" ;; @@ -567,7 +590,9 @@ release_and_deploy() { declare desc="main function for releasing and deploying an app" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") + local APP="$1" + local IMAGE_TAG="$2" + local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") local DOKKU_DOCKERFILE_PORTS verify_app_name "$APP" @@ -609,11 +634,14 @@ dokku_receive() { declare desc="receives an app kicks off deploy process" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP="$1"; local IMAGE=$(get_app_image_name "$APP"); local IMAGE_SOURCE_TYPE="$2"; local TMP_WORK_DIR="$3" + local APP="$1" + local IMAGE=$(get_app_image_name "$APP") + local IMAGE_SOURCE_TYPE="$2" + local TMP_WORK_DIR="$3" local DOKKU_SKIP_CLEANUP="$(config_get "$APP" DOKKU_SKIP_CLEANUP || true)" docker_cleanup "$APP" dokku_log_info1 "Building $APP from $IMAGE_SOURCE_TYPE..." - config_set --no-restart "$APP" DOKKU_APP_TYPE="$IMAGE_SOURCE_TYPE" &> /dev/null + config_set --no-restart "$APP" DOKKU_APP_TYPE="$IMAGE_SOURCE_TYPE" &>/dev/null dokku_build "$APP" "$IMAGE_SOURCE_TYPE" "$TMP_WORK_DIR" release_and_deploy "$APP" } @@ -638,15 +666,15 @@ docker_cleanup() { # delete all non-running containers # shellcheck disable=SC2046 - docker rm $(docker ps -a -f "status=exited" -f "label=$DOKKU_CONTAINER_LABEL" -q) &> /dev/null || true + docker rm $(docker ps -a -f "status=exited" -f "label=$DOKKU_CONTAINER_LABEL" -q) &>/dev/null || true # delete all dead containers # shellcheck disable=SC2046 - docker rm $(docker ps -a -f "status=dead" -f "label=$DOKKU_CONTAINER_LABEL" -q) &> /dev/null || true + docker rm $(docker ps -a -f "status=dead" -f "label=$DOKKU_CONTAINER_LABEL" -q) &>/dev/null || true # delete unused images # shellcheck disable=SC2046 - docker rmi $(docker images -f 'dangling=true' -q) &> /dev/null & + docker rmi $(docker images -f 'dangling=true' -q) &>/dev/null & } get_available_port() { @@ -666,7 +694,7 @@ dokku_auth() { declare desc="calls user-auth plugin trigger" export SSH_USER=${SSH_USER:=$USER} export SSH_NAME=${NAME:="default"} - if ! plugn trigger user-auth "$SSH_USER" "$SSH_NAME" "$@" ; then + if ! plugn trigger user-auth "$SSH_USER" "$SSH_NAME" "$@"; then return 1 fi return 0 @@ -680,18 +708,18 @@ _ipv4_regex() { _ipv6_regex() { declare desc="ipv6 regex" local RE_IPV4="$(_ipv4_regex)" - local RE_IPV6="([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" # TEST: 1:2:3:4:5:6:7:8 - local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,7}:|" # TEST: 1:: 1:2:3:4:5:6:7:: - local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" # TEST: 1::8 1:2:3:4:5:6::8 1:2:3:4:5:6::8 - local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" # TEST: 1::7:8 1:2:3:4:5::7:8 1:2:3:4:5::8 - local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" # TEST: 1::6:7:8 1:2:3:4::6:7:8 1:2:3:4::8 - local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" # TEST: 1::5:6:7:8 1:2:3::5:6:7:8 1:2:3::8 - local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" # TEST: 1::4:5:6:7:8 1:2::4:5:6:7:8 1:2::8 - local RE_IPV6="${RE_IPV6}[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" # TEST: 1::3:4:5:6:7:8 1::3:4:5:6:7:8 1::8 - local RE_IPV6="${RE_IPV6}:((:[0-9a-fA-F]{1,4}){1,7}|:)|" # TEST: ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 :: - local RE_IPV6="${RE_IPV6}fe08:(:[0-9a-fA-F]{1,4}){2,2}%[0-9a-zA-Z]{1,}|" # TEST: fe08::7:8%eth0 fe08::7:8%1 (link-local IPv6 addresses with zone index) - local RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) - local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 + local RE_IPV6="([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|" # TEST: 1:2:3:4:5:6:7:8 + local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,7}:|" # TEST: 1:: 1:2:3:4:5:6:7:: + local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|" # TEST: 1::8 1:2:3:4:5:6::8 1:2:3:4:5:6::8 + local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|" # TEST: 1::7:8 1:2:3:4:5::7:8 1:2:3:4:5::8 + local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|" # TEST: 1::6:7:8 1:2:3:4::6:7:8 1:2:3:4::8 + local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|" # TEST: 1::5:6:7:8 1:2:3::5:6:7:8 1:2:3::8 + local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|" # TEST: 1::4:5:6:7:8 1:2::4:5:6:7:8 1:2::8 + local RE_IPV6="${RE_IPV6}[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|" # TEST: 1::3:4:5:6:7:8 1::3:4:5:6:7:8 1::8 + local RE_IPV6="${RE_IPV6}:((:[0-9a-fA-F]{1,4}){1,7}|:)|" # TEST: ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 :: + local RE_IPV6="${RE_IPV6}fe08:(:[0-9a-fA-F]{1,4}){2,2}%[0-9a-zA-Z]{1,}|" # TEST: fe08::7:8%eth0 fe08::7:8%1 (link-local IPv6 addresses with zone index) + local RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) + local RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 echo "$RE_IPV6" } @@ -719,7 +747,8 @@ get_dockerfile_exposed_ports() { get_exposed_ports_from_image() { declare desc="return all exposed ports from passed image name" - local IMAGE="$1"; verify_image "$IMAGE" + local IMAGE="$1" + verify_image "$IMAGE" # shellcheck disable=SC2016 local DOCKER_IMAGE_EXPOSED_PORTS="$(docker inspect -f '{{range $key, $value := .Config.ExposedPorts}}{{$key}} {{end}}' "$IMAGE")" echo "$DOCKER_IMAGE_EXPOSED_PORTS" @@ -727,14 +756,16 @@ get_exposed_ports_from_image() { get_entrypoint_from_image() { declare desc="return .Config.Entrypoint from passed image name" - local IMAGE="$1"; verify_image "$IMAGE" + local IMAGE="$1" + verify_image "$IMAGE" local DOCKER_IMAGE_ENTRYPOINT="$(docker inspect --format '{{range .Config.Entrypoint}}{{.}} {{end}}' "$IMAGE")" echo "ENTRYPOINT $DOCKER_IMAGE_ENTRYPOINT" } get_cmd_from_image() { declare desc="return .Config.Cmd from passed image name" - local IMAGE="$1"; verify_image "$IMAGE" + local IMAGE="$1" + verify_image "$IMAGE" local DOCKER_IMAGE_CMD="$(docker inspect --format '{{range .Config.Cmd}}{{.}} {{end}}' "$IMAGE")" DOCKER_IMAGE_CMD="${DOCKER_IMAGE_CMD/\/bin\/sh -c/}" echo "CMD $DOCKER_IMAGE_CMD" @@ -742,7 +773,8 @@ get_cmd_from_image() { extract_directive_from_dockerfile() { declare desc="return requested directive from passed file path" - local FILE_PATH="$1"; local SEARCH_STRING="$2" + local FILE_PATH="$1" + local SEARCH_STRING="$2" local FOUND_LINE=$(egrep "^${SEARCH_STRING} " "$FILE_PATH" | tail -n1) || true echo "$FOUND_LINE" } @@ -751,21 +783,23 @@ get_app_raw_tcp_ports() { declare desc="extracts raw tcp port numbers from DOCKERFILE_PORTS config variable" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local DOCKERFILE_PORTS="$(config_get "$APP" DOKKU_DOCKERFILE_PORTS)" for p in $DOCKERFILE_PORTS; do if [[ ! "$p" =~ .*udp.* ]]; then - p=${p//\/tcp} + p=${p//\/tcp/} raw_tcp_ports+="$p " fi done - local raw_tcp_ports="$(echo "$raw_tcp_ports"| xargs)" + local raw_tcp_ports="$(echo "$raw_tcp_ports" | xargs)" echo "$raw_tcp_ports" } get_container_ports() { declare desc="returns published ports from app containers" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local APP_CIDS="$(get_app_container_ids "$APP")" local cid @@ -808,8 +842,8 @@ internal_get_app_urls() { local port_map app_vhost local app_vhosts=$(get_app_domains "$APP") for port_map in $DOKKU_PROXY_PORT_MAP; do - local scheme="$(awk -F ':' '{ print $1 }' <<< "$port_map")" - local listen_port="$(awk -F ':' '{ print $2 }' <<< "$port_map")" + local scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")" + local listen_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")" for app_vhost in $app_vhosts; do if [[ "$listen_port" != "80" ]] && [[ "$listen_port" != "443" ]]; then port_urls+=" $scheme://$app_vhost:$listen_port " @@ -819,7 +853,7 @@ internal_get_app_urls() { done done fi - local port_urls="$(echo "$port_urls"| xargs)" + local port_urls="$(echo "$port_urls" | xargs)" local URLS="$(merge_dedupe_list "$port_urls $app_urls" " ")" case "$1" in url) @@ -828,13 +862,14 @@ internal_get_app_urls() { else echo "$URLS" | tr ' ' '\n' | head -n1 fi - ;; + ;; urls) echo "$URLS" | tr ' ' '\n' | sort - ;; + ;; esac else - local SCHEME="http"; local SSL="$DOKKU_ROOT/$APP/tls" + local SCHEME="http" + local SSL="$DOKKU_ROOT/$APP/tls" if [[ -e "$SSL/server.crt" && -e "$SSL/server.key" ]]; then local SCHEME="https" fi @@ -844,30 +879,30 @@ internal_get_app_urls() { local APP_CONTAINER_PORTS="$(get_container_ports "$APP")" local app_port for app_port in $APP_CONTAINER_PORTS; do - echo "$(< "$DOKKU_ROOT/HOSTNAME"):$app_port (container)" + echo "$(<"$DOKKU_ROOT/HOSTNAME"):$app_port (container)" done else local DOKKU_APP_LISTENERS PORT DOKKU_APP_LISTENERS="$(plugn trigger network-get-listeners "$APP" | xargs)" for DOKKU_APP_LISTENER in $DOKKU_APP_LISTENERS; do PORT="$(echo "$DOKKU_APP_LISTENER" | cut -d ':' -f2)" - echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$PORT (container)" + echo "$SCHEME://$(<"$DOKKU_ROOT/HOSTNAME"):$PORT (container)" done shopt -u nullglob fi elif [[ -n "$DOKKU_PROXY_PORT_MAP" ]]; then local port_map for port_map in $DOKKU_PROXY_PORT_MAP; do - local scheme="$(awk -F ':' '{ print $1 }' <<< "$port_map")" - local listen_port="$(awk -F ':' '{ print $2 }' <<< "$port_map")" - echo "$scheme://$(< "$DOKKU_ROOT/HOSTNAME"):$listen_port" + local scheme="$(awk -F ':' '{ print $1 }' <<<"$port_map")" + local listen_port="$(awk -F ':' '{ print $2 }' <<<"$port_map")" + echo "$scheme://$(<"$DOKKU_ROOT/HOSTNAME"):$listen_port" done elif [[ -n "$RAW_TCP_PORTS" ]]; then for p in $RAW_TCP_PORTS; do - echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$p" + echo "http://$(<"$DOKKU_ROOT/HOSTNAME"):$p" done else - echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")" + echo "$SCHEME://$(<"$DOKKU_ROOT/VHOST")" fi fi } @@ -879,7 +914,7 @@ get_json_value() { local JSON_NODE="$1" local JSON_NODE=${JSON_NODE//\./\"][\"} local JSON_NODE="[\"${JSON_NODE}\"]" - cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print json.dumps(obj'"${JSON_NODE}"').strip("\"")'; + cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print json.dumps(obj'"${JSON_NODE}"').strip("\"")' } get_json_keys() { @@ -889,9 +924,9 @@ get_json_keys() { local JSON_NODE=${JSON_NODE//\./\"][\"} local JSON_NODE="[\"${JSON_NODE}\"]" if [[ "$JSON_NODE" == "[\"\"]" ]]; then - cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print " ".join(obj.keys())'; + cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print " ".join(obj.keys())' else - cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print " ".join(obj'"${JSON_NODE}"'.keys())'; + cat | python2.7 -c 'import json,sys;obj=json.load(sys.stdin);print " ".join(obj'"${JSON_NODE}"'.keys())' fi } @@ -938,13 +973,14 @@ merge_dedupe_list() { declare desc="combine lists ($1) separated by delimiter ($2) (delimiter defaults to comma), dedupe and return list" local input_lists="$1" delimiter="${2:-,}" - local merged_list="$(tr "$delimiter" $'\n' <<< "$input_lists" | sort | uniq | xargs)" + local merged_list="$(tr "$delimiter" $'\n' <<<"$input_lists" | sort | uniq | xargs)" echo "$merged_list" } acquire_app_deploy_lock() { declare desc="acquire advisory lock for use in git/tar deploys" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local LOCK_TYPE="${2:-waiting}" local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock" local LOCK_WAITING_MSG="$APP currently has a deploy lock in place. Waiting..." @@ -955,7 +991,8 @@ acquire_app_deploy_lock() { release_app_deploy_lock() { declare desc="release advisory lock used in git/tar deploys" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock" release_advisory_lock "$APP_DEPLOY_LOCK_FILE" @@ -969,7 +1006,10 @@ acquire_advisory_lock() { eval "exec $LOCK_FD>$LOCK_FILE" if [[ "$LOCK_TYPE" == "waiting" ]]; then - while [[ $(flock -n "$LOCK_FD" &>/dev/null ; echo $?) -ne 0 ]]; do + while [[ $( + flock -n "$LOCK_FD" &>/dev/null + echo $? + ) -ne 0 ]]; do if [[ "$SHOW_MSG" == "true" ]]; then echo "$LOCK_WAITING_MSG" SHOW_MSG=false @@ -986,7 +1026,7 @@ release_advisory_lock() { local LOCK_FILE="$1" local LOCK_FD="200" - flock -u "$LOCK_FD" && rm -f "$LOCK_FILE" &> /dev/null + flock -u "$LOCK_FD" && rm -f "$LOCK_FILE" &>/dev/null } suppress_output() { @@ -995,7 +1035,7 @@ suppress_output() { TMP_COMMAND_OUTPUT=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX") trap 'rm -rf "$TMP_COMMAND_OUTPUT" > /dev/null' RETURN INT TERM EXIT - "$@" > "$TMP_COMMAND_OUTPUT" 2>&1 || { + "$@" >"$TMP_COMMAND_OUTPUT" 2>&1 || { local exit_code="$?" cat "$TMP_COMMAND_OUTPUT" return "$exit_code" diff --git a/plugins/common/property-functions b/plugins/common/property-functions index 73828e286..394bc0d9e 100755 --- a/plugins/common/property-functions +++ b/plugins/common/property-functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x fn-plugin-property-delete() { declare desc="delete a key from the property store for an app" @@ -97,6 +98,6 @@ fn-plugin-property-write() { fi mkdir -p "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}" - echo "$VALUE" > "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}/${KEY}" + echo "$VALUE" >"${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}/${KEY}" chmod 600 "${DOKKU_LIB_ROOT}/config/${PLUGIN}/${APP}/${KEY}" } diff --git a/plugins/common/vendor/github.com/codegangsta/inject/update_readme.sh b/plugins/common/vendor/github.com/codegangsta/inject/update_readme.sh index 497f9a577..3cb21111c 100644 --- a/plugins/common/vendor/github.com/codegangsta/inject/update_readme.sh +++ b/plugins/common/vendor/github.com/codegangsta/inject/update_readme.sh @@ -1,3 +1,3 @@ #!/bin/bash go get github.com/robertkrimen/godocdown/godocdown -godocdown > README.md +godocdown >README.md diff --git a/plugins/config/docker-args-deploy b/plugins/config/docker-args-deploy index 367a0f80d..f47712ce7 100755 --- a/plugins/config/docker-args-deploy +++ b/plugins/config/docker-args-deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -9,7 +10,7 @@ config_docker_args() { local ENV_ARGS IMAGE STDIN trigger IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") - STDIN=$(cat); + STDIN=$(cat) trigger="$0 config_docker_args" verify_app_name "$APP" diff --git a/plugins/config/functions b/plugins/config/functions index 6a36ec9d2..70688b7d7 100755 --- a/plugins/config/functions +++ b/plugins/config/functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" config_sub() { @@ -23,7 +24,6 @@ config_export() { return 0 } - config_all() { declare desc="Backwards compatible function for plugin use" [[ "$1" == "config" ]] || set -- "config" "$@" diff --git a/plugins/docker-options/commands b/plugins/docker-options/commands index 5e795c1d5..ea9b8b268 100755 --- a/plugins/docker-options/commands +++ b/plugins/docker-options/commands @@ -1,10 +1,11 @@ #!/usr/bin/env bash [[ " help docker-options:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x docker_options_help_content_func() { - declare desc="return docker-options plugin help content" - cat< [phase(s)], [DEPRECATED] Alternative for docker-options:report docker-options:add OPTION, Add Docker option to app for phase (comma separated phase list) docker-options:remove OPTION, Remove Docker option from app for phase (comma separated phase list) @@ -13,7 +14,7 @@ help_content } docker_options_help_cmd() { - if [[ $1 = "docker-options:help" ]] ; then + if [[ $1 == "docker-options:help" ]]; then echo -e 'Usage: dokku docker-options[:COMMAND]' echo '' echo 'Display app'"'"'s Docker options for all phases.' @@ -23,7 +24,7 @@ docker_options_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then docker_options_help_content_func else - cat<> "$phase_file_path" - local all_phase_options="$(< "$phase_file_path")" - echo -e "${all_phase_options}" | sed '/^$/d' | sort -u > "$phase_file_path" + echo "${passed_option_string}" >>"$phase_file_path" + local all_phase_options="$(<"$phase_file_path")" + echo -e "${all_phase_options}" | sed '/^$/d' | sort -u >"$phase_file_path" done } @@ -101,9 +103,9 @@ remove_passed_docker_option() { for phase in "${passed_phases[@]}"; do local phase_file_path="$(get_phase_file_path "$phase")" [[ ! -s "$phase_file_path" ]] || { - local all_phase_options="$(< "$phase_file_path")" + local all_phase_options="$(<"$phase_file_path")" local all_phase_options=$(echo -e "${all_phase_options}" | sed "s#^${passed_option_string}\$##") - echo -e "${all_phase_options}" | sed '/^$/d' | sort -u > "$phase_file_path" + echo -e "${all_phase_options}" | sed '/^$/d' | sort -u >"$phase_file_path" } done } diff --git a/plugins/docker-options/internal-functions b/plugins/docker-options/internal-functions index b73e7e421..5d3f4494f 100755 --- a/plugins/docker-options/internal-functions +++ b/plugins/docker-options/internal-functions @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-docker-options-report() { declare desc="displays a docker options report for one or more apps" @@ -46,7 +47,8 @@ cmd-docker-options-report-single() { dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -68,6 +70,6 @@ fn-docker-options() { declare APP="$1" PHASE="$2" local PHASE_FILE="$(fn-get-phase-file-path "$APP" "$PHASE")" if [[ -r "$PHASE_FILE" ]]; then - tr '\n' ' ' < "$PHASE_FILE" + tr '\n' ' ' <"$PHASE_FILE" fi } diff --git a/plugins/docker-options/report b/plugins/docker-options/report index b83b2df2f..722271960 100755 --- a/plugins/docker-options/report +++ b/plugins/docker-options/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/docker-options/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-docker-options-report-single "$@" diff --git a/plugins/docker-options/subcommands/add b/plugins/docker-options/subcommands/add index 8a5242243..72d64129c 100755 --- a/plugins/docker-options/subcommands/add +++ b/plugins/docker-options/subcommands/add @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" @@ -8,7 +9,7 @@ docker_options_add_cmd() { local cmd="docker-options:add" verify_app_name "$2" && local APP="$2" - read -ra passed_phases <<< "$(get_phases "$3")" + read -ra passed_phases <<<"$(get_phases "$3")" shift 3 # everything else passed is the docker option local passed_docker_option="$*" [[ -z "$passed_docker_option" ]] && dokku_log_fail "Please specify docker options to add to the phase" diff --git a/plugins/docker-options/subcommands/default b/plugins/docker-options/subcommands/default index 4cfaa6114..8032e9a84 100755 --- a/plugins/docker-options/subcommands/default +++ b/plugins/docker-options/subcommands/default @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" @@ -9,7 +10,7 @@ docker_options_main_cmd() { dokku_log_warn "Deprecated: Please use docker-options:report" verify_app_name "$2" && local APP="$2" - read -ra passed_phases <<< "$(get_phases "$3")" + read -ra passed_phases <<<"$(get_phases "$3")" if [[ ! "${passed_phases[@]}" ]]; then display_all_phases_options else diff --git a/plugins/docker-options/subcommands/remove b/plugins/docker-options/subcommands/remove index 58f62ec86..d63be3822 100755 --- a/plugins/docker-options/subcommands/remove +++ b/plugins/docker-options/subcommands/remove @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" @@ -8,7 +9,7 @@ docker_options_remove_cmd() { local cmd="docker-options:remove" verify_app_name "$2" && local APP="$2" - read -ra passed_phases <<< "$(get_phases "$3")" + read -ra passed_phases <<<"$(get_phases "$3")" shift 3 # everything else passed is the docker option # shellcheck disable=SC2154 [[ -z ${passed_docker_option="$@"} ]] && dokku_log_fail "Please specify docker options to remove from the phase" diff --git a/plugins/docker-options/subcommands/report b/plugins/docker-options/subcommands/report index 4cb6cefbc..5985f4add 100755 --- a/plugins/docker-options/subcommands/report +++ b/plugins/docker-options/subcommands/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/docker-options/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-docker-options-report "$@" diff --git a/plugins/domains/commands b/plugins/domains/commands index 1ed2fde7f..328664b40 100755 --- a/plugins/domains/commands +++ b/plugins/domains/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help domains:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/domains/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | domains:help) diff --git a/plugins/domains/functions b/plugins/domains/functions index de995c782..83d17e8e7 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -1,12 +1,14 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" disable_app_vhost() { declare desc="disable vhost support for given application" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP=$1; verify_app_name "$APP" + local APP=$1 + verify_app_name "$APP" local APP_VHOST_FILE="$DOKKU_ROOT/$APP/VHOST" local APP_URLS_FILE="$DOKKU_ROOT/$APP/URLS" @@ -28,14 +30,17 @@ disable_app_vhost() { domains_setup() { declare desc="setup domains to default state" verify_app_name "$1" - local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"; local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" - local RE_IPV4="$(get_ipv4_regex)"; local RE_IPV6="$(get_ipv6_regex)" + local APP="$1" + local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" + local RE_IPV4="$(get_ipv4_regex)" + local RE_IPV6="$(get_ipv6_regex)" local DEFAULT_VHOSTS="$(get_default_vhosts "$APP")" if [[ ! -f $APP_VHOST_PATH ]]; then if [[ -n "$DEFAULT_VHOSTS" ]]; then dokku_log_info1 "Creating new $APP_VHOST_PATH..." - echo "$DEFAULT_VHOSTS" > "$APP_VHOST_PATH" + echo "$DEFAULT_VHOSTS" >"$APP_VHOST_PATH" else dokku_log_info2 "no global VHOST set. disabling vhost support" disable_app_vhost "$APP" --no-restart @@ -46,7 +51,8 @@ domains_setup() { domains_add() { declare desc="add list of domains to app" verify_app_name "$1" - local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + local APP="$1" + local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" shift 1 for DOMAIN in "$@"; do @@ -56,10 +62,13 @@ domains_add() { done for DOMAIN in "$@"; do - if [[ $(egrep -w "^$DOMAIN$" "$APP_VHOST_PATH" > /dev/null 2>&1; echo $?) -eq 0 ]]; then + if [[ $( + egrep -w "^$DOMAIN$" "$APP_VHOST_PATH" >/dev/null 2>&1 + echo $? + ) -eq 0 ]]; then dokku_log_info1 "Skipping: $DOMAIN already added to $APP" else - echo "$DOMAIN" >> "$APP_VHOST_PATH" + echo "$DOMAIN" >>"$APP_VHOST_PATH" dokku_log_info1 "Added $DOMAIN to $APP" fi done @@ -74,7 +83,8 @@ domains_add() { domains_remove() { declare desc="remove list of app domains" verify_app_name "$1" - local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + local APP="$1" + local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" shift 1 touch "$APP_VHOST_PATH" @@ -88,7 +98,8 @@ domains_remove() { domains_set() { declare desc="set list of domains for app" verify_app_name "$1" - local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + local APP="$1" + local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" shift 1 touch "$APP_VHOST_PATH" @@ -98,7 +109,7 @@ domains_set() { fi done - echo "$*" | tr " " "\n" > "$APP_VHOST_PATH" + echo "$*" | tr " " "\n" >"$APP_VHOST_PATH" dokku_log_info1 "Set $* for $APP" if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then @@ -111,7 +122,8 @@ domains_set() { domains_disable() { declare desc="disable domains/VHOST support" verify_app_name "$1" - local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + local APP="$1" + local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" touch "$APP_VHOST_PATH" if [[ "$(is_app_vhost_enabled "$APP")" == "true" ]]; then @@ -124,13 +136,14 @@ domains_disable() { domains_enable() { declare desc="enable domains/VHOST support" verify_app_name "$1" - local APP="$1"; local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + local APP="$1" + local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" local DEFAULT_VHOSTS="$(get_default_vhosts "$APP")" touch "$APP_VHOST_PATH" if [[ "$(is_app_vhost_enabled "$APP")" == "false" ]]; then if [[ -n "$DEFAULT_VHOSTS" ]]; then - echo "$DEFAULT_VHOSTS" > "$APP_VHOST_PATH" + echo "$DEFAULT_VHOSTS" >"$APP_VHOST_PATH" fi [[ "$2" == "--no-restart" ]] && local ENABLE_APP_VHOST_ARGS=$2 enable_app_vhost "$APP" "$ENABLE_APP_VHOST_ARGS" @@ -151,7 +164,10 @@ domains_add_global() { done for DOMAIN in "$@"; do - if [[ $(egrep -w "^$DOMAIN$" "$GLOBAL_VHOST_PATH" > /dev/null 2>&1; echo $?) -eq 0 ]]; then + if [[ $( + egrep -w "^$DOMAIN$" "$GLOBAL_VHOST_PATH" >/dev/null 2>&1 + echo $? + ) -eq 0 ]]; then dokku_log_info1 "Skipping: $DOMAIN already added" else sed -i -e "\$a\\$DOMAIN" "$GLOBAL_VHOST_PATH" @@ -182,7 +198,7 @@ domains_set_global() { fi done - echo "$*" | tr " " "\n" > "$GLOBAL_VHOST_PATH" + echo "$*" | tr " " "\n" >"$GLOBAL_VHOST_PATH" dokku_log_info1 "Set $*" } @@ -190,7 +206,8 @@ enable_app_vhost() { declare desc="enable vhost support for given application" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP=$1; verify_app_name "$APP" + local APP=$1 + verify_app_name "$APP" plugn trigger pre-enable-vhost "$APP" [[ "$2" == "--no-restart" ]] && local CONFIG_SET_ARGS=$2 @@ -201,7 +218,8 @@ enable_app_vhost() { get_app_domains() { declare desc="return app domains" verify_app_name "$1" - local APP=$1; local APP_VHOST_FILE="$DOKKU_ROOT/$APP/VHOST" + local APP=$1 + local APP_VHOST_FILE="$DOKKU_ROOT/$APP/VHOST" local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST" local GLOBAL_HOSTNAME_PATH="$DOKKU_ROOT/HOSTNAME" @@ -219,8 +237,9 @@ get_app_domains() { get_default_vhosts() { declare desc="return default vhosts" verify_app_name "$1" - local APP="$1"; local RE_IPV4="$(get_ipv4_regex)"; local RE_IPV6="$(get_ipv6_regex)" - + local APP="$1" + local RE_IPV4="$(get_ipv4_regex)" + local RE_IPV6="$(get_ipv6_regex)" if [[ "$(is_global_vhost_enabled)" == "true" ]]; then local VHOSTS=$(get_global_vhosts) @@ -238,14 +257,14 @@ get_default_vhosts() { fi echo "$hostname" fi - done <<< "$VHOSTS" + done <<<"$VHOSTS" fi } get_global_vhosts() { declare desc="return global vhosts" local GLOBAL_VHOST_FILE="$DOKKU_ROOT/VHOST" - [[ -f "$GLOBAL_VHOST_FILE" ]] && local GLOBAL_VHOSTS=$(< "$GLOBAL_VHOST_FILE") + [[ -f "$GLOBAL_VHOST_FILE" ]] && local GLOBAL_VHOSTS=$(<"$GLOBAL_VHOST_FILE") echo "$GLOBAL_VHOSTS" } @@ -253,7 +272,8 @@ is_app_vhost_enabled() { declare desc="returns true or false if vhost support is enabled for a given application" source "$PLUGIN_AVAILABLE_PATH/config/functions" - local APP=$1; verify_app_name "$APP" + local APP=$1 + verify_app_name "$APP" local NO_VHOST=$(config_get "$APP" NO_VHOST) local APP_VHOST_ENABLED=true @@ -276,14 +296,15 @@ is_global_vhost_enabled() { local GLOBAL_VHOSTS_ENABLED=true break fi - done <<< "$GLOBAL_VHOSTS" + done <<<"$GLOBAL_VHOSTS" echo $GLOBAL_VHOSTS_ENABLED } is_valid_hostname() { declare desc="return 0 if argument is a valid hostname; else return 1" - local hostname_string="${1,,}"; local hostname_regex='^([a-z0-9\*-]+\.)*[a-z0-9\*-]+$' + local hostname_string="${1,,}" + local hostname_regex='^([a-z0-9\*-]+\.)*[a-z0-9\*-]+$' if [[ $hostname_string =~ $hostname_regex ]]; then return 0 else diff --git a/plugins/domains/install b/plugins/domains/install index 6fd5a2a58..ff8f02b82 100755 --- a/plugins/domains/install +++ b/plugins/domains/install @@ -1,9 +1,10 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/domains/functions" shopt -s nullglob for app in $DOKKU_ROOT/*/CONTAINER; do - APP=$(basename "$(dirname "$app")"); + APP=$(basename "$(dirname "$app")") domains_setup "$APP" done diff --git a/plugins/domains/internal-functions b/plugins/domains/internal-functions index b5043d213..f93d51429 100755 --- a/plugins/domains/internal-functions +++ b/plugins/domains/internal-functions @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/domains/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-domains-report() { declare desc="displays a domains report for one or more apps" @@ -47,7 +48,8 @@ cmd-domains-report-single() { dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -65,9 +67,9 @@ cmd-domains-report-single() { fi } -domains_help_content_func () { - declare desc="return domains plugin help content" - cat<], [DEPRECATED] Alternative for domains:report domains:add [ ...], Add domains to app domains:add-global [ ...], Add global domain names @@ -83,7 +85,7 @@ help_content } domains_help_cmd() { - if [[ $1 = "domains:help" ]] ; then + if [[ $1 == "domains:help" ]]; then echo -e 'Usage: dokku domains[:COMMAND]' echo '' echo 'Manage vhost domains used by the Dokku proxy.' @@ -93,7 +95,7 @@ domains_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then domains_help_content_func else - cat< [ || --container-id ], Connect to a specific app container help_content } - if [[ $1 = "enter:help" ]] ; then - echo -e 'Usage: dokku enter ' - echo '' - echo 'Allows you to access a bash prompt inside the container of the app.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, + if [[ $1 == "enter:help" ]]; then + echo -e 'Usage: dokku enter ' + echo '' + echo 'Allows you to access a bash prompt inside the container of the app.' + echo '' + echo 'Additional commands:' + help_content_func | sort | column -c2 -t -s, else - help_content_func + help_content_func fi ;; diff --git a/plugins/enter/subcommands/default b/plugins/enter/subcommands/default index cc9296d99..22b27b6d5 100755 --- a/plugins/enter/subcommands/default +++ b/plugins/enter/subcommands/default @@ -1,12 +1,16 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" enter_default_cmd() { declare desc="enters running app container of specified proc type" local cmd="enter" - local APP="$2"; local CONTAINER_TYPE="$3"; local IMAGE_TAG=$(get_running_image_tag "$APP"); local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") + local APP="$2" + local CONTAINER_TYPE="$3" + local IMAGE_TAG=$(get_running_image_tag "$APP") + local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") verify_app_name "$APP" local AVAILABLE_CONTAINER_TYPES=($(get_app_running_container_types "$APP")) @@ -20,7 +24,7 @@ enter_default_cmd() { fi if [[ "$3" == "--container-id" ]]; then - local DOKKU_APP_CIDS=( $(get_app_container_ids "$APP") ) + local DOKKU_APP_CIDS=($(get_app_container_ids "$APP")) if [[ ! -n "$4" ]]; then dokku_log_warn "No container id specified." dokku_log_fail "Available ids for app ($APP): ${DOKKU_APP_CIDS[*]}" @@ -32,7 +36,7 @@ enter_default_cmd() { local ID=$(printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -e "^$4") shift 4 else - local DOKKU_APP_CIDS=( $(get_app_container_ids "$APP" "$CONTAINER_TYPE") ) + local DOKKU_APP_CIDS=($(get_app_container_ids "$APP" "$CONTAINER_TYPE")) local ID=${DOKKU_APP_CIDS[0]} if [[ ! -n $ID ]]; then dokku_log_warn "No containers found for type '$CONTAINER_TYPE'" diff --git a/plugins/git/commands b/plugins/git/commands index bb9160cc6..654cbcc98 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/git/functions" source "$PLUGIN_AVAILABLE_PATH/git/internal-functions" diff --git a/plugins/git/deploy-source b/plugins/git/deploy-source index 8f086c7be..cc243b081 100755 --- a/plugins/git/deploy-source +++ b/plugins/git/deploy-source @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x git_deploy_source() { declare desc="git deploy-source plugin trigger" @@ -10,8 +11,8 @@ git_deploy_source() { # bail if another source is detected if [[ -n "$STDIN" ]]; then - echo "$STDIN" - return + echo "$STDIN" + return fi if [[ -d "$DOKKU_ROOT/$APP/refs" ]]; then diff --git a/plugins/git/functions b/plugins/git/functions index 663796103..e561e2c21 100755 --- a/plugins/git/functions +++ b/plugins/git/functions @@ -3,7 +3,8 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/apps/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x use_git_worktree() { declare desc="detects whether to use git worktree" @@ -37,16 +38,16 @@ git_build_app_repo() { chmod 755 "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" unset GIT_DIR GIT_WORK_TREE - ! apps_exists "$APP" > /dev/null 2>&1 && apps_maybe_create "$APP" + ! apps_exists "$APP" >/dev/null 2>&1 && apps_maybe_create "$APP" if use_git_worktree; then # git worktree - this method uses git worktree which was introduced in git 2.5 - pushd "$DOKKU_ROOT/$APP" > /dev/null + pushd "$DOKKU_ROOT/$APP" >/dev/null # unset the git quarantine path to allow us to use 2.13.0+ # See this issue for more information: https://github.com/dokku/dokku/issues/2796 suppress_output env -u GIT_QUARANTINE_PATH git worktree add "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" "$REV" - popd > /dev/null 2>&1 || pushd "/tmp" > /dev/null - pushd "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" > /dev/null + popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null + pushd "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" >/dev/null else # git clone - this method creates a new git repository and adds the primary # repo as a remote, then does a fetch depth=1 to avoid cloning @@ -54,24 +55,24 @@ git_build_app_repo() { # Not working for git >= 2.11.0 due to changes introduced # in this merge: # https://github.com/git/git/commit/25ab004c53cdcfea485e5bf437aeaa74df47196d - pushd "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" > /dev/null - GIT_DIR="$DOKKU_ROOT/$APP" git tag -d "$TMP_TAG" &> /dev/null || true - GIT_DIR="$DOKKU_ROOT/$APP" git tag "$TMP_TAG" "$REV" &> /dev/null - git init &> /dev/null + pushd "$GIT_BUILD_APP_REPO_TMP_WORK_DIR" >/dev/null + GIT_DIR="$DOKKU_ROOT/$APP" git tag -d "$TMP_TAG" &>/dev/null || true + GIT_DIR="$DOKKU_ROOT/$APP" git tag "$TMP_TAG" "$REV" &>/dev/null + git init &>/dev/null git config advice.detachedHead false - git remote add origin "$DOKKU_ROOT/$APP" &> /dev/null - git fetch --depth=1 origin "refs/tags/$TMP_TAG" &> /dev/null - git reset --hard FETCH_HEAD &> /dev/null - GIT_DIR="$DOKKU_ROOT/$APP" git tag -d "$TMP_TAG" &> /dev/null || true + git remote add origin "$DOKKU_ROOT/$APP" &>/dev/null + git fetch --depth=1 origin "refs/tags/$TMP_TAG" &>/dev/null + git reset --hard FETCH_HEAD &>/dev/null + GIT_DIR="$DOKKU_ROOT/$APP" git tag -d "$TMP_TAG" &>/dev/null || true fi suppress_output env -u GIT_QUARANTINE_PATH git submodule update --init --recursive - find . -name .git -prune -exec rm -rf {} \; > /dev/null + find . -name .git -prune -exec rm -rf {} \; >/dev/null if use_git_worktree; then - pushd "$DOKKU_ROOT/$APP" > /dev/null + pushd "$DOKKU_ROOT/$APP" >/dev/null git worktree prune - popd > /dev/null + popd >/dev/null fi local DOKKU_APP_DISABLE_ANSI_PREFIX_REMOVAL DOKKU_GLOBAL_DISABLE_ANSI_PREFIX_REMOVAL DOKKU_DISABLE_ANSI_PREFIX_REMOVAL @@ -91,7 +92,10 @@ git_trigger_build() { declare APP="$1" TMP_WORK_DIR="$2" REV="$3" plugn trigger post-extract "$APP" "$TMP_WORK_DIR" "$REV" - if [[ -f Dockerfile ]] && [[ "$([[ -f .env ]] && grep -q BUILDPACK_URL .env; echo $?)" != "0" ]] && [[ ! -f ".buildpacks" ]] && [[ -z $(config_get "$APP" BUILDPACK_URL || true) ]]; then + if [[ -f Dockerfile ]] && [[ "$( + [[ -f .env ]] && grep -q BUILDPACK_URL .env + echo $? + )" != "0" ]] && [[ ! -f ".buildpacks" ]] && [[ -z $(config_get "$APP" BUILDPACK_URL || true) ]]; then plugn trigger pre-receive-app "$APP" "dockerfile" "$TMP_WORK_DIR" "$REV" dokku_receive "$APP" "dockerfile" "$TMP_WORK_DIR" else @@ -119,12 +123,12 @@ git_deploy_branch() { git_hook_cmd() { declare desc="kick off receive-app trigger from git prereceive hook" local cmd="git-hook" - local APP="$2" + local APP="$2" local DOKKU_DEPLOY_BRANCH is_valid_app_name "$APP" DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")" - if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" > /dev/null 2>&1; then + if ! git check-ref-format --branch "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then echo $'\e[1G\e[K'"-----> WARNING: Invalid branch name '$DOKKU_DEPLOY_BRANCH' specified via DOKKU_DEPLOY_BRANCH." echo $'\e[1G\e[K'"-----> For more details, please see the man page for 'git-check-ref-format.'" return @@ -134,7 +138,7 @@ git_hook_cmd() { while read -r oldrev newrev refname; do # Only run this script for the master branch. You can remove this # if block if you wish to run it for others as well. - if [[ $refname = "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then + if [[ $refname == "refs/heads/${DOKKU_DEPLOY_BRANCH}" ]]; then # broken out into plugin so we might support other methods to receive an app # shellcheck disable=SC2086 git_receive_app "$APP" "$newrev" @@ -144,7 +148,7 @@ git_hook_cmd() { plugn trigger receive-branch $APP $newrev $refname else echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master." - echo $'\e[1G\e[K'"-----> for example, try 'git push ${refname/refs\/heads\/}:master'" + echo $'\e[1G\e[K'"-----> for example, try 'git push ${refname/refs\/heads\//}:master'" fi fi done @@ -156,17 +160,17 @@ git_build() { local DOKKU_DEPLOY_BRANCH ENV_VAR_NAME REF if [[ $# -ge 2 ]]; then ENV_VAR_NAME="$(fn-plugin-property-get "git" "$APP" "rev-env-var")" - if [[ -z "$ENV_VAR_NAME" ]] && ! fn-plugin-property-exists "git" "$APP" "rev-env-var"; then + if [[ -z "$ENV_VAR_NAME" ]] && ! fn-plugin-property-exists "git" "$APP" "rev-env-var"; then ENV_VAR_NAME="GIT_REV" fi if [[ -n "$ENV_VAR_NAME" ]]; then - config_set --no-restart "$APP" "${ENV_VAR_NAME}=${REV}" > /dev/null + config_set --no-restart "$APP" "${ENV_VAR_NAME}=${REV}" >/dev/null fi local REF="$REV" else DOKKU_DEPLOY_BRANCH="$(git_deploy_branch "$APP")" - REF=$(< "$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH") + REF=$(<"$DOKKU_ROOT/$APP/refs/heads/$DOKKU_DEPLOY_BRANCH") fi # shellcheck disable=SC2086 @@ -194,7 +198,7 @@ git_upload_pack_cmd() { declare APP="$2" APP="$(echo "$APP" | perl -pe 's/(? /dev/null 2>&1 && apps_maybe_create "$APP" + ! apps_exists "$APP" >/dev/null 2>&1 && apps_maybe_create "$APP" plugn trigger git-pre-pull "$APP" cat | git-upload-pack "$DOKKU_ROOT/$APP" @@ -209,7 +213,7 @@ git_glob_cmd() { is_valid_app_name "$APP" if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then - ! apps_exists "$APP" > /dev/null 2>&1 && apps_maybe_create "$APP" + ! apps_exists "$APP" >/dev/null 2>&1 && apps_maybe_create "$APP" fn-git-create-hook "$APP" fi @@ -229,10 +233,10 @@ fn-git-create-hook() { verify_app_name "$APP" if [[ ! -d "$APP_PATH/refs" ]]; then - git init --bare "$APP_PATH" > /dev/null + git init --bare "$APP_PATH" >/dev/null fi - cat > "$PRERECEIVE_HOOK" <"$PRERECEIVE_HOOK" <, Initialize a git repository for an app git:report [] [], Displays a git report for one or more apps git:set (), Set or clear a git property for an app @@ -74,7 +76,7 @@ help_content } cmd-git-help() { - if [[ $1 = "git:help" ]] ; then + if [[ $1 == "git:help" ]]; then echo -e 'Usage: dokku git[:COMMAND]' echo '' echo 'Manages the git integration for an app.' @@ -85,7 +87,7 @@ cmd-git-help() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then git_help_content_func else - cat< [-h] [-t] [-n num] [-q] [-p process], Display recent log output logs:failed , Show the last logs for an application help_content } cmd-logs-help() { - if [[ $1 = "logs:help" ]] ; then + if [[ $1 == "logs:help" ]]; then echo -e 'Usage: dokku logs[:COMMAND]' echo '' echo 'Output app logs' @@ -31,7 +32,7 @@ cmd-logs-help() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then fn-logs-help-content else - cat<&2 ; exit 1 ; fi + if [[ "$EXIT_CODE" != 0 ]]; then + fn-logs-usage >&2 + exit 1 + fi eval set -- "$TEMP" local DOKKU_LOGS_LINE_NUMBERS="100" while true; do - case "$1" in - -t|--tail) local DOKKU_LOGS_ARGS+="--follow "; shift ;; - -n|--num) local DOKKU_LOGS_LINE_NUMBERS="$2"; shift 2 ;; - -p|--ps) local DOKKU_LOGS_ONLY_PROCESS="$2"; shift 2 ;; - -q|--quiet) local DOKKU_LOGS_NO_PRETTY_PRINT="true"; shift ;; - --) shift; break ;; - *) dokku_log_fail "Internal error";; - esac + case "$1" in + -t | --tail) + local DOKKU_LOGS_ARGS+="--follow " + shift + ;; + -n | --num) + local DOKKU_LOGS_LINE_NUMBERS="$2" + shift 2 + ;; + -p | --ps) + local DOKKU_LOGS_ONLY_PROCESS="$2" + shift 2 + ;; + -q | --quiet) + local DOKKU_LOGS_NO_PRETTY_PRINT="true" + shift + ;; + --) + shift + break + ;; + *) dokku_log_fail "Internal error" ;; + esac done if [[ -n $DOKKU_LOGS_ONLY_PROCESS ]]; then @@ -39,10 +59,10 @@ logs_default_cmd() { [[ -z $(stat -t "${CONTAINERS[0]}" 2>/dev/null) ]] && exit 0 local DOKKU_LOGS_ARGS+="--tail $DOKKU_LOGS_LINE_NUMBERS" - ((MAX_INDEX=${#CONTAINERS[*]} - 1)) || true + ((MAX_INDEX = ${#CONTAINERS[*]} - 1)) || true for i in ${!CONTAINERS[*]}; do local DYNO=$(echo "${CONTAINERS[i]}" | sed -r 's/.*CONTAINER\.(.*)/\1/') - local CID=$(< "${CONTAINERS[i]}") + local CID=$(<"${CONTAINERS[i]}") local COLOR=${COLORS[i % ${#COLORS[*]}]} if [[ $DOKKU_LOGS_NO_PRETTY_PRINT == "true" ]]; then local DOKKU_LOGS_CMD+="(docker logs $DOKKU_LOGS_ARGS $CID 2>&1)" diff --git a/plugins/logs/subcommands/failed b/plugins/logs/subcommands/failed index 3c9efdecc..e668c1b8a 100755 --- a/plugins/logs/subcommands/failed +++ b/plugins/logs/subcommands/failed @@ -2,11 +2,13 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/apps/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-logs-failed() { declare desc="shows the last failed deploy logs" - declare cmd="logs:failed" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare cmd="logs:failed" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 declare APP="$1" local DOKKU_SCHEDULER diff --git a/plugins/network/vendor/github.com/codegangsta/inject/update_readme.sh b/plugins/network/vendor/github.com/codegangsta/inject/update_readme.sh index 497f9a577..3cb21111c 100644 --- a/plugins/network/vendor/github.com/codegangsta/inject/update_readme.sh +++ b/plugins/network/vendor/github.com/codegangsta/inject/update_readme.sh @@ -1,3 +1,3 @@ #!/bin/bash go get github.com/robertkrimen/godocdown/godocdown -godocdown > README.md +godocdown >README.md diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 3dbfc98d8..1402f3075 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help nginx:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | nginx:help) diff --git a/plugins/nginx-vhosts/core-post-deploy b/plugins/nginx-vhosts/core-post-deploy index 493fd2da2..9dd2c3a49 100755 --- a/plugins/nginx-vhosts/core-post-deploy +++ b/plugins/nginx-vhosts/core-post-deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/domains/functions" source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" diff --git a/plugins/nginx-vhosts/dependencies b/plugins/nginx-vhosts/dependencies index 8068dd4ee..aabb4519a 100755 --- a/plugins/nginx-vhosts/dependencies +++ b/plugins/nginx-vhosts/dependencies @@ -1,12 +1,13 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x nginx_needs_upgrade() { declare desc="checks as to whether nginx needs to be installed or upgraded" local MAJOR_VERSION MINOR_VERSION local NEEDS_UPGRADE=true - if ! which nginx > /dev/null 2>&1; then + if ! which nginx >/dev/null 2>&1; then echo $NEEDS_UPGRADE return fi @@ -46,7 +47,7 @@ nginx_dependencies() { [[ "$ubuntu_year" -eq "15" ]] && [[ "$ubuntu_month" -eq "10" ]] && exit 0 add-apt-repository -y ppa:nginx/stable - apt-get update -qq > /dev/null + apt-get update -qq >/dev/null apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes -qq -y nginx dnsutils ;; diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index 388a50da8..f7edb5189 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/certs/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -30,7 +31,7 @@ validate_nginx() { local NGINX_LOCATION EXIT_CODE NGINX_LOCATION=$(get_nginx_location) if [[ -z "$NGINX_LOCATION" ]]; then - exit 1; + exit 1 fi if [[ "$APP" == "--clean" ]]; then @@ -39,7 +40,7 @@ validate_nginx() { fi set +e - sudo "$NGINX_LOCATION" -t > /dev/null 2>&1 + sudo "$NGINX_LOCATION" -t >/dev/null 2>&1 EXIT_CODE=$? set -e if [[ "$EXIT_CODE" -eq "0" ]]; then @@ -55,14 +56,13 @@ validate_nginx() { fi set +e - sudo "$NGINX_LOCATION" -t > /dev/null 2>&1 + sudo "$NGINX_LOCATION" -t >/dev/null 2>&1 EXIT_CODE=$? set -e if [[ "$EXIT_CODE" -eq "0" ]]; then return fi - sudo "$NGINX_LOCATION" -t exit $? } @@ -71,18 +71,18 @@ restart_nginx() { declare desc="restart nginx for given distros" case "$DOKKU_DISTRO" in debian) - sudo /usr/sbin/invoke-rc.d nginx reload > /dev/null + sudo /usr/sbin/invoke-rc.d nginx reload >/dev/null ;; ubuntu) - sudo /etc/init.d/nginx reload > /dev/null + sudo /etc/init.d/nginx reload >/dev/null ;; opensuse) - sudo /sbin/service nginx reload > /dev/null + sudo /sbin/service nginx reload >/dev/null ;; - arch|centos|rhel) + arch | centos | rhel) sudo /usr/bin/systemctl reload nginx ;; esac @@ -90,7 +90,8 @@ restart_nginx() { nginx_logs() { declare desc="display app nginx logs" - local APP="$2"; verify_app_name "$APP" + local APP="$2" + verify_app_name "$APP" local NGINX_LOGS_TYPE=${1#nginx:} local NGINX_LOGS_TYPE=${NGINX_LOGS_TYPE%-logs} local NGINX_LOGS_PATH="/var/log/nginx/$APP-$NGINX_LOGS_TYPE.log" @@ -106,7 +107,8 @@ nginx_logs() { configure_nginx_ports() { declare desc="configure nginx listening ports" - local APP=$1; verify_app_name "$APP" + local APP=$1 + verify_app_name "$APP" local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")" local DOKKU_PROXY_PORT=$(config_get "$APP" DOKKU_PROXY_PORT) local DOKKU_PROXY_SSL_PORT=$(config_get "$APP" DOKKU_PROXY_SSL_PORT) @@ -142,7 +144,7 @@ configure_nginx_ports() { else local PROXY_PORT=${PROXY_PORT:-$DOKKU_PROXY_PORT} local PROXY_SSL_PORT=${PROXY_SSL_PORT:-$DOKKU_PROXY_SSL_PORT} - [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]] && local UPSTREAM_PORT="$(< "$DOKKU_ROOT/$APP/PORT.web.1")" + [[ -f "$DOKKU_ROOT/$APP/PORT.web.1" ]] && local UPSTREAM_PORT="$(<"$DOKKU_ROOT/$APP/PORT.web.1")" if [[ -n "$PROXY_PORT" ]] && [[ -n "$PROXY_SSL_PORT" ]]; then local PROXY_PORT_MAP+=" http:${PROXY_PORT}:$UPSTREAM_PORT https:${PROXY_SSL_PORT}:$UPSTREAM_PORT " elif [[ -n "$PROXY_PORT" ]]; then @@ -159,16 +161,17 @@ configure_nginx_ports() { validate_ssl_domains() { declare desc="check configured domains against SSL cert contents and show warning if mismatched" - local APP=$1; verify_app_name "$APP" + local APP=$1 + verify_app_name "$APP" local SSL_HOSTNAME=$(get_ssl_hostnames "$APP") local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g') - if ! (egrep -q "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" &> /dev/null); then + if ! (egrep -q "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" &>/dev/null); then dokku_log_info1 "No matching configured domains for $APP found in SSL certificate. Your app will show as insecure in a browser if accessed via SSL" dokku_log_info1 "Please add appropriate domains via the dokku domains command" [[ -n "$NONSSL_VHOSTS" ]] && dokku_log_info1 "Configured domains for app:" local domain - for domain in $(echo "$NONSSL_VHOSTS"| xargs); do + for domain in $(echo "$NONSSL_VHOSTS" | xargs); do dokku_log_info2 "$domain" done [[ -n "$SSL_HOSTNAME" ]] && dokku_log_info1 "Domains found in SSL certificate:" @@ -180,7 +183,8 @@ validate_ssl_domains() { get_custom_nginx_template() { declare desc="attempts to copy custom nginx template from app image" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local DESTINATION="$2" local IMAGE_TAG="$(get_running_image_tag "$APP")" local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") @@ -257,13 +261,18 @@ is_http2_enabled() { nginx_build_config() { declare desc="build nginx config to proxy app containers using sigil" - local APP="$1"; verify_app_name "$APP" - local DOKKU_APP_LISTEN_PORT="$2"; local DOKKU_APP_LISTEN_IP="$3" - local VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"; local URLS_PATH="$DOKKU_ROOT/$APP/URLS" + local APP="$1" + verify_app_name "$APP" + local DOKKU_APP_LISTEN_PORT="$2" + local DOKKU_APP_LISTEN_IP="$3" + local VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + local URLS_PATH="$DOKKU_ROOT/$APP/URLS" local NGINX_TEMPLATE_NAME="nginx.conf.sigil" local DEFAULT_NGINX_TEMPLATE="$PLUGIN_AVAILABLE_PATH/nginx-vhosts/templates/$NGINX_TEMPLATE_NAME" - local NGINX_TEMPLATE="$DEFAULT_NGINX_TEMPLATE"; local SCHEME=http - local NGINX_TEMPLATE_SOURCE="built-in"; local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" + local NGINX_TEMPLATE="$DEFAULT_NGINX_TEMPLATE" + local SCHEME=http + local NGINX_TEMPLATE_SOURCE="built-in" + local APP_SSL_PATH="$DOKKU_ROOT/$APP/tls" local RAW_TCP_PORTS="$(get_app_raw_tcp_ports "$APP")" local DOKKU_APP_LISTENERS @@ -284,7 +293,7 @@ nginx_build_config() { local PORT_MAP for PORT_MAP in $PROXY_PORT_MAP; do - local PROXY_UPSTREAM_PORT="$(awk -F ':' '{ print $3 }' <<< "$PORT_MAP")" + local PROXY_UPSTREAM_PORT="$(awk -F ':' '{ print $3 }' <<<"$PORT_MAP")" if [[ "$(is_val_in_list "$PROXY_UPSTREAM_PORT" "$PROXY_UPSTREAM_PORTS" " ")" == "false" ]]; then local PROXY_UPSTREAM_PORTS+="$PROXY_UPSTREAM_PORT " fi @@ -297,7 +306,7 @@ nginx_build_config() { # shellcheck disable=SC2086 trap 'rm -rf $NGINX_CONF $NGINX_BUILD_CONFIG_TMP_WORK_DIR > /dev/null' RETURN INT TERM EXIT - get_custom_nginx_template "$APP" "$CUSTOM_NGINX_TEMPLATE" 2> /dev/null + get_custom_nginx_template "$APP" "$CUSTOM_NGINX_TEMPLATE" 2>/dev/null if [[ -f "$CUSTOM_NGINX_TEMPLATE" ]]; then dokku_log_info1 'Overriding default nginx.conf with detected nginx.conf.sigil' local NGINX_TEMPLATE="$CUSTOM_NGINX_TEMPLATE" @@ -307,7 +316,8 @@ nginx_build_config() { local NONSSL_VHOSTS=$(get_app_domains "$APP") local NOSSL_SERVER_NAME=$(echo "$NONSSL_VHOSTS" | xargs) if is_ssl_enabled "$APP"; then - local SSL_INUSE=true; local SCHEME=https + local SSL_INUSE=true + local SCHEME=https validate_ssl_domains "$APP" local SSL_HOSTNAME=$(get_ssl_hostnames "$APP") local SSL_HOSTNAME_REGEX=$(echo "$SSL_HOSTNAME" | xargs | sed 's|\.|\\.|g' | sed 's/\*/\[^\.\]\*/g' | sed 's/ /|/g') @@ -315,7 +325,7 @@ nginx_build_config() { if [[ "$IS_APP_VHOST_ENABLED" == "true" ]]; then local SSL_VHOSTS=$(egrep "^${SSL_HOSTNAME_REGEX}$" "$VHOST_PATH" || true) else - local SSL_VHOSTS=$(< "$DOKKU_ROOT/HOSTNAME") + local SSL_VHOSTS=$(<"$DOKKU_ROOT/HOSTNAME") fi local SSL_SERVER_NAME local host @@ -330,7 +340,7 @@ nginx_build_config() { local NGINX_LOCATION NGINX_VERSION SPDY_SUPPORTED HTTP2_SUPPORTED HTTP2_PUSH_SUPPORTED NGINX_LOCATION=$(get_nginx_location) if [[ -z "$NGINX_LOCATION" ]]; then - exit 1; + exit 1 fi NGINX_VERSION="$("$NGINX_LOCATION" -v 2>&1 | cut -d'/' -f 2)" SPDY_SUPPORTED="$(is_spdy_enabled "$NGINX_VERSION")" @@ -341,26 +351,26 @@ nginx_build_config() { eval "$(config_export app "$APP")" local SIGIL_PARAMS=(-f "$NGINX_TEMPLATE" APP="$APP" DOKKU_ROOT="$DOKKU_ROOT" - NOSSL_SERVER_NAME="$NOSSL_SERVER_NAME" - DOKKU_APP_LISTENERS="$DOKKU_APP_LISTENERS" - DOKKU_LIB_ROOT="$DOKKU_LIB_ROOT" - PASSED_LISTEN_IP_PORT="$PASSED_LISTEN_IP_PORT" - SPDY_SUPPORTED="$SPDY_SUPPORTED" - HTTP2_SUPPORTED="$HTTP2_SUPPORTED" - HTTP2_PUSH_SUPPORTED="$HTTP2_PUSH_SUPPORTED" - DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP" - APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME" - # @TODO: Remove this after a few versions - NGINX_PORT="$PROXY_PORT" NGINX_SSL_PORT="$PROXY_SSL_PORT" - PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" - PROXY_PORT_MAP="$PROXY_PORT_MAP" PROXY_UPSTREAM_PORTS="$PROXY_UPSTREAM_PORTS") + NOSSL_SERVER_NAME="$NOSSL_SERVER_NAME" + DOKKU_APP_LISTENERS="$DOKKU_APP_LISTENERS" + DOKKU_LIB_ROOT="$DOKKU_LIB_ROOT" + PASSED_LISTEN_IP_PORT="$PASSED_LISTEN_IP_PORT" + SPDY_SUPPORTED="$SPDY_SUPPORTED" + HTTP2_SUPPORTED="$HTTP2_SUPPORTED" + HTTP2_PUSH_SUPPORTED="$HTTP2_PUSH_SUPPORTED" + DOKKU_APP_LISTEN_PORT="$DOKKU_APP_LISTEN_PORT" DOKKU_APP_LISTEN_IP="$DOKKU_APP_LISTEN_IP" + APP_SSL_PATH="$APP_SSL_PATH" SSL_INUSE="$SSL_INUSE" SSL_SERVER_NAME="$SSL_SERVER_NAME" + # @TODO: Remove this after a few versions + NGINX_PORT="$PROXY_PORT" NGINX_SSL_PORT="$PROXY_SSL_PORT" + PROXY_PORT="$PROXY_PORT" PROXY_SSL_PORT="$PROXY_SSL_PORT" RAW_TCP_PORTS="$RAW_TCP_PORTS" + PROXY_PORT_MAP="$PROXY_PORT_MAP" PROXY_UPSTREAM_PORTS="$PROXY_UPSTREAM_PORTS") if [[ -z "$DOKKU_APP_LISTENERS" ]]; then dokku_log_warn_quiet "No web listeners specified for $APP" elif (is_deployed "$APP"); then # execute sigil template processing - xargs -i echo "-----> Configuring {}...(using $NGINX_TEMPLATE_SOURCE template)" <<< "$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)" - sigil "${SIGIL_PARAMS[@]}" | cat -s > "$NGINX_CONF" + xargs -i echo "-----> Configuring {}...(using $NGINX_TEMPLATE_SOURCE template)" <<<"$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)" + sigil "${SIGIL_PARAMS[@]}" | cat -s >"$NGINX_CONF" dokku_log_info1 "Creating $SCHEME nginx.conf" mv "$NGINX_CONF" "$DOKKU_ROOT/$APP/nginx.conf" @@ -373,8 +383,8 @@ nginx_build_config() { fi if ([[ -n "$NONSSL_VHOSTS" ]] || [[ -n "$SSL_VHOSTS" ]]) && [[ "$IS_APP_VHOST_ENABLED" == "true" ]]; then - echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" > "$URLS_PATH" - xargs -i echo "$SCHEME://{}" <<< "$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)" >> "$URLS_PATH" + echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" >"$URLS_PATH" + xargs -i echo "$SCHEME://{}" <<<"$(echo "${SSL_VHOSTS}" "${NONSSL_VHOSTS}" | tr ' ' '\n' | sort -u)" >>"$URLS_PATH" fi else # note because this clause is long. if the proxy is disabled: diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 9a601776a..dd81aad17 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -1,28 +1,29 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" case "$DOKKU_DISTRO" in debian) - echo "%dokku ALL=(ALL) NOPASSWD:/usr/sbin/invoke-rc.d nginx reload, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" > /etc/sudoers.d/dokku-nginx + echo "%dokku ALL=(ALL) NOPASSWD:/usr/sbin/invoke-rc.d nginx reload, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" >/etc/sudoers.d/dokku-nginx ;; ubuntu) - echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" > /etc/sudoers.d/dokku-nginx + echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" >/etc/sudoers.d/dokku-nginx ;; opensuse) - echo "%dokku ALL=(ALL) NOPASSWD:/sbin/service nginx reload, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" > /etc/sudoers.d/dokku-nginx + echo "%dokku ALL=(ALL) NOPASSWD:/sbin/service nginx reload, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" >/etc/sudoers.d/dokku-nginx ;; arch) - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload nginx, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" > /etc/sudoers.d/dokku-nginx + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload nginx, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" >/etc/sudoers.d/dokku-nginx ;; - centos|rhel) - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload nginx, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" > /etc/sudoers.d/dokku-nginx - echo "Defaults:dokku !requiretty" >> /etc/sudoers.d/dokku-nginx + centos | rhel) + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload nginx, /usr/sbin/nginx -t, /usr/sbin/nginx -t -c *" >/etc/sudoers.d/dokku-nginx + echo "Defaults:dokku !requiretty" >>/etc/sudoers.d/dokku-nginx ;; esac @@ -36,7 +37,7 @@ fi mkdir -p /etc/nginx/conf.d chown root:root /etc/nginx/dhparam.pem chown root:root /etc/nginx/conf.d -cat< /etc/nginx/conf.d/dokku.conf +cat </etc/nginx/conf.d/dokku.conf include $DOKKU_ROOT/*/nginx.conf; server_tokens off; @@ -53,7 +54,7 @@ EOF # allow users to override their server_names_hash_bucket_size if [[ ! -f /etc/nginx/conf.d/server_names_hash_bucket_size.conf ]]; then - echo 'server_names_hash_bucket_size 512;' >| /etc/nginx/conf.d/server_names_hash_bucket_size.conf + echo 'server_names_hash_bucket_size 512;' >|/etc/nginx/conf.d/server_names_hash_bucket_size.conf fi # revert dokku group changes @@ -68,7 +69,6 @@ cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/400-error.html" "${DOKK cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/404-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/404-error.html" cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/500-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/500-error.html" - # patch broken nginx 1.8.0 logrotate [[ -f /etc/logrotate.d/nginx ]] && sed -i -e 's/invoke-rc.d/service/g' /etc/logrotate.d/nginx @@ -108,7 +108,7 @@ case "$DOKKU_DISTRO" in "$NGINX_INIT" nginx start || "$NGINX_INIT" nginx reload ;; - arch|centos|rhel) + arch | centos | rhel) NGINX_INIT="/usr/bin/systemctl" "$NGINX_INIT" start nginx || "$NGINX_INIT" reload nginx ;; diff --git a/plugins/nginx-vhosts/internal-functions b/plugins/nginx-vhosts/internal-functions index cc27fbf3f..626d5b8b0 100755 --- a/plugins/nginx-vhosts/internal-functions +++ b/plugins/nginx-vhosts/internal-functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x nginx_vhosts_validate_single_func() { declare APP="$1" FLAG="$2" @@ -29,8 +30,8 @@ nginx_vhosts_is_valid_nginx_config_func() { local TMP_OUTPUT=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX") trap 'rm -rf "$TMP_OUTPUT" > /dev/null' RETURN INT TERM EXIT - sigil -f "$VALIDATE_TEMPLATE" NGINX_CONF="$DOKKU_ROOT/$APP/nginx.conf" | cat -s > "$TMP_OUTPUT" - sudo "$NGINX_LOCATION" -t -c "$TMP_OUTPUT" 2> /dev/null + sigil -f "$VALIDATE_TEMPLATE" NGINX_CONF="$DOKKU_ROOT/$APP/nginx.conf" | cat -s >"$TMP_OUTPUT" + sudo "$NGINX_LOCATION" -t -c "$TMP_OUTPUT" 2>/dev/null } nginx_vhosts_conf_clean_func() { @@ -41,8 +42,8 @@ nginx_vhosts_conf_clean_func() { } nginx_vhosts_help_content_func() { - declare desc="return nginx plugin help content" - cat<, (Re)builds nginx config for given app nginx:access-logs [-t], Show the nginx access logs for an application (-t follows) nginx:error-logs [-t], Show the nginx error logs for an application (-t follows) @@ -51,7 +52,7 @@ help_content } nginx_vhosts_help_cmd() { - if [[ $1 = "nginx:help" ]] ; then + if [[ $1 == "nginx:help" ]]; then echo -e 'Usage: dokku nginx[:COMMAND]' echo '' echo 'Interact with Dokku'"'"'s Nginx proxy.' @@ -61,7 +62,7 @@ nginx_vhosts_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then nginx_vhosts_help_content_func else - cat< "/var/cache/dokku-completion" + dokku --quiet help --all | awk '/^ /{ print $1 }' | sort >"/var/cache/dokku-completion" } diff --git a/plugins/plugin/subcommands/default b/plugins/plugin/subcommands/default index 8fdd2eaa3..1f336719e 100755 --- a/plugins/plugin/subcommands/default +++ b/plugins/plugin/subcommands/default @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" diff --git a/plugins/plugin/subcommands/disable b/plugins/plugin/subcommands/disable index 96ecda2ef..869d22601 100755 --- a/plugins/plugin/subcommands/disable +++ b/plugins/plugin/subcommands/disable @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" diff --git a/plugins/plugin/subcommands/enable b/plugins/plugin/subcommands/enable index 5bc0e0fc6..fce33c21c 100755 --- a/plugins/plugin/subcommands/enable +++ b/plugins/plugin/subcommands/enable @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" diff --git a/plugins/plugin/subcommands/install b/plugins/plugin/subcommands/install index 7dab191a1..c9cf82926 100755 --- a/plugins/plugin/subcommands/install +++ b/plugins/plugin/subcommands/install @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" @@ -12,7 +13,7 @@ plugin_install_cmd() { [[ "$#" -gt 2 ]] && dokku_log_info1_quiet "Cannot install additional core plugins, running core plugin install trigger" PLUGIN_PATH="$PLUGIN_CORE_PATH" plugn trigger install ;; - https:*|git*|ssh:*|*.tar.gz|*.tgz) + https:* | git* | ssh:* | *.tar.gz | *.tgz) shift download_and_enable_plugin "$@" plugn trigger install diff --git a/plugins/plugin/subcommands/install-dependencies b/plugins/plugin/subcommands/install-dependencies index 13a2ca079..9e9949b86 100755 --- a/plugins/plugin/subcommands/install-dependencies +++ b/plugins/plugin/subcommands/install-dependencies @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x plugin_install_dependencies_cmd() { declare desc="calls dependencies plugin trigger via command line" diff --git a/plugins/plugin/subcommands/list b/plugins/plugin/subcommands/list index bb5e4744d..fcdc1fd0f 100755 --- a/plugins/plugin/subcommands/list +++ b/plugins/plugin/subcommands/list @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" plugin_list_cmd "$@" diff --git a/plugins/plugin/subcommands/uninstall b/plugins/plugin/subcommands/uninstall index 80e7bf992..66b246d5a 100755 --- a/plugins/plugin/subcommands/uninstall +++ b/plugins/plugin/subcommands/uninstall @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" diff --git a/plugins/plugin/subcommands/update b/plugins/plugin/subcommands/update index 3c4fbbef9..529a1b015 100755 --- a/plugins/plugin/subcommands/update +++ b/plugins/plugin/subcommands/update @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" plugin_update_cmd() { diff --git a/plugins/proxy/commands b/plugins/proxy/commands index 3802db5ef..ebc2510b5 100755 --- a/plugins/proxy/commands +++ b/plugins/proxy/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help proxy:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/proxy/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | proxy:help) diff --git a/plugins/proxy/functions b/plugins/proxy/functions index 4ef7a5573..10fd1588a 100755 --- a/plugins/proxy/functions +++ b/plugins/proxy/functions @@ -1,11 +1,13 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" is_app_proxy_enabled() { declare desc="return true if proxy is enabled; otherwise return false" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local APP_PROXY_ENABLED=true local DOKKU_DISABLE_PROXY=$(config_get "$APP" DOKKU_DISABLE_PROXY) @@ -17,7 +19,8 @@ is_app_proxy_enabled() { get_app_proxy_type() { declare desc="return app proxy type" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local DOKKU_APP_PROXY_TYPE="$(config_get "$APP" DOKKU_APP_PROXY_TYPE || true)" local APP_PROXY_TYPE="${DOKKU_APP_PROXY_TYPE:-nginx}" @@ -26,13 +29,15 @@ get_app_proxy_type() { get_app_proxy_port_map() { declare desc="return a list of configured port mappings" - local APP="$1"; local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)" + local APP="$1" + local PROXY_PORT_MAP="$(config_get "$APP" DOKKU_PROXY_PORT_MAP || true)" echo "$PROXY_PORT_MAP" } list_app_proxy_ports() { declare desc="list proxy port mappings for an app" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local PROXY_PORT_MAP="$(get_app_proxy_port_map "$APP")" if [[ -n "$PROXY_PORT_MAP" ]]; then @@ -40,7 +45,7 @@ list_app_proxy_ports() { dokku_col_log_info1_quiet "scheme" "host port" "container port" local port_map for port_map in $PROXY_PORT_MAP; do - dokku_col_log_msg "$(cut -d ':' -f1 <<< "$port_map")" "$(cut -d ':' -f2 <<< "$port_map")" "$(cut -d ':' -f3 <<< "$port_map")" + dokku_col_log_msg "$(cut -d ':' -f1 <<<"$port_map")" "$(cut -d ':' -f2 <<<"$port_map")" "$(cut -d ':' -f3 <<<"$port_map")" done else dokku_log_fail "No port mappings configured for app ($APP)" @@ -49,15 +54,16 @@ list_app_proxy_ports() { filter_app_proxy_ports() { declare desc="list proxy port mappings for an app that start with a particular scheme and a host port" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local SCHEME="$2" HOST_PORT="$3" local PROXY_PORT_MAP="$(get_app_proxy_port_map "$APP")" if [[ -n "$PROXY_PORT_MAP" ]]; then local port_map for port_map in $PROXY_PORT_MAP; do - local scheme="$(cut -d ':' -f1 <<< "$port_map")" - local host_port="$(cut -d ':' -f2 <<< "$port_map")" + local scheme="$(cut -d ':' -f1 <<<"$port_map")" + local host_port="$(cut -d ':' -f2 <<<"$port_map")" if [[ "$scheme" == "$SCHEME" ]] && [[ "$host_port" == "$HOST_PORT" ]]; then echo "$port_map" fi @@ -93,9 +99,9 @@ remove_proxy_ports() { PROXY_PORT_MAP=" $PROXY_PORT_MAP " for port in $INPUT_PORTS; do if [[ "$port" =~ $RE_PORT ]]; then - PROXY_PORT_MAP="$(sed -r "s/[[:alnum:]]+:$port:[[:alnum:]]+//g" <<< "$PROXY_PORT_MAP")" + PROXY_PORT_MAP="$(sed -r "s/[[:alnum:]]+:$port:[[:alnum:]]+//g" <<<"$PROXY_PORT_MAP")" else - PROXY_PORT_MAP="$(sed -r "s/ $port / /g" <<< "$PROXY_PORT_MAP")" + PROXY_PORT_MAP="$(sed -r "s/ $port / /g" <<<"$PROXY_PORT_MAP")" fi done PROXY_PORT_MAP="$(echo "$PROXY_PORT_MAP" | xargs)" diff --git a/plugins/proxy/internal-functions b/plugins/proxy/internal-functions index be048fc47..073c9aece 100755 --- a/plugins/proxy/internal-functions +++ b/plugins/proxy/internal-functions @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/proxy/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-proxy-report() { declare desc="displays a proxy report for one or more apps" @@ -46,7 +47,8 @@ cmd-proxy-report-single() { dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -75,8 +77,8 @@ fn-proxy-enabled() { } proxy_help_content_func() { - declare desc="return proxy plugin help content" - cat<, [DEPRECATED] Show proxy settings for app proxy:enable , Enable proxy for app proxy:disable , Disable proxy for app @@ -90,7 +92,7 @@ help_content } proxy_help_cmd() { - if [[ $1 = "proxy:help" ]] ; then + if [[ $1 == "proxy:help" ]]; then echo -e 'Usage: dokku proxy[:COMMAND]' echo '' echo 'Manage the proxy used by dokku on a per app.' @@ -100,7 +102,7 @@ proxy_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then proxy_help_content_func else - cat<, List processes running in app container(s) ps:inspect , Displays a sanitized version of docker inspect for an app ps:scale = [=...], Get/Set how many instances of a given process to run @@ -25,15 +26,15 @@ case "$1" in help_content } - if [[ $1 = "ps:help" ]] ; then - echo -e 'Usage: dokku ps[:COMMAND]' - echo '' - echo 'List running processes in container, and restart app.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, + if [[ $1 == "ps:help" ]]; then + echo -e 'Usage: dokku ps[:COMMAND]' + echo '' + echo 'List running processes in container, and restart app.' + echo '' + echo 'Additional commands:' + help_content_func | sort | column -c2 -t -s, else - help_content_func + help_content_func fi ;; diff --git a/plugins/ps/core-post-deploy b/plugins/ps/core-post-deploy index 1fc2e2b6b..0785b90e7 100755 --- a/plugins/ps/core-post-deploy +++ b/plugins/ps/core-post-deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/functions b/plugins/ps/functions index 2682aedb1..c43f6e346 100755 --- a/plugins/ps/functions +++ b/plugins/ps/functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -16,10 +17,11 @@ get_cmd_from_procfile() { print_dokku_scale_file() { declare desc="prints contents of DOKKU_SCALE file" - local APP="$1"; local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" + local APP="$1" + local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" while read -r line || [[ -n "$line" ]]; do dokku_log_info2_quiet "$line" - done < "$DOKKU_SCALE_FILE" + done <"$DOKKU_SCALE_FILE" } extract_procfile() { @@ -46,7 +48,8 @@ extract_procfile() { remove_procfile() { declare desc="removes DOKKU_PROCFILE" - local APP="$1"; local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" + local APP="$1" + local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" if [[ -f "$DOKKU_PROCFILE" ]]; then rm -f "$DOKKU_PROCFILE" fi @@ -54,7 +57,10 @@ remove_procfile() { generate_scale_file() { declare desc="generates DOKKU_SCALE file" - local APP="$1"; local IMAGE_TAG="$2"; local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG"); local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" + local APP="$1" + local IMAGE_TAG="$2" + local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG") + local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" verify_app_name "$APP" @@ -73,10 +79,10 @@ generate_scale_file() { local NAME=${line%%:*} local NUM_PROCS=0 [[ "$NAME" == "web" ]] && NUM_PROCS=1 - [[ -n "$NAME" ]] && echo "$NAME=$NUM_PROCS" >> "$DOKKU_SCALE_FILE" + [[ -n "$NAME" ]] && echo "$NAME=$NUM_PROCS" >>"$DOKKU_SCALE_FILE" done < <(egrep -v "^#" "$DOKKU_PROCFILE" | grep ':' | awk -F ':' '{ print $1 }' | sort | uniq) else - echo "web=1" >> "$DOKKU_SCALE_FILE" + echo "web=1" >>"$DOKKU_SCALE_FILE" fi dokku_log_info1_quiet "New DOKKU_SCALE file generated" else @@ -92,30 +98,31 @@ set_scale() { local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" shift 1 - extract_procfile "$APP" "$IMAGE_TAG" > /dev/null + extract_procfile "$APP" "$IMAGE_TAG" >/dev/null trap 'remove_procfile $APP' RETURN INT TERM EXIT local SCALE_SETTINGS=("$@") for procscale in "${SCALE_SETTINGS[@]}"; do local PROC_NAME=${procscale%%=*} local PROC_COUNT=${procscale#*=} - if [[ -f "$DOKKU_PROCFILE" ]] && ! procfile-util exists --procfile "$DOKKU_PROCFILE" --process-type "$PROC_NAME" > /dev/null 2>&1; then + if [[ -f "$DOKKU_PROCFILE" ]] && ! procfile-util exists --procfile "$DOKKU_PROCFILE" --process-type "$PROC_NAME" >/dev/null 2>&1; then dokku_log_fail "${PROC_NAME} is not a valid process name" fi is_number "$PROC_COUNT" || dokku_log_fail "ps:scale $PROC_COUNT is not a number" dokku_log_info1_quiet "Scaling $APP:$PROC_NAME to $PROC_COUNT" - if (egrep -q "^${PROC_NAME}=" "$DOKKU_SCALE_FILE" > /dev/null 2>&1); then + if (egrep -q "^${PROC_NAME}=" "$DOKKU_SCALE_FILE" >/dev/null 2>&1); then sed --in-place "s:^${PROC_NAME}=.*:$PROC_NAME=$PROC_COUNT:g" "$DOKKU_SCALE_FILE" else - echo "$PROC_NAME=$PROC_COUNT" >> "$DOKKU_SCALE_FILE" + echo "$PROC_NAME=$PROC_COUNT" >>"$DOKKU_SCALE_FILE" fi done } ps_start() { declare desc="starts app" - local APP="$1"; verify_app_name "$APP" - local IMAGE_TAG=$(get_running_image_tag "$APP"); + local APP="$1" + verify_app_name "$APP" + local IMAGE_TAG=$(get_running_image_tag "$APP") local RUNNING if (is_deployed "$APP"); then @@ -139,7 +146,8 @@ ps_start() { ps_stop() { declare desc="stops app" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" ! (is_deployed "$APP") && dokku_log_warn "App $APP has not been deployed" && exit 0 @@ -151,14 +159,16 @@ ps_stop() { ps_rebuild() { declare desc="rebuilds app from base image" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" plugn trigger receive-app "$APP" } ps_restart() { declare desc="restarts app" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local IMAGE_TAG=$(get_running_image_tag "$APP") if (is_deployed "$APP"); then @@ -170,14 +180,15 @@ ps_restart() { ps_scale() { declare desc="sets app scaling config according arguments; otherwise according to DOKKU_SCALE file" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" local IMAGE_TAG=$(get_running_image_tag "$APP") local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" local DOKKU_PROCFILE="$DOKKU_ROOT/$APP/DOKKU_PROCFILE" shift 1 [[ ! -e $DOKKU_SCALE_FILE ]] && generate_scale_file "$APP" "$IMAGE_TAG" - if [[ -z "$@" ]];then + if [[ -z "$@" ]]; then dokku_log_info1_quiet "Scaling for $APP" dokku_col_log_info1_quiet "proctype" "qty" dokku_col_log_info1_quiet "--------" "---" @@ -186,7 +197,7 @@ ps_scale() { local PROC_NAME=${line%%=*} local PROC_COUNT=${line#*=} dokku_col_log_info1 "$PROC_NAME" "$PROC_COUNT" - done < "$DOKKU_SCALE_FILE" + done <"$DOKKU_SCALE_FILE" else set_scale "$APP" "$@" release_and_deploy "$APP" "$IMAGE_TAG" @@ -196,7 +207,7 @@ ps_scale() { get_raw_restart_policies() { declare desc="strips docker options and prints raw restart policies" local -r phase_file_path=$1 - [[ -r "$phase_file_path" ]] && sed -e '/^--restart=/!d' < "$phase_file_path" + [[ -r "$phase_file_path" ]] && sed -e '/^--restart=/!d' <"$phase_file_path" } get_restart_policies() { @@ -208,7 +219,7 @@ get_restart_policies() { fn-ps-app-status() { declare APP="$1" local PROCS=0 RUNNING="" - local APP_CIDS=$(get_app_container_ids "$APP"); + local APP_CIDS=$(get_app_container_ids "$APP") for CID in $APP_CIDS; do if (is_container_status "$CID" "Running"); then diff --git a/plugins/ps/install b/plugins/ps/install index b70187689..dd9125f78 100755 --- a/plugins/ps/install +++ b/plugins/ps/install @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/internal-functions b/plugins/ps/internal-functions index d4b6dc353..cb145acb3 100755 --- a/plugins/ps/internal-functions +++ b/plugins/ps/internal-functions @@ -2,7 +2,8 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-ps-inspect() { declare desc="displays a sanitized version of docker inspect for an app" @@ -58,8 +59,8 @@ cmd-ps-report-single() { if [[ "$DOKKU_APP_RESTORE" != 0 ]]; then RESTORE="true"; else RESTORE="false"; fi local APP_CONTAINER_STATUS for CONTAINER_FILE in $CONTAINER_FILES; do - CID=$(< "$DOKKU_ROOT/$APP/$CONTAINER_FILE") - APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' "$CID" 2> /dev/null || true) + CID=$(<"$DOKKU_ROOT/$APP/$CONTAINER_FILE") + APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' "$CID" 2>/dev/null || true) [[ -z "$APP_CONTAINER_STATUS" ]] && APP_CONTAINER_STATUS="missing" STATUSES+=("${CONTAINER_FILE#*.}:$APP_CONTAINER_STATUS#${CID:0:12}") done @@ -85,7 +86,8 @@ cmd-ps-report-single() { dokku_log_verbose "$(printf "%-30s %-10s (CID: %s)" "Status $name:" "$status" "$cid")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for STATUS in "${STATUSES[@]}"; do name=${STATUS%:*} value=${STATUS#*:} diff --git a/plugins/ps/post-create b/plugins/ps/post-create index 78e08b1c5..bcdbaa2ad 100755 --- a/plugins/ps/post-create +++ b/plugins/ps/post-create @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/post-stop b/plugins/ps/post-stop index 404c06f06..b9b8a4567 100755 --- a/plugins/ps/post-stop +++ b/plugins/ps/post-stop @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -12,4 +13,4 @@ ps_post_stop() { config_set --no-restart "$APP" DOKKU_APP_RESTORE=0 } -ps_post_stop "$@" \ No newline at end of file +ps_post_stop "$@" diff --git a/plugins/ps/pre-deploy b/plugins/ps/pre-deploy index ef8c1251f..67cab2171 100755 --- a/plugins/ps/pre-deploy +++ b/plugins/ps/pre-deploy @@ -1,12 +1,14 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" ps_pre_deploy() { declare desc="ps pre-deploy plugin trigger" local trigger="ps_pre_deploy" - local APP="$1"; local IMAGE_TAG="$2" + local APP="$1" + local IMAGE_TAG="$2" extract_procfile "$APP" "$IMAGE_TAG" generate_scale_file "$APP" "$IMAGE_TAG" diff --git a/plugins/ps/report b/plugins/ps/report index d7bbce270..273d4431c 100755 --- a/plugins/ps/report +++ b/plugins/ps/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-ps-report-single "$@" diff --git a/plugins/ps/subcommands/default b/plugins/ps/subcommands/default index cc2ecfbe2..ed5ca1182 100755 --- a/plugins/ps/subcommands/default +++ b/plugins/ps/subcommands/default @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" ps_main_cmd() { @@ -9,7 +10,8 @@ ps_main_cmd() { [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" - local APP="$2"; verify_app_name "$APP" + local APP="$2" + verify_app_name "$APP" ! (is_deployed "$APP") && dokku_log_warn "App $APP has not been deployed" && exit 0 local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids "$APP") diff --git a/plugins/ps/subcommands/inspect b/plugins/ps/subcommands/inspect index 96974342e..acea3e2b9 100755 --- a/plugins/ps/subcommands/inspect +++ b/plugins/ps/subcommands/inspect @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-ps-inspect "$@" diff --git a/plugins/ps/subcommands/rebuild b/plugins/ps/subcommands/rebuild index 242c65bf0..47bb97f99 100755 --- a/plugins/ps/subcommands/rebuild +++ b/plugins/ps/subcommands/rebuild @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/subcommands/rebuildall b/plugins/ps/subcommands/rebuildall index 61409e793..3f10e32a8 100755 --- a/plugins/ps/subcommands/rebuildall +++ b/plugins/ps/subcommands/rebuildall @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -9,7 +10,7 @@ ps_rebuildall_cmd() { local cmd="ps:rebuildall" local GNU_PARALLEL - if which parallel > /dev/null 2>&1; then + if which parallel >/dev/null 2>&1; then dokku_log_info1 "Rebuilding in parallel" GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) if [[ -z "$GNU_PARALLEL" ]]; then diff --git a/plugins/ps/subcommands/report b/plugins/ps/subcommands/report index 88d64b5c1..0a967fd0d 100755 --- a/plugins/ps/subcommands/report +++ b/plugins/ps/subcommands/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/ps/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-ps-report "$@" diff --git a/plugins/ps/subcommands/restart b/plugins/ps/subcommands/restart index cf41a64b4..85068e59c 100755 --- a/plugins/ps/subcommands/restart +++ b/plugins/ps/subcommands/restart @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/subcommands/restart-policy b/plugins/ps/subcommands/restart-policy index c73ed72ab..c1195f190 100755 --- a/plugins/ps/subcommands/restart-policy +++ b/plugins/ps/subcommands/restart-policy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/subcommands/restartall b/plugins/ps/subcommands/restartall index 7f6e8aee2..19a4be7b6 100755 --- a/plugins/ps/subcommands/restartall +++ b/plugins/ps/subcommands/restartall @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -9,7 +10,7 @@ ps_restartall_cmd() { local cmd="ps:restartall" local GNU_PARALLEL - if which parallel > /dev/null 2>&1; then + if which parallel >/dev/null 2>&1; then dokku_log_info1 "Restarting in parallel" GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) if [[ -z "$GNU_PARALLEL" ]]; then diff --git a/plugins/ps/subcommands/restore b/plugins/ps/subcommands/restore index bbfa86f82..94f84206a 100755 --- a/plugins/ps/subcommands/restore +++ b/plugins/ps/subcommands/restore @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -27,11 +28,11 @@ ps_restore_cmd() { ps_restore_all fi } - + ps_restore_all() { local GNU_PARALLEL - if which parallel > /dev/null 2>&1; then + if which parallel >/dev/null 2>&1; then dokku_log_info1 "Restarting in parallel" GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) if [[ -z "$GNU_PARALLEL" ]]; then diff --git a/plugins/ps/subcommands/retire b/plugins/ps/subcommands/retire index 221f0d551..4fb414940 100755 --- a/plugins/ps/subcommands/retire +++ b/plugins/ps/subcommands/retire @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" diff --git a/plugins/ps/subcommands/scale b/plugins/ps/subcommands/scale index 3e4993200..25b467068 100755 --- a/plugins/ps/subcommands/scale +++ b/plugins/ps/subcommands/scale @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/subcommands/set-restart-policy b/plugins/ps/subcommands/set-restart-policy index ab836edea..bfb3bc044 100755 --- a/plugins/ps/subcommands/set-restart-policy +++ b/plugins/ps/subcommands/set-restart-policy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/subcommands/start b/plugins/ps/subcommands/start index 4f3e298d7..5d276a9af 100755 --- a/plugins/ps/subcommands/start +++ b/plugins/ps/subcommands/start @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/subcommands/startall b/plugins/ps/subcommands/startall index 63c620900..13841486e 100755 --- a/plugins/ps/subcommands/startall +++ b/plugins/ps/subcommands/startall @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -9,7 +10,7 @@ ps_startall_cmd() { local cmd="ps:startall" local GNU_PARALLEL - if which parallel > /dev/null 2>&1; then + if which parallel >/dev/null 2>&1; then dokku_log_info1 "Starting in parallel" GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) if [[ -z "$GNU_PARALLEL" ]]; then diff --git a/plugins/ps/subcommands/stop b/plugins/ps/subcommands/stop index a24b75559..512570c6e 100755 --- a/plugins/ps/subcommands/stop +++ b/plugins/ps/subcommands/stop @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" diff --git a/plugins/ps/subcommands/stopall b/plugins/ps/subcommands/stopall index 9a76657be..3014ef189 100755 --- a/plugins/ps/subcommands/stopall +++ b/plugins/ps/subcommands/stopall @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -9,7 +10,7 @@ ps_stopall_cmd() { local cmd="ps:stopall" local GNU_PARALLEL - if which parallel > /dev/null 2>&1; then + if which parallel >/dev/null 2>&1; then dokku_log_info1 "Stopping in parallel" GNU_PARALLEL=$(parallel -V 2>&1 | grep GNU || true) if [[ -z "$GNU_PARALLEL" ]]; then diff --git a/plugins/scheduler-docker-local/check-deploy b/plugins/scheduler-docker-local/check-deploy index bbced03f6..ef07db77f 100755 --- a/plugins/scheduler-docker-local/check-deploy +++ b/plugins/scheduler-docker-local/check-deploy @@ -33,7 +33,8 @@ # TIMEOUT=60 # Timeout after a minute # ATTEMPTS=10 # retry checks 10 times # -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/checks/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -41,7 +42,11 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions" scheduler-docker-local-check-deploy() { declare desc="scheduler-docker-local check-deploy plugin trigger" local trigger="scheduler-docker-local-check-deploy" - local APP="$1"; local DOKKU_APP_CONTAINER_ID="$2"; local DOKKU_APP_CONTAINER_TYPE="$3"; local DOKKU_APP_LISTEN_PORT="$4"; local DOKKU_APP_LISTEN_IP="$5" + local APP="$1" + local DOKKU_APP_CONTAINER_ID="$2" + local DOKKU_APP_CONTAINER_TYPE="$3" + local DOKKU_APP_LISTEN_PORT="$4" + local DOKKU_APP_LISTEN_IP="$5" local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then @@ -49,13 +54,13 @@ scheduler-docker-local-check-deploy() { fi if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT" ]]; then - local DOKKU_APP_LISTEN_PORT=$(< "$DOKKU_ROOT/$APP/PORT") + local DOKKU_APP_LISTEN_PORT=$(<"$DOKKU_ROOT/$APP/PORT") fi if [[ -z "$DOKKU_APP_LISTEN_IP" ]] && [[ -f "$DOKKU_ROOT/$APP/IP" ]]; then - local DOKKU_APP_LISTEN_IP=$(< "$DOKKU_ROOT/$APP/IP") + local DOKKU_APP_LISTEN_IP=$(<"$DOKKU_ROOT/$APP/IP") fi if [[ -z "$DOKKU_APP_CONTAINER_ID" ]]; then - local DOKKU_APP_CIDS=( $(get_app_container_ids "$APP") ) + local DOKKU_APP_CIDS=($(get_app_container_ids "$APP")) local DOKKU_APP_CONTAINER_ID=${DOKKU_APP_CIDS[0]} fi @@ -80,18 +85,18 @@ scheduler-docker-local-check-deploy() { # after successfully copying the file. Thus, we suppress stderr. # ref: https://github.com/dotcloud/docker/issues/3986 local CHECK_DEPLOY_TMP_WORK_DIR=$(mktemp -d /tmp/dokku_CHECKS.XXXXX) - docker cp "$DOKKU_APP_CONTAINER_ID:/app/CHECKS" "$CHECK_DEPLOY_TMP_WORK_DIR" 2> /dev/null || true + docker cp "$DOKKU_APP_CONTAINER_ID:/app/CHECKS" "$CHECK_DEPLOY_TMP_WORK_DIR" 2>/dev/null || true local FILENAME=${CHECK_DEPLOY_TMP_WORK_DIR}/CHECKS checks_check_deploy_cleanup() { declare desc="cleans up CHECK_DEPLOY_TMP_WORK_DIR and print container output" local id="$1" - rm -rf "$CHECK_DEPLOY_TMP_WORK_DIR" &> /dev/null || true + rm -rf "$CHECK_DEPLOY_TMP_WORK_DIR" &>/dev/null || true if [[ $id ]]; then - dokku_log_info2_quiet "$APP $DOKKU_APP_CONTAINER_TYPE container output:" + dokku_log_info2_quiet "$APP $DOKKU_APP_CONTAINER_TYPE container output:" dokku_container_log_verbose_quiet "$id" - dokku_log_info2_quiet "end $APP $DOKKU_APP_CONTAINER_TYPE container output" + dokku_log_info2_quiet "end $APP $DOKKU_APP_CONTAINER_TYPE container output" fi } trap 'checks_check_deploy_cleanup $DOKKU_APP_CONTAINER_ID' RETURN INT TERM EXIT @@ -106,7 +111,7 @@ scheduler-docker-local-check-deploy() { dokku_log_verbose "Non web container detected: Running default container check..." fi - rm -rf "$CHECK_DEPLOY_TMP_WORK_DIR" &> /dev/null || true + rm -rf "$CHECK_DEPLOY_TMP_WORK_DIR" &>/dev/null || true # simple default check to see if the container stuck around local DOKKU_DEFAULT_CHECKS_WAIT="${DOKKU_DEFAULT_CHECKS_WAIT:-10}" @@ -126,34 +131,34 @@ scheduler-docker-local-check-deploy() { # ensure CHECKS file has trailing newline if [[ "$(tail -c1 "$FILENAME")" != "" ]]; then - echo "" >> "$FILENAME" + echo "" >>"$FILENAME" fi # Reads name/value pairs, sets the WAIT and TIMEOUT variables - exec < "$FILENAME" - local line; local NAME; local VALUE + exec <"$FILENAME" + local line + local NAME + local VALUE while read -r line; do line=$(strip_inline_comments "$line") # Name/value pair if [[ "$line" =~ ^.+= ]]; then NAME=${line%=*} VALUE=${line#*=} - [[ "$NAME" = "WAIT" ]] && local WAIT=$VALUE - [[ "$NAME" = "TIMEOUT" ]] && local TIMEOUT=$VALUE - [[ "$NAME" = "ATTEMPTS" ]] && local ATTEMPTS=$VALUE + [[ "$NAME" == "WAIT" ]] && local WAIT=$VALUE + [[ "$NAME" == "TIMEOUT" ]] && local TIMEOUT=$VALUE + [[ "$NAME" == "ATTEMPTS" ]] && local ATTEMPTS=$VALUE fi done local ATTEMPT=0 - until [[ $SUCCESS == 1 || $ATTEMPT -ge $ATTEMPTS ]] - do + until [[ $SUCCESS == 1 || $ATTEMPT -ge $ATTEMPTS ]]; do local FAILEDCHECKS=0 - local ATTEMPT=$(( ATTEMPT + 1 )) + local ATTEMPT=$((ATTEMPT + 1)) dokku_log_info1 "Attempt $ATTEMPT/$ATTEMPTS Waiting for $WAIT seconds ..." sleep "$WAIT" - # -q Do not use .curlrc (must come first) # --compressed Test compression handled correctly # --fail Fail on server errors (4xx, 5xx) @@ -167,7 +172,7 @@ scheduler-docker-local-check-deploy() { local CURL_OPTIONS+=" -H X-Forwarded-Proto:https" fi - exec < "$FILENAME" + exec <"$FILENAME" local CHECK_URL local EXPECTED while read -r CHECK_URL EXPECTED; do @@ -216,26 +221,26 @@ scheduler-docker-local-check-deploy() { # OUTPUT contains the HTTP response if [[ ! "$OUTPUT" =~ $EXPECTED ]]; then dokku_log_warn "$LOG_URL: expected to but did not find: \"$EXPECTED\"" - local FAILEDCHECKS=$(( FAILEDCHECKS + 1 )) + local FAILEDCHECKS=$((FAILEDCHECKS + 1)) fi else # Failed to connect/no response, OUTPUT contains error message dokku_log_warn "$OUTPUT" - local FAILEDCHECKS=$(( FAILEDCHECKS + 1 )) + local FAILEDCHECKS=$((FAILEDCHECKS + 1)) fi done if [[ $FAILEDCHECKS -gt 0 ]]; then - dokku_log_warn "Check attempt $ATTEMPT/$ATTEMPTS failed." - local SUCCESS=0 + dokku_log_warn "Check attempt $ATTEMPT/$ATTEMPTS failed." + local SUCCESS=0 else - local SUCCESS=1 + local SUCCESS=1 fi done if [[ $FAILEDCHECKS -gt 0 ]]; then - dokku_log_fail "Could not start due to $FAILEDCHECKS failed checks." - exit 1 + dokku_log_fail "Could not start due to $FAILEDCHECKS failed checks." + exit 1 fi trap - EXIT diff --git a/plugins/scheduler-docker-local/commands b/plugins/scheduler-docker-local/commands index 4b53ac6b8..564163c53 100755 --- a/plugins/scheduler-docker-local/commands +++ b/plugins/scheduler-docker-local/commands @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/internal-functions" case "$1" in diff --git a/plugins/scheduler-docker-local/core-post-deploy b/plugins/scheduler-docker-local/core-post-deploy index f052097fe..5a24b04ef 100755 --- a/plugins/scheduler-docker-local/core-post-deploy +++ b/plugins/scheduler-docker-local/core-post-deploy @@ -1,12 +1,13 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" scheduler-docker-local-core-post-deploy() { declare desc="scheduler-docker-local core-post-deploy state cleanup" declare trigger="scheduler-docker-local core-post-deploy" - declare APP="$1"; + declare APP="$1" local APP_ROOT="$DOKKU_ROOT/$APP" local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") @@ -19,7 +20,7 @@ scheduler-docker-local-core-post-deploy() { local CONTAINER_FILE for CONTAINER_FILE in $CONTAINER_FILES; do - local CONTAINER_TYPE="$(awk -F '.' '{ print $2 }' <<< "$CONTAINER_FILE")" + local CONTAINER_TYPE="$(awk -F '.' '{ print $2 }' <<<"$CONTAINER_FILE")" if [[ "$(is_val_in_list "$CONTAINER_TYPE" "$PROCTYPES" " ")" == "false" ]]; then dokku_log_info1 "Container type ($CONTAINER_TYPE) is no longer defined. Removing state" local IP_FILE="${CONTAINER_FILE//CONTAINER/IP}" @@ -33,7 +34,7 @@ scheduler-docker-local-core-post-deploy() { for container in $APP_ROOT/CONTAINER.*; do local DYNO=$(echo "$container" | sed -r 's/.*CONTAINER\.(.*)/\1/') || true local NAME="$APP.$DYNO" - local CURRENT_CONTAINER_ID="$(< "$container")" + local CURRENT_CONTAINER_ID="$(<"$container")" # TODO: Ensure these are from the current service local PREVIOUS_CIDS=$(docker ps -a -q -f name="^.?$NAME\$" | xargs) || true if [[ -n $PREVIOUS_CIDS ]]; then @@ -46,7 +47,7 @@ scheduler-docker-local-core-post-deploy() { if [[ "$PREVIOUS_CONTAINER_STATUS" != "dead" ]]; then local CONTAINER_DATE_NAME="$NAME.$(date +%s)" dokku_log_info2_quiet "Renaming container ($cid) ${NAME} to $CONTAINER_DATE_NAME" - docker rename "$NAME" "$CONTAINER_DATE_NAME" > /dev/null 2>&1 || dokku_log_warn "Unable to rename container" + docker rename "$NAME" "$CONTAINER_DATE_NAME" >/dev/null 2>&1 || dokku_log_warn "Unable to rename container" fi done fi @@ -54,7 +55,7 @@ scheduler-docker-local-core-post-deploy() { local CURRENT_NAME=$(docker inspect -f '{{.Name}}' "$ID" | tr -d /) if [[ -n "$CURRENT_NAME" ]]; then dokku_log_info2_quiet "Renaming container (${ID:0:12}) $CURRENT_NAME to $NAME" - docker rename "$CURRENT_NAME" "$NAME" > /dev/null + docker rename "$CURRENT_NAME" "$NAME" >/dev/null fi done shopt -u nullglob diff --git a/plugins/scheduler-docker-local/install b/plugins/scheduler-docker-local/install index 464624d75..ec8f07590 100755 --- a/plugins/scheduler-docker-local/install +++ b/plugins/scheduler-docker-local/install @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" @@ -15,8 +16,8 @@ scheduler-docker-local-install() { DOKKU_PATH="$(which dokku)" -if [[ $(systemctl 2> /dev/null) =~ -\.mount ]]; then - cat< /etc/systemd/system/dokku-retire.service + if [[ $(systemctl 2>/dev/null) =~ -\.mount ]]; then + cat </etc/systemd/system/dokku-retire.service [Unit] Description=Dokku retire service Requires=docker.service @@ -31,24 +32,24 @@ ExecStart=$DOKKU_PATH ps:restore WantedBy=docker.service EOF - cat< /etc/systemd/system/dokku-retire.timer + cat </etc/systemd/system/dokku-retire.timer [Unit] Description=Run dokku-retire.service every 5 minutes [Timer] OnCalendar=*:0/5 EOF - if command -v systemctl &>/dev/null; then - systemctl reenable dokku-redeploy - fi -else - cat< /etc/cron.d/dokku-retire + if command -v systemctl &>/dev/null; then + systemctl reenable dokku-redeploy + fi + else + cat </etc/cron.d/dokku-retire PATH=/usr/local/bin:/usr/bin:/bin SHELL=/bin/bash */5 * * * * $DOKKU_SYSTEM_USER $DOKKU_PATH ps:retire >> /var/log/dokku/retire.log 2>&1 EOF -fi + fi } scheduler-docker-local-install "$@" diff --git a/plugins/scheduler-docker-local/internal-functions b/plugins/scheduler-docker-local/internal-functions index 37d3cd099..b8d87a922 100755 --- a/plugins/scheduler-docker-local/internal-functions +++ b/plugins/scheduler-docker-local/internal-functions @@ -2,7 +2,8 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-scheduler-docker-local-report() { declare desc="displays a scheduler-docker-local report for one or more apps" @@ -45,7 +46,8 @@ cmd-scheduler-docker-local-report-single() { dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -65,14 +67,14 @@ cmd-scheduler-docker-local-report-single() { scheduler_docker_local_help_content_func() { declare desc="return scheduler-docker-local plugin help content" - cat<] [], Displays a scheduler-docker-local report for one or more apps scheduler-docker-local:set (), Set or clear a scheduler-docker-local property for an app help_content } cmd-scheduler-docker-local-help() { - if [[ $1 = "scheduler-docker-local:help" ]] ; then + if [[ $1 == "scheduler-docker-local:help" ]]; then echo -e 'Usage: dokku scheduler-docker-local[:COMMAND]' echo '' echo 'Manages the scheduler-docker-local integration for an app.' @@ -83,7 +85,7 @@ cmd-scheduler-docker-local-help() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then scheduler_docker_local_help_content_func else - cat< /dev/null; then + if ! docker inspect "${CID}" >/dev/null; then return fi @@ -104,8 +106,8 @@ fn-scheduler-docker-local-retire-container() { # on to the next. # shellcheck disable=SC2086 docker stop $DOCKER_STOP_TIME_ARG "$CID" \ - || docker kill "$CID" \ - || dokku_log_warn "Unable to kill container ${CID}" + || docker kill "$CID" \ + || dokku_log_warn "Unable to kill container ${CID}" if ! docker kill "$CID"; then dokku_log_warn "Unable to kill container ${CID}" @@ -119,5 +121,5 @@ fn-scheduler-docker-local-register-retired-container() { CURRENT_TIME="$(date +%s)" DEAD_TIME=$((CURRENT_TIME + WAIT)) - echo "${APP} ${CID} ${DEAD_TIME}" >> "${DEAD_CONTAINER_FILE}" + echo "${APP} ${CID} ${DEAD_TIME}" >>"${DEAD_CONTAINER_FILE}" } diff --git a/plugins/scheduler-docker-local/post-app-clone-setup b/plugins/scheduler-docker-local/post-app-clone-setup index b45fb390c..ee923ab1c 100755 --- a/plugins/scheduler-docker-local/post-app-clone-setup +++ b/plugins/scheduler-docker-local/post-app-clone-setup @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x scheduler-docker-local-post-app-clone-setup() { declare desc="removes docker-local files when setting up a clone" diff --git a/plugins/scheduler-docker-local/post-create b/plugins/scheduler-docker-local/post-create index 9c9f98c29..c888fd291 100755 --- a/plugins/scheduler-docker-local/post-create +++ b/plugins/scheduler-docker-local/post-create @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x scheduler-docker-local-post-create() { declare desc="scheduler-docker-local post-create plugin trigger" diff --git a/plugins/scheduler-docker-local/post-delete b/plugins/scheduler-docker-local/post-delete index 39f753f93..c180c0905 100755 --- a/plugins/scheduler-docker-local/post-delete +++ b/plugins/scheduler-docker-local/post-delete @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -20,7 +21,7 @@ scheduler-docker-local-post-delete() { local DOKKU_APP_CIDS=$(docker ps -a --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs) if [[ -n "$DOKKU_APP_CIDS" ]]; then # shellcheck disable=SC2086 - docker rm -f $DOKKU_APP_CIDS > /dev/null 2>&1 || true + docker rm -f $DOKKU_APP_CIDS >/dev/null 2>&1 || true fi # shellcheck disable=SC2046 diff --git a/plugins/scheduler-docker-local/pre-deploy b/plugins/scheduler-docker-local/pre-deploy index cb0f6f378..d1b798799 100755 --- a/plugins/scheduler-docker-local/pre-deploy +++ b/plugins/scheduler-docker-local/pre-deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -27,7 +28,7 @@ scheduler-docker-local-pre-deploy() { CONTAINER_PATHS=$(echo "$APP_PATHS" | awk -F ':' '{ print $2 }' | xargs) DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG") # strip --restart args from DOCKER_ARGS - DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<< "$DOCKER_ARGS") + DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<<"$DOCKER_ARGS") eval "ARG_ARRAY=($DOCKER_ARGS)" fi diff --git a/plugins/scheduler-docker-local/pre-restore b/plugins/scheduler-docker-local/pre-restore index 660cd5193..7423a636f 100755 --- a/plugins/scheduler-docker-local/pre-restore +++ b/plugins/scheduler-docker-local/pre-restore @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" scheduler-docker-local-pre-restore() { @@ -13,7 +14,7 @@ scheduler-docker-local-pre-restore() { # delete all "old" containers # shellcheck disable=SC2046 - docker rm $(docker ps --format "{{.Names}}" -a -f "label=$DOKKU_CONTAINER_LABEL" -q | grep -E '(.+\..+\.[0-9]+\.[0-9]+$)') &> /dev/null || true + docker rm $(docker ps --format "{{.Names}}" -a -f "label=$DOKKU_CONTAINER_LABEL" -q | grep -E '(.+\..+\.[0-9]+\.[0-9]+$)') &>/dev/null || true } scheduler-docker-local-pre-restore "$@" diff --git a/plugins/scheduler-docker-local/report b/plugins/scheduler-docker-local/report index 6d0b13aa3..5403f8630 100755 --- a/plugins/scheduler-docker-local/report +++ b/plugins/scheduler-docker-local/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-scheduler-docker-local-report-single "$@" diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index d13a65887..f604267b9 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/checks/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -31,7 +32,10 @@ scheduler-docker-local-scheduler-deploy() { DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)" [[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}" - local line; local PROC_TYPE; local PROC_COUNT; local CONTAINER_INDEX + local line + local PROC_TYPE + local PROC_COUNT + local CONTAINER_INDEX while read -r line || [[ -n "$line" ]]; do [[ "$line" =~ ^#.* ]] && continue line="$(strip_inline_comments "$line")" @@ -45,14 +49,16 @@ scheduler-docker-local-scheduler-deploy() { for cid in $proctype_oldids; do dokku_log_info2 "stopping $APP.$PROC_TYPE ($cid)" # shellcheck disable=SC2086 - docker stop $DOCKER_STOP_TIME_ARG "$cid" &> /dev/null + docker stop $DOCKER_STOP_TIME_ARG "$cid" &>/dev/null # remove cid from oldids to skip the old container finish processing oldids="$(remove_val_from_list "$cid" "$oldids" " ")" done fi while [[ $CONTAINER_INDEX -le $PROC_COUNT ]]; do - local cid=""; local port=""; local ipaddr="" + local cid="" + local port="" + local ipaddr="" local DOKKU_CONTAINER_ID_FILE="$DOKKU_ROOT/$APP/CONTAINER.$PROC_TYPE.$CONTAINER_INDEX" # start the app @@ -100,8 +106,8 @@ scheduler-docker-local-scheduler-deploy() { declare desc="wrapper function to kill newly started app container" declare CID="$1" PROC_TYPE="$2" CONTAINER_INDEX="$3" mkdir -p "${DOKKU_LIB_ROOT}/data/scheduler-docker-local/$APP" - echo "${CID} ${PROC_TYPE}.${CONTAINER_INDEX}" >> "${DOKKU_LIB_ROOT}/data/scheduler-docker-local/$APP/failed-containers" - docker inspect "$CID" &> /dev/null && docker stop "$CID" > /dev/null && docker kill "$CID" &> /dev/null + echo "${CID} ${PROC_TYPE}.${CONTAINER_INDEX}" >>"${DOKKU_LIB_ROOT}/data/scheduler-docker-local/$APP/failed-containers" + docker inspect "$CID" &>/dev/null && docker stop "$CID" >/dev/null && docker kill "$CID" &>/dev/null trap - INT TERM EXIT kill -9 $$ } @@ -112,17 +118,17 @@ scheduler-docker-local-scheduler-deploy() { dokku_log_info1 "Attempting pre-flight checks" plugn trigger check-deploy "$APP" "$cid" "$PROC_TYPE" "$port" "$ipaddr" fi - trap - INT TERM EXIT + trap - INT TERM EXIT # now using the new container - [[ -n "$cid" ]] && echo "$cid" > "$DOKKU_CONTAINER_ID_FILE" + [[ -n "$cid" ]] && echo "$cid" >"$DOKKU_CONTAINER_ID_FILE" [[ -n "$ipaddr" ]] && plugn trigger network-write-ipaddr "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$ipaddr" [[ -n "$port" ]] && plugn trigger network-write-port "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$port" # cleanup pre-migration files rm -f "$DOKKU_ROOT/$APP/CONTAINER" "$DOKKU_ROOT/$APP/IP" "$DOKKU_ROOT/$APP/PORT" - local CONTAINER_INDEX=$(( CONTAINER_INDEX + 1 )) + local CONTAINER_INDEX=$((CONTAINER_INDEX + 1)) done # cleanup when we scale down if [[ "$PROC_COUNT" == 0 ]]; then @@ -135,7 +141,7 @@ scheduler-docker-local-scheduler-deploy() { cd "$DOKKU_ROOT/$APP" find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f done - done < "$DOKKU_SCALE_FILE" + done <"$DOKKU_SCALE_FILE" dokku_log_info1 "Running post-deploy" plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG" @@ -168,10 +174,11 @@ scheduler-docker-local-scheduler-deploy() { # on to the next. # shellcheck disable=SC2086 docker stop $DOCKER_STOP_TIME_ARG "$oldid" \ - || docker kill "$oldid" \ - || plugn trigger retire-container-failed "$APP" "$oldid" # plugin trigger for event logging + || docker kill "$oldid" \ + || plugn trigger retire-container-failed "$APP" "$oldid" # plugin trigger for event logging done - ) & disown -a + ) & + disown -a # Use trap since disown/nohup don't seem to keep child alive # Give child process just enough time to set the traps sleep 0.1 diff --git a/plugins/scheduler-docker-local/scheduler-docker-cleanup b/plugins/scheduler-docker-local/scheduler-docker-cleanup index bd1447349..73e6e7a7d 100755 --- a/plugins/scheduler-docker-local/scheduler-docker-cleanup +++ b/plugins/scheduler-docker-local/scheduler-docker-cleanup @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" scheduler-docker-local-scheduler-docker-cleanup() { @@ -13,15 +14,15 @@ scheduler-docker-local-scheduler-docker-cleanup() { # delete all non-running containers # shellcheck disable=SC2046 - docker rm $(docker ps -a -f "status=exited" -f "label=$DOKKU_CONTAINER_LABEL" -q) &> /dev/null || true + docker rm $(docker ps -a -f "status=exited" -f "label=$DOKKU_CONTAINER_LABEL" -q) &>/dev/null || true # delete all dead containers # shellcheck disable=SC2046 - docker rm $(docker ps -a -f "status=dead" -f "label=$DOKKU_CONTAINER_LABEL" -q) &> /dev/null || true + docker rm $(docker ps -a -f "status=dead" -f "label=$DOKKU_CONTAINER_LABEL" -q) &>/dev/null || true # delete unused images # shellcheck disable=SC2046 - docker rmi $(docker images -f 'dangling=true' -q) &> /dev/null & + docker rmi $(docker images -f 'dangling=true' -q) &>/dev/null & } scheduler-docker-local-scheduler-docker-cleanup "$@" diff --git a/plugins/scheduler-docker-local/scheduler-inspect b/plugins/scheduler-docker-local/scheduler-inspect index 1200314b9..7eaaae32d 100755 --- a/plugins/scheduler-docker-local/scheduler-inspect +++ b/plugins/scheduler-docker-local/scheduler-inspect @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -14,7 +15,7 @@ scheduler-docker-local-scheduler-inspect() { local TMP_INSPECT_CMD=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX") trap 'rm -rf "$TMP_INSPECT_CMD" > /dev/null' RETURN INT TERM EXIT - cat > "$TMP_INSPECT_CMD" <"$TMP_INSPECT_CMD" </dev/null | sort -t . -k 2 -n | xargs)" local CIDS=() for CONTAINER_FILE in $CONTAINER_FILES; do - CIDS+="$(< "$DOKKU_ROOT/$APP/$CONTAINER_FILE")" + CIDS+="$(<"$DOKKU_ROOT/$APP/$CONTAINER_FILE")" done docker inspect "${CIDS[@]}" | python2.7 "$TMP_INSPECT_CMD" diff --git a/plugins/scheduler-docker-local/scheduler-logs-failed b/plugins/scheduler-docker-local/scheduler-logs-failed index 1c75705f0..d816155e2 100755 --- a/plugins/scheduler-docker-local/scheduler-logs-failed +++ b/plugins/scheduler-docker-local/scheduler-logs-failed @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" scheduler-docker-local-scheduler-logs-failed() { @@ -23,12 +24,12 @@ scheduler-docker-local-scheduler-logs-failed() { while read -r LINE || [[ -n "$LINE" ]]; do CID="$(echo "$LINE" | cut -d ' ' -f1)" PREFIX="$(echo "$LINE" | cut -d ' ' -f2)" - if docker inspect "${CID}" > /dev/null 2>&1; then + if docker inspect "${CID}" >/dev/null 2>&1; then RUNNING_CONTAINERS+=("$CID") else DEAD_CONTAINERS+=("$CID") fi - done < "$FAILED_CONTAINERS_FILE" + done <"$FAILED_CONTAINERS_FILE" for CID in "${DEAD_CONTAINERS[@]}"; do dokku_log_warn "App container $CID no longer running" @@ -40,7 +41,7 @@ scheduler-docker-local-scheduler-logs-failed() { return fi - ((MAX_INDEX=${#RUNNING_CONTAINERS[*]} - 1)) || true + ((MAX_INDEX = ${#RUNNING_CONTAINERS[*]} - 1)) || true for i in ${!RUNNING_CONTAINERS[*]}; do local CID="${RUNNING_CONTAINERS[i]}" DOKKU_LOGS_CMD+="(docker logs $DOKKU_LOGS_ARGS $CID 2>&1)" diff --git a/plugins/scheduler-docker-local/scheduler-retire b/plugins/scheduler-docker-local/scheduler-retire index f40971c91..124697658 100755 --- a/plugins/scheduler-docker-local/scheduler-retire +++ b/plugins/scheduler-docker-local/scheduler-retire @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/internal-functions" @@ -26,19 +27,19 @@ scheduler-docker-local-scheduler-retire() { fi fn-scheduler-docker-local-retire-container "$APP" "$CID" "$DEAD_TIME" - if docker ps -aq -f "id=${CID}" -f "status=running" > /dev/null 2>&1; then + if docker ps -aq -f "id=${CID}" -f "status=running" >/dev/null 2>&1; then dokku_log_warn "Container ${CID} still running" continue fi - docker rm -f "$CID" > /dev/null 2>&1 || true - if docker inspect "${CID}" > /dev/null 2>&1; then + docker rm -f "$CID" >/dev/null 2>&1 || true + if docker inspect "${CID}" >/dev/null 2>&1; then dokku_log_warn "Container ${CID} still running" continue fi DEAD_CONTAINERS+=("$CID") - done < "$DEAD_CONTAINER_FILE" + done <"$DEAD_CONTAINER_FILE" for CID in "${DEAD_CONTAINERS[@]}"; do sed -i "/${CID}/d" "$DEAD_CONTAINER_FILE" diff --git a/plugins/scheduler-docker-local/scheduler-run b/plugins/scheduler-docker-local/scheduler-run index 33929d80e..3cb68173b 100755 --- a/plugins/scheduler-docker-local/scheduler-run +++ b/plugins/scheduler-docker-local/scheduler-run @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -7,7 +8,7 @@ source "$PLUGIN_AVAILABLE_PATH/ps/functions" scheduler-docker-local-scheduler-run() { declare desc="runs command in container based on app image" declare trigger="scheduler-docker-local scheduler-run" - declare DOKKU_SCHEDULER="$1" APP="$2" + declare DOKKU_SCHEDULER="$1" APP="$2" shift 2 if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then diff --git a/plugins/scheduler-docker-local/scheduler-stop b/plugins/scheduler-docker-local/scheduler-stop index 747f4b63a..bfc6e8f3a 100755 --- a/plugins/scheduler-docker-local/scheduler-stop +++ b/plugins/scheduler-docker-local/scheduler-stop @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -19,7 +20,7 @@ scheduler-docker-local-scheduler-stop() { if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then # shellcheck disable=SC2086 - docker stop $DOCKER_STOP_TIME_ARG $DOKKU_APP_RUNNING_CONTAINER_IDS > /dev/null || true + docker stop $DOCKER_STOP_TIME_ARG $DOKKU_APP_RUNNING_CONTAINER_IDS >/dev/null || true fi if [[ "$REMOVE_CONTAINERS" == "true" ]]; then @@ -27,10 +28,9 @@ scheduler-docker-local-scheduler-stop() { if [[ -n "$DOKKU_APP_CIDS" ]]; then # shellcheck disable=SC2086 - docker rm -f $DOKKU_APP_CIDS > /dev/null 2>&1 || true + docker rm -f $DOKKU_APP_CIDS >/dev/null 2>&1 || true fi fi } - scheduler-docker-local-scheduler-stop "$@" diff --git a/plugins/scheduler-docker-local/scheduler-tags-create b/plugins/scheduler-docker-local/scheduler-tags-create index 18af1133e..c4c41d81d 100755 --- a/plugins/scheduler-docker-local/scheduler-tags-create +++ b/plugins/scheduler-docker-local/scheduler-tags-create @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" scheduler-docker-local-scheduler-tags-create() { diff --git a/plugins/scheduler-docker-local/scheduler-tags-destroy b/plugins/scheduler-docker-local/scheduler-tags-destroy index a19bc8270..5c3ccfb1d 100755 --- a/plugins/scheduler-docker-local/scheduler-tags-destroy +++ b/plugins/scheduler-docker-local/scheduler-tags-destroy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" scheduler-docker-local-scheduler-tags-destroy() { diff --git a/plugins/scheduler-docker-local/subcommands/default b/plugins/scheduler-docker-local/subcommands/default index ce447b875..b2258f10b 100755 --- a/plugins/scheduler-docker-local/subcommands/default +++ b/plugins/scheduler-docker-local/subcommands/default @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/internal-functions" cmd-scheduler-docker-local-help "scheduler-docker-local:help" diff --git a/plugins/scheduler-docker-local/subcommands/report b/plugins/scheduler-docker-local/subcommands/report index ab61cfcb7..a9787c80c 100755 --- a/plugins/scheduler-docker-local/subcommands/report +++ b/plugins/scheduler-docker-local/subcommands/report @@ -1,5 +1,6 @@ #!/usr/bin/env bash source "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-scheduler-docker-local-report "$@" diff --git a/plugins/scheduler-docker-local/subcommands/set b/plugins/scheduler-docker-local/subcommands/set index 7bc84c381..99a37fb3e 100755 --- a/plugins/scheduler-docker-local/subcommands/set +++ b/plugins/scheduler-docker-local/subcommands/set @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x fn-in-array() { declare desc="return true if value ($1) is in list (all other arguments)" @@ -15,7 +16,8 @@ fn-in-array() { scheduler-docker-local-set-cmd() { declare desc="set or clear a scheduler-docker-local property for an app" - local cmd="scheduler-docker-local:set" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 + local cmd="scheduler-docker-local:set" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 declare APP="$1" KEY="$2" VALUE="$3" local VALID_KEYS=("disable-chown") [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" diff --git a/plugins/shell/commands b/plugins/shell/commands index e31fc0298..df45312ea 100755 --- a/plugins/shell/commands +++ b/plugins/shell/commands @@ -1,27 +1,28 @@ #!/usr/bin/env bash [[ " help shell:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | shell:help) - help_content_func () { + help_content_func() { declare desc="return shell plugin help content" - cat< " line || { - echo; true; break + echo + true + break } trap - SIGINT @@ -36,7 +38,7 @@ shell_cmd() { clear ;; - quit|exit) + quit | exit) break ;; @@ -44,6 +46,7 @@ shell_cmd() { *) # shellcheck disable=SC2086 dokku $line || true + ;; esac done diff --git a/plugins/ssh-keys/commands b/plugins/ssh-keys/commands index 1aabfd445..67d6b3740 100755 --- a/plugins/ssh-keys/commands +++ b/plugins/ssh-keys/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help ssh-keys:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/ssh-keys/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | ssh-keys:help) diff --git a/plugins/ssh-keys/functions b/plugins/ssh-keys/functions index 2d5d1ebf0..f18200830 100755 --- a/plugins/ssh-keys/functions +++ b/plugins/ssh-keys/functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" list_ssh_keys() { @@ -15,7 +16,7 @@ verify_ssh_key_file() { local key line=0 while read -r key; do line=$((line + 1)) - ssh-keygen -l -f /dev/stdin <<< "$key" &> /dev/null || dokku_log_fail "${DOKKU_ROOT}/.ssh/authorized_keys line $line failed ssh-keygen check." + ssh-keygen -l -f /dev/stdin <<<"$key" &>/dev/null || dokku_log_fail "${DOKKU_ROOT}/.ssh/authorized_keys line $line failed ssh-keygen check." done <"${DOKKU_ROOT}/.ssh/authorized_keys" } diff --git a/plugins/ssh-keys/internal-functions b/plugins/ssh-keys/internal-functions index e4bff023f..818136cbe 100755 --- a/plugins/ssh-keys/internal-functions +++ b/plugins/ssh-keys/internal-functions @@ -1,9 +1,10 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x ssh_keys_help_content_func() { declare desc="return ssh-keys plugin help content" - cat< [/path/to/key], Add a new public key by pipe or path ssh-keys:remove , Remove SSH public key by name @@ -11,7 +12,7 @@ help_content } ssh_keys_help_cmd() { - if [[ $1 = "ssh-keys:help" ]] ; then + if [[ $1 == "ssh-keys:help" ]]; then echo -e 'Usage: dokku ssh-keys[:COMMAND]' echo '' echo 'Manage public ssh keys that are allowed to connect to Dokku' @@ -21,7 +22,7 @@ ssh_keys_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then ssh_keys_help_content_func else - cat< /dev/null || dokku_log_fail "Key piped in is not a valid ssh public key" + ssh-keygen -lf /dev/stdin <<<"$key_from_pipe" &>/dev/null || dokku_log_fail "Key piped in is not a valid ssh public key" key_contents="$key_from_pipe" elif [[ -n "$key_file" ]]; then key_contents="$(cat "$key_file")" - ssh-keygen -lf /dev/stdin <<< "$key_contents" &> /dev/null || dokku_log_fail "Key from file is not a valid ssh public key" + ssh-keygen -lf /dev/stdin <<<"$key_contents" &>/dev/null || dokku_log_fail "Key from file is not a valid ssh public key" fi [[ -n "$name" && -n "$key_contents" ]] || dokku_log_fail "Two arguments are required if not piping, ie: dokku ssh-keys:add " - local count="$(wc -l <<< "$key_contents")" + local count="$(wc -l <<<"$key_contents")" [ "$count" -eq 1 ] || dokku_log_fail 'Too many keys provided, set one per invocation of dokku ssh-keys:add ' create_ssh_key_file verify_ssh_key_exists diff --git a/plugins/ssh-keys/subcommands/default b/plugins/ssh-keys/subcommands/default index 2260f6e62..1ee01b434 100755 --- a/plugins/ssh-keys/subcommands/default +++ b/plugins/ssh-keys/subcommands/default @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_AVAILABLE_PATH/ssh-keys/internal-functions" ssh_keys_help_cmd "ssh-keys:help" diff --git a/plugins/ssh-keys/subcommands/list b/plugins/ssh-keys/subcommands/list index fb78c5e2a..853e98fc1 100755 --- a/plugins/ssh-keys/subcommands/list +++ b/plugins/ssh-keys/subcommands/list @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ssh-keys/functions" diff --git a/plugins/ssh-keys/subcommands/remove b/plugins/ssh-keys/subcommands/remove index 3e7e5c5fe..7f19b06a8 100755 --- a/plugins/ssh-keys/subcommands/remove +++ b/plugins/ssh-keys/subcommands/remove @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/ssh-keys/functions" diff --git a/plugins/ssh-keys/user-auth b/plugins/ssh-keys/user-auth index a5025c4a6..6fea1dca8 100755 --- a/plugins/ssh-keys/user-auth +++ b/plugins/ssh-keys/user-auth @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" check_ssh_keys_user() { diff --git a/plugins/storage/commands b/plugins/storage/commands index d4335a84c..459d53762 100755 --- a/plugins/storage/commands +++ b/plugins/storage/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " storage:help help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/storage/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | storage:help) diff --git a/plugins/storage/functions b/plugins/storage/functions index 643fa906c..6fc97da21 100755 --- a/plugins/storage/functions +++ b/plugins/storage/functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" @@ -18,5 +19,5 @@ check_if_path_exists() { get_bind_mounts() { declare desc="strips docker options and prints mounts" local -r phase_file_path=$1 - [[ -r "$phase_file_path" ]] && sed -e '/^-v/!d' -e 's/^-v/ /' < "$phase_file_path" + [[ -r "$phase_file_path" ]] && sed -e '/^-v/!d' -e 's/^-v/ /' <"$phase_file_path" } diff --git a/plugins/storage/install b/plugins/storage/install index 49b4ce5ec..fb23f28d0 100755 --- a/plugins/storage/install +++ b/plugins/storage/install @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x mkdir -p "${DOKKU_LIB_ROOT}/data/storage" chown dokku:dokku "${DOKKU_LIB_ROOT}/data/storage" diff --git a/plugins/storage/internal-functions b/plugins/storage/internal-functions index 9a4175cf5..30b297143 100755 --- a/plugins/storage/internal-functions +++ b/plugins/storage/internal-functions @@ -2,7 +2,8 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/storage/functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x cmd-storage-report() { declare desc="displays a storage report for one or more apps" @@ -47,7 +48,8 @@ cmd-storage-report-single() { dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#*: }")" done else - local match=false; local value_exists=false + local match=false + local value_exists=false for flag in "${flag_map[@]}"; do valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)" if [[ "$flag" == "${INFO_FLAG}:"* ]]; then @@ -74,8 +76,8 @@ fn-storage-bind-mounts() { } storage_help_content_func() { - declare desc="return storage plugin help content" - cat<, List bind mounts for app's container(s) (host:container) storage:mount , Create a new bind mount storage:report [] [], Displays a checks report for one or more apps @@ -84,7 +86,7 @@ help_content } storage_help_cmd() { - if [[ $1 = "storage:help" ]] ; then + if [[ $1 == "storage:help" ]]; then echo -e 'Usage: dokku storage[:COMMAND]' echo '' echo 'Mount local volume / directories inside containers.' @@ -94,7 +96,7 @@ storage_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then storage_help_content_func else - cat<, List all app image tags tags:create , Add tag to latest running app image tags:deploy , Deploy tagged app image @@ -14,15 +15,15 @@ case "$1" in help_content } - if [[ $1 = "tags:help" ]] ; then - echo -e 'Usage: dokku tags[:COMMAND]' - echo '' - echo 'Manage docker image tags.' - echo '' - echo 'Additional commands:' - help_content_func | sort | column -c2 -t -s, + if [[ $1 == "tags:help" ]]; then + echo -e 'Usage: dokku tags[:COMMAND]' + echo '' + echo 'Manage docker image tags.' + echo '' + echo 'Additional commands:' + help_content_func | sort | column -c2 -t -s, else - help_content_func + help_content_func fi ;; diff --git a/plugins/tags/subcommands/create b/plugins/tags/subcommands/create index 6c0286d15..755a752d9 100755 --- a/plugins/tags/subcommands/create +++ b/plugins/tags/subcommands/create @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -7,7 +8,9 @@ tags_create_cmd() { declare desc="creates an images tag for app via command line" local cmd="tags:create" [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" - local APP="$2"; local IMAGE_TAG="$3"; local IMAGE_REPO=$(get_app_image_repo "$APP") + local APP="$2" + local IMAGE_TAG="$3" + local IMAGE_REPO=$(get_app_image_repo "$APP") verify_app_name "$APP" local DOKKU_SCHEDULER=$(get_app_scheduler "$APP") diff --git a/plugins/tags/subcommands/default b/plugins/tags/subcommands/default index 1b9da0050..1c3595123 100755 --- a/plugins/tags/subcommands/default +++ b/plugins/tags/subcommands/default @@ -1,12 +1,14 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" tags_main_cmd() { declare desc="shows docker images tags for app via command line" local cmd="tags" [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" - local APP="$2"; local IMAGE_REPO=$(get_app_image_repo "$APP") + local APP="$2" + local IMAGE_REPO=$(get_app_image_repo "$APP") verify_app_name "$APP" dokku_log_info2_quiet "Image tags for $IMAGE_REPO" diff --git a/plugins/tags/subcommands/deploy b/plugins/tags/subcommands/deploy index 2b4fd16f0..c87f7312c 100755 --- a/plugins/tags/subcommands/deploy +++ b/plugins/tags/subcommands/deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" tags_deploy_cmd() { @@ -14,7 +15,7 @@ tags_deploy_cmd() { verify_image "$IMAGE" || return 1 release_and_deploy "$APP" "$IMAGE_TAG" - if [[ "$IMAGE_TAG" != "latest" ]]; then + if [[ "$IMAGE_TAG" != "latest" ]]; then local DOKKU_SCHEDULER="$(get_app_scheduler "$APP")" local LATEST_IMAGE="$(get_app_image_name "$APP")" plugn trigger scheduler-tags-create "$DOKKU_SCHEDULER" "$APP" "$IMAGE" "$LATEST_IMAGE" diff --git a/plugins/tags/subcommands/destroy b/plugins/tags/subcommands/destroy index 1b285641f..f23009b46 100755 --- a/plugins/tags/subcommands/destroy +++ b/plugins/tags/subcommands/destroy @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" @@ -7,7 +8,9 @@ tags_destroy_cmd() { declare desc="destroys an app image tag via command line" local cmd="tags:destroy" [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on" - local APP="$2"; local IMAGE_TAG="$3"; local IMAGE_REPO=$(get_app_image_repo "$APP") + local APP="$2" + local IMAGE_TAG="$3" + local IMAGE_REPO=$(get_app_image_repo "$APP") verify_app_name "$2" case "$IMAGE_TAG" in diff --git a/plugins/tar/commands b/plugins/tar/commands index 50fb131fb..9c29b3358 100755 --- a/plugins/tar/commands +++ b/plugins/tar/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash [[ " help tar:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" source "$PLUGIN_AVAILABLE_PATH/tar/internal-functions" -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x case "$1" in help | tar:help) diff --git a/plugins/tar/deploy-source b/plugins/tar/deploy-source index ab8517f10..d83e51c9e 100755 --- a/plugins/tar/deploy-source +++ b/plugins/tar/deploy-source @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x tar_deploy_source() { declare desc="tar deploy-source plugin trigger" diff --git a/plugins/tar/functions b/plugins/tar/functions index 166488b87..8a884de73 100755 --- a/plugins/tar/functions +++ b/plugins/tar/functions @@ -1,11 +1,13 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" tar_build() { declare desc="builds apps from tarball via command line" - local APP="$1"; verify_app_name "$APP" + local APP="$1" + verify_app_name "$APP" shift 1 # clean up after ourselves @@ -14,7 +16,7 @@ tar_build() { # extract tar file chmod 755 "$TAR_BUILD_TMP_WORK_DIR" - pushd "$TAR_BUILD_TMP_WORK_DIR" > /dev/null + pushd "$TAR_BUILD_TMP_WORK_DIR" >/dev/null # Detect a common prefix that all files in the tar have, and strip off each directory found in it local COMMON_PREFIX=$(tar -tf "$DOKKU_ROOT/$APP/src.tar" | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D') @@ -42,7 +44,10 @@ tar_trigger_build() { declare APP="$1" TMP_WORK_DIR="$2" REV="$3" plugn trigger post-extract "$APP" "$TMP_WORK_DIR" "$REV" - if [[ -f Dockerfile ]] && [[ "$([[ -f .env ]] && grep -q BUILDPACK_URL .env; echo $?)" != "0" ]] && [[ ! -f ".buildpacks" ]] && [[ -z $(config_get "$APP" BUILDPACK_URL || true) ]]; then + if [[ -f Dockerfile ]] && [[ "$( + [[ -f .env ]] && grep -q BUILDPACK_URL .env + echo $? + )" != "0" ]] && [[ ! -f ".buildpacks" ]] && [[ -z $(config_get "$APP" BUILDPACK_URL || true) ]]; then plugn trigger pre-receive-app "$APP" "dockerfile" "$TMP_WORK_DIR" "$REV" dokku_receive "$APP" "dockerfile" "$TMP_WORK_DIR" else diff --git a/plugins/tar/internal-functions b/plugins/tar/internal-functions index 1d81df165..a21dadfd4 100755 --- a/plugins/tar/internal-functions +++ b/plugins/tar/internal-functions @@ -1,16 +1,17 @@ #!/usr/bin/env bash -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x tar_help_content_func() { declare desc="return tar plugin help content" - cat<, Reads an tarball containing the app from stdin tar:from , Loads an app tarball from url help_content } tar_help_cmd() { - if [[ $1 = "tar:help" ]] ; then + if [[ $1 == "tar:help" ]]; then echo -e 'Usage: dokku tar[:COMMAND]' echo '' echo 'An alternative to using git, apps are loaded via tarballs instead.' @@ -20,7 +21,7 @@ tar_help_cmd() { elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then tar_help_content_func else - cat< /dev/null 2>&1 ; echo $$?),0) +ifeq ($(shfmt),Darwin) + brew install shfmt +else + wget -qO /tmp/shfmt https://github.com/mvdan/sh/releases/download/v2.6.2/shfmt_v2.6.2_linux_amd64 + chmod +x /tmp/shfmt + sudo mv /tmp/shfmt /usr/local/bin/shfmt +endif +endif + xmlstarlet: ifneq ($(shell xmlstarlet --version > /dev/null 2>&1 ; echo $$?),0) ifeq ($(SYSTEM),Darwin) @@ -31,7 +42,7 @@ else endif endif -ci-dependencies: shellcheck bats xmlstarlet +ci-dependencies: bats shellcheck shfmt xmlstarlet setup-deploy-tests: mkdir -p /home/dokku @@ -83,6 +94,10 @@ lint-setup: @cat tests/shellcheck-exclude | sed -n -e '/^# SC/p' | cut -d' ' -f2 | paste -d, -s > tmp/shellcheck/exclude lint: lint-setup + # verifying via shfmt + # shfmt -l -bn -ci -i 2 -d . + @shfmt -l -bn -ci -i 2 -d . + # these are disabled due to their expansive existence in the codebase. we should clean it up though @cat tests/shellcheck-exclude | sed -n -e '/^# SC/p' @echo linting... diff --git a/tests/apps/.websocket.disabled/check_deploy b/tests/apps/.websocket.disabled/check_deploy index 3a1dd57ed..892f47082 100755 --- a/tests/apps/.websocket.disabled/check_deploy +++ b/tests/apps/.websocket.disabled/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S -i -N -H \"Connection: Upgrade\" -H \"Upgrade: websocket\" -H \"Host: $1\" -H \"Origin: $1\" $1 -m 2)"; echo $output; test "$output" == "bazingaa" +set -e +output="$(curl -s -S -i -N -H \"Connection: Upgrade\" -H \"Upgrade: websocket\" -H \"Host: $1\" -H \"Origin: $1\" $1 -m 2)" +echo $output +test "$output" == "bazingaa" diff --git a/tests/apps/clojure/check_deploy b/tests/apps/clojure/check_deploy index fa1f6e489..29e223aba 100755 --- a/tests/apps/clojure/check_deploy +++ b/tests/apps/clojure/check_deploy @@ -1,2 +1,6 @@ #!/usr/bin/env bash -set -e; sleep 5; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello World!" +set -e +sleep 5 +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "Hello World!" diff --git a/tests/apps/config/check_deploy b/tests/apps/config/check_deploy index e6b0cb135..d0ad9f3af 100755 --- a/tests/apps/config/check_deploy +++ b/tests/apps/config/check_deploy @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -e; +set -e -test_url () { +test_url() { path="$1" expected_output="$2" url="$base_url$path" diff --git a/tests/apps/config/post-deploy b/tests/apps/config/post-deploy index 61cda9ea4..9f73e775b 100755 --- a/tests/apps/config/post-deploy +++ b/tests/apps/config/post-deploy @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex; +set -ex REMOTE=$1 REPO=$2 diff --git a/tests/apps/dockerfile-noexpose/check_deploy b/tests/apps/dockerfile-noexpose/check_deploy index b652fb8f6..e3c3a8dce 100755 --- a/tests/apps/dockerfile-noexpose/check_deploy +++ b/tests/apps/dockerfile-noexpose/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello World!" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "Hello World!" diff --git a/tests/apps/dockerfile-procfile-bad/check_deploy b/tests/apps/dockerfile-procfile-bad/check_deploy index 1334888e2..e4519b442 100644 --- a/tests/apps/dockerfile-procfile-bad/check_deploy +++ b/tests/apps/dockerfile-procfile-bad/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "nodejs/express" diff --git a/tests/apps/dockerfile-procfile/check_deploy b/tests/apps/dockerfile-procfile/check_deploy index 1334888e2..e4519b442 100755 --- a/tests/apps/dockerfile-procfile/check_deploy +++ b/tests/apps/dockerfile-procfile/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "nodejs/express" diff --git a/tests/apps/dockerfile/check_deploy b/tests/apps/dockerfile/check_deploy index c047ec81b..7682679ed 100755 --- a/tests/apps/dockerfile/check_deploy +++ b/tests/apps/dockerfile/check_deploy @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -e; +set -e -test_url () { +test_url() { path="$1" expected_output="$2" url="${base_url}:3000${path}" diff --git a/tests/apps/dockerfile/post-deploy b/tests/apps/dockerfile/post-deploy index 973188fb0..b9d24d2e8 100755 --- a/tests/apps/dockerfile/post-deploy +++ b/tests/apps/dockerfile/post-deploy @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex; +set -ex REMOTE=$1 REPO=$2 diff --git a/tests/apps/gitsubmodules/check_deploy b/tests/apps/gitsubmodules/check_deploy index b652fb8f6..e3c3a8dce 100755 --- a/tests/apps/gitsubmodules/check_deploy +++ b/tests/apps/gitsubmodules/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello World!" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "Hello World!" diff --git a/tests/apps/go-fail-postdeploy/check_deploy b/tests/apps/go-fail-postdeploy/check_deploy index 980dc933a..04b39f48b 100755 --- a/tests/apps/go-fail-postdeploy/check_deploy +++ b/tests/apps/go-fail-postdeploy/check_deploy @@ -1,2 +1,3 @@ #!/usr/bin/env bash -set -e; test "$(curl -s -S "$1")" == "go" +set -e +test "$(curl -s -S "$1")" == "go" diff --git a/tests/apps/go-fail-predeploy/check_deploy b/tests/apps/go-fail-predeploy/check_deploy index 980dc933a..04b39f48b 100755 --- a/tests/apps/go-fail-predeploy/check_deploy +++ b/tests/apps/go-fail-predeploy/check_deploy @@ -1,2 +1,3 @@ #!/usr/bin/env bash -set -e; test "$(curl -s -S "$1")" == "go" +set -e +test "$(curl -s -S "$1")" == "go" diff --git a/tests/apps/go/check_deploy b/tests/apps/go/check_deploy index 980dc933a..04b39f48b 100755 --- a/tests/apps/go/check_deploy +++ b/tests/apps/go/check_deploy @@ -1,2 +1,3 @@ #!/usr/bin/env bash -set -e; test "$(curl -s -S "$1")" == "go" +set -e +test "$(curl -s -S "$1")" == "go" diff --git a/tests/apps/java/check_deploy b/tests/apps/java/check_deploy index aad082553..f8a7f75be 100755 --- a/tests/apps/java/check_deploy +++ b/tests/apps/java/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello from Java!" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "Hello from Java!" diff --git a/tests/apps/multi/check_deploy b/tests/apps/multi/check_deploy index 9dfac8577..ae5f59030 100755 --- a/tests/apps/multi/check_deploy +++ b/tests/apps/multi/check_deploy @@ -1,2 +1,3 @@ #!/usr/bin/env bash -set -e; curl -s -S "$1" | grep -q "Heroku Multi Buildpack on Dokku" +set -e +curl -s -S "$1" | grep -q "Heroku Multi Buildpack on Dokku" diff --git a/tests/apps/nodejs-express-noprocfile/check_deploy b/tests/apps/nodejs-express-noprocfile/check_deploy index 1334888e2..e4519b442 100755 --- a/tests/apps/nodejs-express-noprocfile/check_deploy +++ b/tests/apps/nodejs-express-noprocfile/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "nodejs/express" diff --git a/tests/apps/nodejs-express/check_deploy b/tests/apps/nodejs-express/check_deploy index 1334888e2..e4519b442 100755 --- a/tests/apps/nodejs-express/check_deploy +++ b/tests/apps/nodejs-express/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "nodejs/express" diff --git a/tests/apps/nodejs-worker/check_deploy b/tests/apps/nodejs-worker/check_deploy index bf1cd32aa..edd7b9d04 100755 --- a/tests/apps/nodejs-worker/check_deploy +++ b/tests/apps/nodejs-worker/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(pgrep -f "node worker.js" | wc -l)"; echo "$output"; test "$output" == "1" +set -e +output="$(pgrep -f "node worker.js" | wc -l)" +echo "$output" +test "$output" == "1" diff --git a/tests/apps/php/check_deploy b/tests/apps/php/check_deploy index 2c5af54c7..c85c66d06 100755 --- a/tests/apps/php/check_deploy +++ b/tests/apps/php/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "

php

" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "

php

" diff --git a/tests/apps/python-flask/check_deploy b/tests/apps/python-flask/check_deploy index 65408ff64..7fae3515a 100755 --- a/tests/apps/python-flask/check_deploy +++ b/tests/apps/python-flask/check_deploy @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -e; +set -e base_url=$1 -test_url () { +test_url() { path="$1" expected_output="$2" url="${base_url}${path}" diff --git a/tests/apps/python-flask/post-deploy b/tests/apps/python-flask/post-deploy index 973188fb0..b9d24d2e8 100755 --- a/tests/apps/python-flask/post-deploy +++ b/tests/apps/python-flask/post-deploy @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -ex; +set -ex REMOTE=$1 REPO=$2 diff --git a/tests/apps/ruby/check_deploy b/tests/apps/ruby/check_deploy index 4001f55ac..320998c30 100755 --- a/tests/apps/ruby/check_deploy +++ b/tests/apps/ruby/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello, world" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "Hello, world" diff --git a/tests/apps/scala/check_deploy b/tests/apps/scala/check_deploy index 40c0692c6..0466f2eca 100755 --- a/tests/apps/scala/check_deploy +++ b/tests/apps/scala/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello from Scala!" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "Hello from Scala!" diff --git a/tests/apps/static/check_deploy b/tests/apps/static/check_deploy index 2fea58d2d..fdcdf331f 100755 --- a/tests/apps/static/check_deploy +++ b/tests/apps/static/check_deploy @@ -1,2 +1,5 @@ #!/usr/bin/env bash -set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "

Static Page

" +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "

Static Page

" diff --git a/tests/bats-exec-test-single b/tests/bats-exec-test-single index 8012ca47c..762fc2df5 100755 --- a/tests/bats-exec-test-single +++ b/tests/bats-exec-test-single @@ -46,7 +46,7 @@ main() { TMP_OUTPUT=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX") trap 'rm -rf "$TMP_OUTPUT" > /dev/null' RETURN INT TERM EXIT - /usr/local/libexec/bats-preprocess < "$TEST_FILE" > "$TMP_OUTPUT" + /usr/local/libexec/bats-preprocess <"$TEST_FILE" >"$TMP_OUTPUT" AVAILABLE_TESTS="$(fn-available-tests "$TMP_OUTPUT")" MATCHED_TEST=$(fn-matched-test "$TEST_NAME" "$AVAILABLE_TESTS") diff --git a/tests/ci/setup.sh b/tests/ci/setup.sh index 8d5890712..9bfb8fcc9 100755 --- a/tests/ci/setup.sh +++ b/tests/ci/setup.sh @@ -45,12 +45,12 @@ install_dokku() { "${ROOT_DIR}/contrib/release" build - echo "dokku dokku/hostname string dokku.me" | sudo debconf-set-selections + echo "dokku dokku/hostname string dokku.me" | sudo debconf-set-selections echo "dokku dokku/key_file string /root/.ssh/id_rsa.pub" | sudo debconf-set-selections - echo "dokku dokku/nginx_enable boolean true" | sudo debconf-set-selections - echo "dokku dokku/skip_key_file boolean true" | sudo debconf-set-selections - echo "dokku dokku/vhost_enable boolean true" | sudo debconf-set-selections - echo "dokku dokku/web_config boolean false" | sudo debconf-set-selections + echo "dokku dokku/nginx_enable boolean true" | sudo debconf-set-selections + echo "dokku dokku/skip_key_file boolean true" | sudo debconf-set-selections + echo "dokku dokku/vhost_enable boolean true" | sudo debconf-set-selections + echo "dokku dokku/web_config boolean false" | sudo debconf-set-selections sudo dpkg -i "$(cat "${ROOT_DIR}/build/deb-filename")" } diff --git a/tests/ci/unit_test_runner.sh b/tests/ci/unit_test_runner.sh index 189bf497f..53f18d6d2 100755 --- a/tests/ci/unit_test_runner.sh +++ b/tests/ci/unit_test_runner.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash is_number() { - local NUMBER=$1; local NUM_RE='^[1-4]+$' + local NUMBER=$1 + local NUM_RE='^[1-4]+$' if [[ $NUMBER =~ $NUM_RE ]]; then return 0 else @@ -33,6 +34,6 @@ for test in $TESTS; do fi endtest=$(date +%s) - testruntime=$((endtest-starttest)) + testruntime=$((endtest - starttest)) echo "individual runtime: $(date -u -d @${testruntime} +"%T")" done diff --git a/tests/test_deploy b/tests/test_deploy index 200e126a8..f7e605b5c 100755 --- a/tests/test_deploy +++ b/tests/test_deploy @@ -1,7 +1,11 @@ #!/usr/bin/env bash set -xeo pipefail -SELF=$(which "$0"); APP="$1"; TARGET="$2"; FORWARDED_PORT="$3"; SHOULD_FAIL="$4" +SELF=$(which "$0") +APP="$1" +TARGET="$2" +FORWARDED_PORT="$3" +SHOULD_FAIL="$4" REMOTE="dokku@$TARGET" REPO="test-$(basename "$APP")-$RANDOM" @@ -25,7 +29,7 @@ succeeded() { TMP=$(mktemp -d "/tmp/$TARGET.XXXXX") rmdir "$TMP" && cp -r "$(dirname "$SELF")/$APP" "$TMP" -pushd "$TMP" &> /dev/null || exit 1 +pushd "$TMP" &>/dev/null || exit 1 trap 'popd &> /dev/null || true; rm -rf "$TMP"' INT TERM EXIT git init diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index bf3a8d7e4..81c54050c 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -9,7 +9,7 @@ PLUGIN_ENABLED_PATH=${PLUGIN_ENABLED_PATH:="$PLUGIN_PATH/enabled"} PLUGIN_CORE_PATH=${PLUGIN_CORE_PATH:="$DOKKU_LIB_ROOT/core-plugins"} PLUGIN_CORE_AVAILABLE_PATH=${PLUGIN_CORE_AVAILABLE_PATH:="$PLUGIN_CORE_PATH/available"} CUSTOM_TEMPLATE_SSL_DOMAIN=customssltemplate.dokku.me -UUID=$(tr -dc 'a-z0-9' < /dev/urandom | fold -w 32 | head -n 1) +UUID=$(tr -dc 'a-z0-9' /dev/null + ssh-keygen -P "" -f /tmp/testkey &>/dev/null } destroy_app() { - local RC="$1"; local RC=${RC:=0} - local APP="$2"; local TEST_APP=${APP:=$TEST_APP} + local RC="$1" + local RC=${RC:=0} + local APP="$2" + local TEST_APP=${APP:=$TEST_APP} dokku --force apps:destroy "$TEST_APP" return "$RC" } destroy_key() { - rm -f /tmp/testkey* &> /dev/null || true + rm -f /tmp/testkey* &>/dev/null || true } add_domain() { @@ -214,7 +223,7 @@ deploy_app() { # shellcheck disable=SC2086 [[ -n "$CUSTOM_TEMPLATE" ]] && $CUSTOM_TEMPLATE $TEST_APP $TMP/$CUSTOM_PATH - pushd "$TMP" &> /dev/null || exit 1 + pushd "$TMP" &>/dev/null || exit 1 trap 'popd &> /dev/null || true; rm -rf "$TMP"' RETURN INT TERM git init @@ -243,7 +252,8 @@ setup_client_repo() { } setup_test_tls() { - local TLS_TYPE="$1"; local TLS="/home/dokku/$TEST_APP/tls" + local TLS_TYPE="$1" + local TLS="/home/dokku/$TEST_APP/tls" mkdir -p "$TLS" case "$TLS_TYPE" in @@ -262,12 +272,13 @@ setup_test_tls() { } custom_ssl_nginx_template() { - local APP="$1"; local APP_REPO_DIR="$2" + local APP="$1" + local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" mkdir -p "$APP_REPO_DIR" echo "injecting custom_ssl_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil" -cat< "$APP_REPO_DIR/nginx.conf.sigil" + cat <"$APP_REPO_DIR/nginx.conf.sigil" {{ range \$port_map := .PROXY_PORT_MAP | split " " }} {{ \$port_map_list := \$port_map | split ":" }} {{ \$scheme := index \$port_map_list 0 }} @@ -316,16 +327,17 @@ upstream {{ $.APP }}-{{ \$upstream_port }} { } {{ end }}{{ end }} EOF -cat "$APP_REPO_DIR/nginx.conf.sigil" + cat "$APP_REPO_DIR/nginx.conf.sigil" } custom_nginx_template() { - local APP="$1"; local APP_REPO_DIR="$2" + local APP="$1" + local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" mkdir -p "$APP_REPO_DIR" echo "injecting custom_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil" -cat< "$APP_REPO_DIR/nginx.conf.sigil" + cat <"$APP_REPO_DIR/nginx.conf.sigil" {{ range \$port_map := .PROXY_PORT_MAP | split " " }} {{ \$port_map_list := \$port_map | split ":" }} {{ \$scheme := index \$port_map_list 0 }} @@ -362,14 +374,15 @@ upstream {{ $.APP }}-{{ \$upstream_port }} { } {{ end }}{{ end }} EOF -cat "$APP_REPO_DIR/nginx.conf.sigil" + cat "$APP_REPO_DIR/nginx.conf.sigil" } bad_custom_nginx_template() { - local APP="$1"; local APP_REPO_DIR="$2" + local APP="$1" + local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" echo "injecting bad_custom_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil" -cat< "$APP_REPO_DIR/nginx.conf.sigil" + cat <"$APP_REPO_DIR/nginx.conf.sigil" some lame nginx config EOF }