Add support for flags on the service:info command
This commit is contained in:
18
README.md
18
README.md
@@ -49,18 +49,12 @@ dokku mongo:create lolipop
|
|||||||
# official mongo image
|
# official mongo image
|
||||||
export MONGO_IMAGE="mongo"
|
export MONGO_IMAGE="mongo"
|
||||||
export MONGO_IMAGE_VERSION="3.0.5"
|
export MONGO_IMAGE_VERSION="3.0.5"
|
||||||
|
dokku mongo:create lolipop
|
||||||
# be sure to pull the specific Docker
|
|
||||||
# image you'd like to install if it
|
|
||||||
# differs from the default
|
|
||||||
docker pull mongo:3.0.5
|
|
||||||
|
|
||||||
# you can also specify custom environment
|
# you can also specify custom environment
|
||||||
# variables to start the mongo service
|
# variables to start the mongo service
|
||||||
# in semi-colon separated forma
|
# in semi-colon separated forma
|
||||||
export MONGO_CUSTOM_ENV="USER=alpha;HOST=beta"
|
export MONGO_CUSTOM_ENV="USER=alpha;HOST=beta"
|
||||||
|
|
||||||
# create a mongo service
|
|
||||||
dokku mongo:create lolipop
|
dokku mongo:create lolipop
|
||||||
|
|
||||||
# by default we use the wiredTiger storage solution
|
# by default we use the wiredTiger storage solution
|
||||||
@@ -71,10 +65,18 @@ export MONGO_CONFIG_OPTIONS=" --auth "
|
|||||||
export MONGO_IMAGE_VERSION="2.6.11"
|
export MONGO_IMAGE_VERSION="2.6.11"
|
||||||
dokku mongo:create lolipop
|
dokku mongo:create lolipop
|
||||||
|
|
||||||
|
|
||||||
# get connection information as follows
|
# get connection information as follows
|
||||||
dokku mongo:info lolipop
|
dokku mongo:info lolipop
|
||||||
|
|
||||||
|
# you can also retrieve a specific piece of service info via flags
|
||||||
|
dokku mongo:info lolipop --config-dir
|
||||||
|
dokku mongo:info lolipop --data-dir
|
||||||
|
dokku mongo:info lolipop --dsn
|
||||||
|
dokku mongo:info lolipop --exposed-ports
|
||||||
|
dokku mongo:info lolipop --links
|
||||||
|
dokku mongo:info lolipop --status
|
||||||
|
dokku mongo:info lolipop --version
|
||||||
|
|
||||||
# a mongo service can be linked to a
|
# a mongo service can be linked to a
|
||||||
# container this will use native docker
|
# container this will use native docker
|
||||||
# links via the docker-options plugin
|
# links via the docker-options plugin
|
||||||
|
|||||||
36
functions
36
functions
@@ -139,13 +139,37 @@ service_exposed_ports() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
service_info() {
|
service_info() {
|
||||||
local SERVICE="$1"
|
local SERVICE="$1" INFO_FLAG="$2"
|
||||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||||
local SERVICE_URL=$(service_url "$SERVICE")
|
local SERVICE_URL=$(service_url "$SERVICE")
|
||||||
|
local PORT_FILE="$SERVICE_ROOT/PORT"
|
||||||
|
local flag key valid_flags
|
||||||
|
|
||||||
echo " DSN: $SERVICE_URL"
|
local flag_map=(
|
||||||
echo " Config dir: $SERVICE_ROOT/config"
|
"--config-dir: ${SERVICE_ROOT}/config"
|
||||||
echo " Data dir: $SERVICE_ROOT/data"
|
"--data-dir: ${SERVICE_ROOT}/data"
|
||||||
|
"--dsn: ${SERVICE_URL}"
|
||||||
|
"--exposed-ports: $(service_exposed_ports "$SERVICE")"
|
||||||
|
"--links: $(service_linked_apps "$SERVICE")"
|
||||||
|
"--status: $(service_status "$SERVICE")"
|
||||||
|
"--version: $(service_version "$SERVICE")"
|
||||||
|
)
|
||||||
|
if [[ -z "$INFO_FLAG" ]]; then
|
||||||
|
dokku_log_info2 "Container Information"
|
||||||
|
for flag in "${flag_map[@]}"; do
|
||||||
|
key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')"
|
||||||
|
dokku_log_verbose "$(printf "%-20s %-25s" "${key^}" "${flag#*: }")"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
local match=false
|
||||||
|
for flag in "${flag_map[@]}"; do
|
||||||
|
valid_flags="${valid_flags} $(echo "$flag" | cut -d':' -f1)"
|
||||||
|
if [[ "$flag" == "${INFO_FLAG}:"* ]]; then
|
||||||
|
echo "${flag#*: }" && match=true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
service_link() {
|
service_link() {
|
||||||
@@ -387,7 +411,7 @@ service_create_container() {
|
|||||||
local SERVICE="$1"
|
local SERVICE="$1"
|
||||||
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
|
||||||
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
local SERVICE_NAME="$(get_service_name "$SERVICE")"
|
||||||
local ROOTPASSWORD=$(cat "$SERVICE_ROOT/ROOTPASSWORD")
|
local ROOTPASSWORD="$(cat "$SERVICE_ROOT/ROOTPASSWORD")"
|
||||||
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
|
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
@@ -442,7 +466,7 @@ service_start() {
|
|||||||
dokku_log_info1_quiet "Starting container"
|
dokku_log_info1_quiet "Starting container"
|
||||||
local PREVIOUS_ID=$(docker ps -f status=exited | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
|
local PREVIOUS_ID=$(docker ps -f status=exited | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
|
||||||
local IMAGE_EXISTS=$(docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " && true)
|
local IMAGE_EXISTS=$(docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " && true)
|
||||||
local ROOTPASSWORD=$(cat "$SERVICE_ROOT/ROOTPASSWORD")
|
local ROOTPASSWORD="$(cat "$SERVICE_ROOT/ROOTPASSWORD")"
|
||||||
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
|
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
|
||||||
|
|
||||||
if [[ -n $PREVIOUS_ID ]]; then
|
if [[ -n $PREVIOUS_ID ]]; then
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
|
|||||||
mongo-info-cmd() {
|
mongo-info-cmd() {
|
||||||
declare desc="print the connection information"
|
declare desc="print the connection information"
|
||||||
local cmd="$PLUGIN_COMMAND_PREFIX:info" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
|
local cmd="$PLUGIN_COMMAND_PREFIX:info" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
|
||||||
declare SERVICE="$1"
|
declare SERVICE="$1" INFO_FLAG="$2"
|
||||||
|
|
||||||
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
|
||||||
verify_service_name "$SERVICE"
|
verify_service_name "$SERVICE"
|
||||||
service_info "$SERVICE"
|
service_info "$SERVICE" "$INFO_FLAG"
|
||||||
}
|
}
|
||||||
|
|
||||||
mongo-info-cmd "$@"
|
mongo-info-cmd "$@"
|
||||||
|
|||||||
@@ -21,14 +21,46 @@ teardown() {
|
|||||||
|
|
||||||
@test "($PLUGIN_COMMAND_PREFIX:info) success" {
|
@test "($PLUGIN_COMMAND_PREFIX:info) success" {
|
||||||
run dokku "$PLUGIN_COMMAND_PREFIX:info" l
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l
|
||||||
password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
|
local password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
|
||||||
assert_contains "${lines[*]}" "DSN: mongodb://l:$password@dokku-mongo-l:27017/l"
|
assert_contains "${lines[*]}" "mongodb://l:$password@dokku-mongo-l:27017/l"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "($PLUGIN_COMMAND_PREFIX:info) replaces underscores by dash in hostname" {
|
@test "($PLUGIN_COMMAND_PREFIX:info) replaces underscores by dash in hostname" {
|
||||||
dokku "$PLUGIN_COMMAND_PREFIX:create" test_with_underscores
|
dokku "$PLUGIN_COMMAND_PREFIX:create" test_with_underscores
|
||||||
run dokku "$PLUGIN_COMMAND_PREFIX:info" test_with_underscores
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" test_with_underscores
|
||||||
password="$(cat "$PLUGIN_DATA_ROOT/test_with_underscores/PASSWORD")"
|
local password="$(cat "$PLUGIN_DATA_ROOT/test_with_underscores/PASSWORD")"
|
||||||
assert_contains "${lines[*]}" "DSN: mongodb://test_with_underscores:$password@dokku-mongo-test-with-underscores:27017/test_with_underscores"
|
assert_contains "${lines[*]}" "mongodb://test_with_underscores:$password@dokku-mongo-test-with-underscores:27017/test_with_underscores"
|
||||||
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" test_with_underscores
|
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" test_with_underscores
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "($PLUGIN_COMMAND_PREFIX:info) success with flag" {
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --dsn
|
||||||
|
local password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
|
||||||
|
assert_output "mongodb://l:$password@dokku-mongo-l:27017/l"
|
||||||
|
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --config-dir
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --data-dir
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --dsn
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --exposed-ports
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --links
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --status
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --version
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "($PLUGIN_COMMAND_PREFIX:info) error when invalid flag" {
|
||||||
|
run dokku "$PLUGIN_COMMAND_PREFIX:info" l --invalid-flag
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ assert_success() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_failure() {
|
||||||
|
if [[ "$status" -eq 0 ]]; then
|
||||||
|
flunk "expected failed exit status"
|
||||||
|
elif [[ "$#" -gt 0 ]]; then
|
||||||
|
assert_output "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
assert_exists() {
|
assert_exists() {
|
||||||
if [ ! -f "$1" ]; then
|
if [ ! -f "$1" ]; then
|
||||||
flunk "expected file to exist: $1"
|
flunk "expected file to exist: $1"
|
||||||
|
|||||||
Reference in New Issue
Block a user