diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index faca9de..06f39ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,12 +10,14 @@ on: branches: - master +concurrency: + group: build-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: unit-tests-master: name: unit-tests runs-on: ubuntu-20.04 - strategy: - fail-fast: true env: DOKKU_VERSION: master @@ -58,8 +60,6 @@ jobs: unit-tests-0_19_0: name: unit-tests-0.19.0 runs-on: ubuntu-20.04 - strategy: - fail-fast: true env: DOKKU_TAG: v0.19.0 diff --git a/README.md b/README.md index 0c54de0..ea0f023 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,11 @@ flags: - `-i|--image IMAGE`: the image name to start the service with - `-I|--image-version IMAGE_VERSION`: the image version to start the service with - `-m|--memory MEMORY`: container memory limit in megabytes (default: unlimited) +- `-N|--initial-network INITIAL_NETWORK`: the initial network to attach the service to - `-p|--password PASSWORD`: override the user-level service password +- `-P|--post-create-network NETWORKS`: a comman-separated list of networks to attach the service container to after service creation - `-r|--root-password PASSWORD`: override the root-level service password +- `-S|--post-start-network NETWORKS`: a comman-separated list of networks to attach the service container to after service start - `-s|--shm-size SHM_SIZE`: override shared memory size for postgres docker container Create a postgres service named lollipop: @@ -454,7 +457,10 @@ flags: - `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with - `-i|--image IMAGE`: the image name to start the service with - `-I|--image-version IMAGE_VERSION`: the image version to start the service with +- `-N|--initial-network INITIAL_NETWORK`: the initial network to attach the service to +- `-P|--post-create-network NETWORKS`: a comman-separated list of networks to attach the service container to after service creation - `-R|--restart-apps "true"`: whether to force an app restart +- `-S|--post-start-network NETWORKS`: a comman-separated list of networks to attach the service container to after service start - `-s|--shm-size SHM_SIZE`: override shared memory size for postgres docker container You can upgrade an existing service to a new image or image-version: @@ -525,8 +531,11 @@ flags: - `-i|--image IMAGE`: the image name to start the service with - `-I|--image-version IMAGE_VERSION`: the image version to start the service with - `-m|--memory MEMORY`: container memory limit in megabytes (default: unlimited) +- `-N|--initial-network INITIAL_NETWORK`: the initial network to attach the service to - `-p|--password PASSWORD`: override the user-level service password +- `-P|--post-create-network NETWORKS`: a comman-separated list of networks to attach the service container to after service creation - `-r|--root-password PASSWORD`: override the root-level service password +- `-S|--post-start-network NETWORKS`: a comman-separated list of networks to attach the service container to after service start - `-s|--shm-size SHM_SIZE`: override shared memory size for postgres docker container You can clone an existing service to a new one: diff --git a/commands b/commands index 5a878fe..0b22b42 100755 --- a/commands +++ b/commands @@ -1,7 +1,7 @@ #!/usr/bin/env bash source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" [[ " help $PLUGIN_COMMAND_PREFIX:help $PLUGIN_COMMAND_PREFIX $PLUGIN_COMMAND_PREFIX:default " == *" $1 "* ]] || [[ "$1" == "$PLUGIN_COMMAND_PREFIX:"* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x diff --git a/common-functions b/common-functions index b42ac0d..10a4677 100755 --- a/common-functions +++ b/common-functions @@ -2,7 +2,7 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/property-functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" add_to_links_file() { @@ -349,6 +349,18 @@ service_commit_config() { if [[ -n "$PLUGIN_IMAGE_VERSION" ]]; then echo "$PLUGIN_IMAGE_VERSION" >"$SERVICE_ROOT/IMAGE_VERSION" fi + + if [[ -n "$SERVICE_INITIAL_NETWORK" ]]; then + fn-plugin-property-write "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "initial-network" "$SERVICE_INITIAL_NETWORK" + fi + + if [[ -n "$SERVICE_POST_CREATE_NETWORK" ]]; then + fn-plugin-property-write "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "post-create-network" "$SERVICE_POST_CREATE_NETWORK" + fi + + if [[ -n "$SERVICE_POST_START_NETWORK" ]]; then + fn-plugin-property-write "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "post-start-network" "$SERVICE_POST_START_NETWORK" + fi } service_backup_auth() { @@ -699,9 +711,12 @@ service_parse_args() { "--custom-env") set -- "$@" "-C" ;; "--database") set -- "$@" "-d" ;; "--image-version") set -- "$@" "-I" ;; + "--initial-network") set -- "$@" "-N" ;; "--image") set -- "$@" "-i" ;; "--memory") set -- "$@" "-m" ;; "--password") set -- "$@" "-p" ;; + "--post-create-network") set -- "$@" "-P" ;; + "--post-start-network") set -- "$@" "-S" ;; "--querystring") set -- "$@" "-q" ;; "--restart-apps") set -- "$@" "-R" ;; "--root-password") set -- "$@" "-r" ;; @@ -712,7 +727,7 @@ service_parse_args() { done OPTIND=1 - while getopts "a:c:C:d:i:I:m:p:q:R:r:s:u:" opt; do + while getopts "a:c:C:d:i:I:m:n:N:p:P:q:R:r:s:S:u:" opt; do case "$opt" in a) SERVICE_ALIAS="${OPTARG^^}" @@ -736,9 +751,15 @@ service_parse_args() { m) export SERVICE_MEMORY=$OPTARG ;; + N) + export SERVICE_INITIAL_NETWORK=$OPTARG + ;; p) export SERVICE_PASSWORD=$OPTARG ;; + P) + export SERVICE_POST_CREATE_NETWORK=$OPTARG + ;; q) export SERVICE_QUERYSTRING=${OPTARG#"?"} ;; @@ -751,6 +772,9 @@ service_parse_args() { s) export SERVICE_SHM_SIZE=$OPTARG ;; + S) + export SERVICE_POST_START_NETWORK=$OPTARG + ;; u) export SERVICE_USER=$OPTARG ;; diff --git a/functions b/functions index a38dffc..354447a 100755 --- a/functions +++ b/functions @@ -3,8 +3,8 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions" -source "$PLUGIN_BASE_PATH/common/functions" -source "$PLUGIN_BASE_PATH/common/property-functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" if [[ -f "$PLUGIN_AVAILABLE_PATH/docker-options/functions" ]]; then source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" @@ -133,7 +133,12 @@ service_create_container() { fi dokku_log_verbose_quiet "Waiting for container to be ready" - "$DOCKER_BIN" container run "${LINK_CONTAINER_DOCKER_ARGS[@]}" "$PLUGIN_WAIT_IMAGE" -c "$SERVICE_NAME:$PLUGIN_DATASTORE_WAIT_PORT" >/dev/null + if ! suppress_output "$DOCKER_BIN" container run "${LINK_CONTAINER_DOCKER_ARGS[@]}" "$PLUGIN_WAIT_IMAGE" -c "$SERVICE_NAME:$PLUGIN_DATASTORE_WAIT_PORT"; then + dokku_log_info2_quiet "Start of $SERVICE container output" + dokku_container_log_verbose_quiet "$SERVICE_NAME" + dokku_log_info2_quiet "End of $SERVICE container output" + return 1 + fi dokku_log_verbose_quiet "Creating container database" "$DOCKER_BIN" container exec "$SERVICE_NAME" su - postgres -c "createdb -E utf8 $DATABASE_NAME" 2>/dev/null || dokku_log_verbose_quiet 'Already exists' diff --git a/install b/install index 6b24efc..f8fc404 100755 --- a/install +++ b/install @@ -1,7 +1,7 @@ #!/usr/bin/env bash source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions" -source "$PLUGIN_BASE_PATH/common/property-functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x diff --git a/pre-delete b/pre-delete index 1f565d5..d315464 100755 --- a/pre-delete +++ b/pre-delete @@ -1,6 +1,5 @@ #!/usr/bin/env bash -source "$PLUGIN_BASE_PATH/common/functions" - +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/functions" set -eo pipefail diff --git a/subcommands/app-links b/subcommands/app-links index b6df3a1..6b0a0eb 100755 --- a/subcommands/app-links +++ b/subcommands/app-links @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-app-links-cmd() { diff --git a/subcommands/backup b/subcommands/backup index 161c191..354ed9b 100755 --- a/subcommands/backup +++ b/subcommands/backup @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-cmd() { diff --git a/subcommands/backup-auth b/subcommands/backup-auth index 992b295..050397b 100755 --- a/subcommands/backup-auth +++ b/subcommands/backup-auth @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-auth-cmd() { diff --git a/subcommands/backup-deauth b/subcommands/backup-deauth index d1d70cd..19cbe8a 100755 --- a/subcommands/backup-deauth +++ b/subcommands/backup-deauth @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-deauth-cmd() { diff --git a/subcommands/backup-schedule b/subcommands/backup-schedule index 448f930..594c748 100755 --- a/subcommands/backup-schedule +++ b/subcommands/backup-schedule @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-schedule-cmd() { diff --git a/subcommands/backup-schedule-cat b/subcommands/backup-schedule-cat index 0e3f2df..56a388a 100755 --- a/subcommands/backup-schedule-cat +++ b/subcommands/backup-schedule-cat @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-schedule-cat-cmd() { diff --git a/subcommands/backup-set-encryption b/subcommands/backup-set-encryption index 3ad29e5..27cb86e 100755 --- a/subcommands/backup-set-encryption +++ b/subcommands/backup-set-encryption @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-set-encryption-cmd() { diff --git a/subcommands/backup-unschedule b/subcommands/backup-unschedule index c3d3e31..874a22a 100755 --- a/subcommands/backup-unschedule +++ b/subcommands/backup-unschedule @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-unschedule-cmd() { diff --git a/subcommands/backup-unset-encryption b/subcommands/backup-unset-encryption index f783220..c046a55 100755 --- a/subcommands/backup-unset-encryption +++ b/subcommands/backup-unset-encryption @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-backup-unset-encryption-cmd() { diff --git a/subcommands/clone b/subcommands/clone index a7e2f64..eb10519 100755 --- a/subcommands/clone +++ b/subcommands/clone @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-clone-cmd() { @@ -15,8 +15,11 @@ service-clone-cmd() { #F -i|--image IMAGE, the image name to start the service with #F -I|--image-version IMAGE_VERSION, the image version to start the service with #F -m|--memory MEMORY, container memory limit in megabytes (default: unlimited) + #F -N|--initial-network INITIAL_NETWORK, the initial network to attach the service to #F -p|--password PASSWORD, override the user-level service password + #F -P|--post-create-network NETWORKS, a comman-separated list of networks to attach the service container to after service creation #F -r|--root-password PASSWORD, override the root-level service password + #F -S|--post-start-network NETWORKS, a comman-separated list of networks to attach the service container to after service start #F -s|--shm-size SHM_SIZE, override shared memory size for $PLUGIN_COMMAND_PREFIX docker container declare desc="create container then copy data from into " local cmd="$PLUGIN_COMMAND_PREFIX:clone" argv=("$@") diff --git a/subcommands/connect b/subcommands/connect index 37d05a8..ad6abca 100755 --- a/subcommands/connect +++ b/subcommands/connect @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-connect-cmd() { diff --git a/subcommands/create b/subcommands/create index 557b8b8..87135e5 100755 --- a/subcommands/create +++ b/subcommands/create @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-create-cmd() { @@ -23,8 +23,11 @@ service-create-cmd() { #F -i|--image IMAGE, the image name to start the service with #F -I|--image-version IMAGE_VERSION, the image version to start the service with #F -m|--memory MEMORY, container memory limit in megabytes (default: unlimited) + #F -N|--initial-network INITIAL_NETWORK, the initial network to attach the service to #F -p|--password PASSWORD, override the user-level service password + #F -P|--post-create-network NETWORKS, a comman-separated list of networks to attach the service container to after service creation #F -r|--root-password PASSWORD, override the root-level service password + #F -S|--post-start-network NETWORKS, a comman-separated list of networks to attach the service container to after service start #F -s|--shm-size SHM_SIZE, override shared memory size for $PLUGIN_COMMAND_PREFIX docker container declare desc="create a $PLUGIN_SERVICE service" local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@") diff --git a/subcommands/destroy b/subcommands/destroy index 1294b8a..cffe32d 100755 --- a/subcommands/destroy +++ b/subcommands/destroy @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-destroy-cmd() { @@ -49,6 +49,8 @@ service-destroy-cmd() { "$DOCKER_BIN" container run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/config" "$PLUGIN_BUSYBOX_IMAGE" chmod 777 -R /config /data rm -rf "$SERVICE_ROOT" + fn-plugin-property-destroy "$PLUGIN_COMMAND_PREFIX" "$SERVICE" + plugn trigger service-action post-delete "$PLUGIN_COMMAND_PREFIX" "$SERVICE" dokku_log_info2 "$PLUGIN_SERVICE container deleted: $SERVICE" } diff --git a/subcommands/enter b/subcommands/enter index 13f6a31..9062beb 100755 --- a/subcommands/enter +++ b/subcommands/enter @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-enter-cmd() { diff --git a/subcommands/exists b/subcommands/exists index ae59eee..6fd1bfc 100755 --- a/subcommands/exists +++ b/subcommands/exists @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-exists-cmd() { diff --git a/subcommands/export b/subcommands/export index 7e5bc69..d77dd47 100755 --- a/subcommands/export +++ b/subcommands/export @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-export-cmd() { diff --git a/subcommands/expose b/subcommands/expose index 57ead49..1e6b081 100755 --- a/subcommands/expose +++ b/subcommands/expose @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-expose-cmd() { diff --git a/subcommands/import b/subcommands/import index fd2b89f..441f415 100755 --- a/subcommands/import +++ b/subcommands/import @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-import-cmd() { diff --git a/subcommands/info b/subcommands/info index 9cba535..f9970d3 100755 --- a/subcommands/info +++ b/subcommands/info @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-info-cmd() { diff --git a/subcommands/link b/subcommands/link index 73c6291..01c3028 100755 --- a/subcommands/link +++ b/subcommands/link @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-link-cmd() { diff --git a/subcommands/linked b/subcommands/linked index 38cbc67..5d61d79 100755 --- a/subcommands/linked +++ b/subcommands/linked @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-linked-cmd() { diff --git a/subcommands/links b/subcommands/links index 9f3609b..35586aa 100755 --- a/subcommands/links +++ b/subcommands/links @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-links-cmd() { diff --git a/subcommands/list b/subcommands/list index cd4d52e..cebe31c 100755 --- a/subcommands/list +++ b/subcommands/list @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-list-cmd() { diff --git a/subcommands/logs b/subcommands/logs index 55f13ac..7f2e90e 100755 --- a/subcommands/logs +++ b/subcommands/logs @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-logs-cmd() { diff --git a/subcommands/pause b/subcommands/pause index acf43be..91d51fe 100755 --- a/subcommands/pause +++ b/subcommands/pause @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-pause-cmd() { diff --git a/subcommands/promote b/subcommands/promote index cbd5cda..ddf35ad 100755 --- a/subcommands/promote +++ b/subcommands/promote @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-promote-cmd() { diff --git a/subcommands/restart b/subcommands/restart index c7d11a0..9ff6b03 100755 --- a/subcommands/restart +++ b/subcommands/restart @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-restart-cmd() { diff --git a/subcommands/set b/subcommands/set index 260c918..0bcf474 100755 --- a/subcommands/set +++ b/subcommands/set @@ -2,8 +2,8 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" -source "$PLUGIN_BASE_PATH/common/property-functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions" source "$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" && pwd)/common-functions" service-set-cmd() { diff --git a/subcommands/start b/subcommands/start index 8416745..c928f3a 100755 --- a/subcommands/start +++ b/subcommands/start @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-start-cmd() { diff --git a/subcommands/stop b/subcommands/stop index b20c32d..9680ea5 100755 --- a/subcommands/stop +++ b/subcommands/stop @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-stop-cmd() { diff --git a/subcommands/unexpose b/subcommands/unexpose index 83e5239..a3e990a 100755 --- a/subcommands/unexpose +++ b/subcommands/unexpose @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-unexpose-cmd() { diff --git a/subcommands/unlink b/subcommands/unlink index b1e37d6..7819079 100755 --- a/subcommands/unlink +++ b/subcommands/unlink @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" service-unlink-cmd() { diff --git a/subcommands/upgrade b/subcommands/upgrade index 788c767..898b268 100755 --- a/subcommands/upgrade +++ b/subcommands/upgrade @@ -2,7 +2,7 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x -source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$PLUGIN_AVAILABLE_PATH/ps/functions" @@ -14,7 +14,10 @@ service-upgrade-cmd() { #F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with #F -i|--image IMAGE, the image name to start the service with #F -I|--image-version IMAGE_VERSION, the image version to start the service with + #F -N|--initial-network INITIAL_NETWORK, the initial network to attach the service to + #F -P|--post-create-network NETWORKS, a comman-separated list of networks to attach the service container to after service creation #F -R|--restart-apps "true", whether to force an app restart + #F -S|--post-start-network NETWORKS, a comman-separated list of networks to attach the service container to after service start #F -s|--shm-size SHM_SIZE, override shared memory size for $PLUGIN_COMMAND_PREFIX docker container declare desc="upgrade service to the specified versions" local cmd="$PLUGIN_COMMAND_PREFIX:upgrade" argv=("$@") diff --git a/tests/hook_pre_delete.bats b/tests/hook_pre_delete.bats index e849887..600b8b0 100755 --- a/tests/hook_pre_delete.bats +++ b/tests/hook_pre_delete.bats @@ -3,17 +3,18 @@ load test_helper setup() { dokku apps:create my-app - dokku "$PLUGIN_COMMAND_PREFIX:create" l - dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app >&2 + dokku "$PLUGIN_COMMAND_PREFIX:create" ls + dokku "$PLUGIN_COMMAND_PREFIX:link" ls my-app >&2 } teardown() { - dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app >&2 - dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l + dokku "$PLUGIN_COMMAND_PREFIX:unlink" ls my-app >&2 + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" ls + dokku --force apps:destroy my-app || true } @test "($PLUGIN_COMMAND_PREFIX:hook:pre-delete) removes app from links file when destroying app" { - [[ -n $(<"$PLUGIN_DATA_ROOT/l/LINKS") ]] + [[ -n $(<"$PLUGIN_DATA_ROOT/ls/LINKS") ]] dokku --force apps:destroy my-app - [[ -z $(<"$PLUGIN_DATA_ROOT/l/LINKS") ]] + [[ -z $(<"$PLUGIN_DATA_ROOT/ls/LINKS") ]] } diff --git a/tests/link_networks.bats b/tests/link_networks.bats new file mode 100755 index 0000000..6c1ffd8 --- /dev/null +++ b/tests/link_networks.bats @@ -0,0 +1,261 @@ +#!/usr/bin/env bats +load test_helper + +setup() { + dokku "$PLUGIN_COMMAND_PREFIX:create" ls + dokku network:create custom-network +} + +teardown() { + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" ls || true + dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" lsa || true + dokku network:destroy --force custom-network +} + +@test "($PLUGIN_COMMAND_PREFIX:set) set initial-network" { + run dokku "$PLUGIN_COMMAND_PREFIX:set" ls initial-network custom-network + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:info" ls --initial-network + echo "output: $output" + echo "status: $status" + assert_output "custom-network" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network 0 + + run dokku "$PLUGIN_COMMAND_PREFIX:stop" ls + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:start" ls + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge 0 + assert_output_contains custom-network + + run dokku "$PLUGIN_COMMAND_PREFIX:set" ls initial-network + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:info" ls --initial-network + echo "output: $output" + echo "status: $status" + assert_output "" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:stop" ls + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:start" ls + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network 0 +} + +@test "($PLUGIN_COMMAND_PREFIX:set) set post-create-network" { + run dokku "$PLUGIN_COMMAND_PREFIX:set" ls post-create-network custom-network + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:info" ls --post-create-network + echo "output: $output" + echo "status: $status" + assert_output "custom-network" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network 0 + + run dokku "$PLUGIN_COMMAND_PREFIX:stop" ls + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:start" ls + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains custom-network + assert_output_contains bridge + + run dokku "$PLUGIN_COMMAND_PREFIX:set" ls post-create-network + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:info" ls --post-create-network + echo "output: $output" + echo "status: $status" + assert_output "" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:stop" ls + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:start" ls + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network 0 +} + +@test "($PLUGIN_COMMAND_PREFIX:set) set an post-start-network" { + run dokku "$PLUGIN_COMMAND_PREFIX:set" ls post-start-network custom-network + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:info" ls --post-start-network + echo "output: $output" + echo "status: $status" + assert_output "custom-network" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network 0 + + run dokku "$PLUGIN_COMMAND_PREFIX:stop" ls + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:start" ls + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network + + run dokku "$PLUGIN_COMMAND_PREFIX:set" ls post-start-network + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:info" ls --post-start-network + echo "output: $output" + echo "status: $status" + assert_output "" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:stop" ls + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:start" ls + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect dokku.$PLUGIN_COMMAND_PREFIX.ls -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network 0 +} + +@test "($PLUGIN_COMMAND_PREFIX:create) flags" { + run dokku "$PLUGIN_COMMAND_PREFIX:create" lsa --initial-network custom-network + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect "dokku.$PLUGIN_COMMAND_PREFIX.lsa" -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge 0 + assert_output_contains custom-network + + run dokku "$PLUGIN_COMMAND_PREFIX:destroy" lsa --force + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:create" lsa --post-create-network custom-network + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect "dokku.$PLUGIN_COMMAND_PREFIX.lsa" -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network + + run dokku "$PLUGIN_COMMAND_PREFIX:destroy" lsa --force + echo "output: $output" + echo "status: $status" + assert_success + + run dokku "$PLUGIN_COMMAND_PREFIX:create" lsa --post-start-network custom-network + echo "output: $output" + echo "status: $status" + assert_success + + run docker inspect "dokku.$PLUGIN_COMMAND_PREFIX.lsa" -f '{{range $net,$v := .NetworkSettings.Networks}}{{printf "%s\n" $net}}{{end}}' + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains bridge + assert_output_contains custom-network + + run dokku "$PLUGIN_COMMAND_PREFIX:destroy" lsa --force + echo "output: $output" + echo "status: $status" + assert_success +} diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 8a0d1ee..fb397ab 100755 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -70,3 +70,17 @@ assert_output() { fi assert_equal "$expected" "$output" } + +# ShellCheck doesn't know about $output from Bats +# shellcheck disable=SC2154 +assert_output_contains() { + local input="$output" + local expected="$1" + local count="${2:-1}" + local found=0 + until [ "${input/$expected/}" = "$input" ]; do + input="${input/$expected/}" + found=$((found + 1)) + done + assert_equal "$count" "$found" +}