From 606352b6ed6bab0a24123d11b074b88dcbd7756a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 25 Aug 2015 23:00:49 -0400 Subject: [PATCH] Add the ability to retrieve container ids by container type You can now use the following to narrow down the search for a container id: get_app_container_ids app web get_app_container_ids app worker You can also specify a specific type "id" like so: get_app_container_ids app web.1 get_app_container_ids app worker.3 Specifying an invalid type or id will result in an empty response --- plugins/common/functions | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/common/functions b/plugins/common/functions index 66d787b05..0b186dff1 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -179,12 +179,22 @@ copy_from_image() { } get_app_container_ids() { - APP="$1" + APP="$1"; CONTAINER_TYPE="$2" verify_app_name $APP [[ -f $DOKKU_ROOT/$APP/CONTAINER ]] && DOKKU_CIDS+=$(< $DOKKU_ROOT/$APP/CONTAINER) + if [[ -n "$CONTAINER_TYPE" ]]; then + CONTAINER_PATTERN=$DOKKU_ROOT/$APP/CONTAINER.$CONTAINER_TYPE.* + if [[ $CONTAINER_TYPE == *.* ]]; then + CONTAINER_PATTERN=$DOKKU_ROOT/$APP/CONTAINER.$CONTAINER_TYPE + [[ ! -f $CONTAINER_PATTERN ]] && echo "" && return 0 + fi + else + CONTAINER_PATTERN=$DOKKU_ROOT/$APP/CONTAINER.* + fi + shopt -s nullglob - for DOKKU_CID_FILE in $DOKKU_ROOT/$APP/CONTAINER.*; do + for DOKKU_CID_FILE in $CONTAINER_PATTERN; do DOKKU_CIDS+=" " DOKKU_CIDS+=$(< $DOKKU_CID_FILE) DOKKU_CIDS+=" "