Skip to content

Commit

Permalink
feat: add ability to specify custom flags on clone/create
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez committed Aug 26, 2017
1 parent 1c69b65 commit 6c191ec
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
53 changes: 53 additions & 0 deletions common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,59 @@ service_logs() {
docker logs $DOKKU_LOGS_ARGS "$ID"
}

service_parse_args() {
declare desc="cli arg parser"
local next_index=1; local skip=false; local args=("$@")

for arg in "$@"; do
shift
case "$arg" in
"--config-options") set -- "$@" "-c" ;;
"--custom-env") set -- "$@" "-C" ;;
"--image") set -- "$@" "-i" ;;
"--image-version") set -- "$@" "-I" ;;
"--password") set -- "$@" "-p" ;;
"--root-password") set -- "$@" "-r" ;;

"--alias") set -- "$@" "-a" ;;
"--database") set -- "$@" "-d" ;;
"--memory") set -- "$@" "-m" ;;
"--querystring") set -- "$@" "-q" ;;
"--user") set -- "$@" "-u" ;;
*) set -- "$@" "$arg"
esac
done

OPTIND=1
while getopts "a:c:C:d:i:I:m:p:q:r:u:" opt; do
case "$opt" in
a) export SERVICE_ALIAS=$OPTARG
;;
c) export PLUGIN_CONFIG_OPTIONS=$OPTARG
;;
C) export SERVICE_CUSTOM_ENV=$OPTARG
;;
d) export SERVICE_DATABASE=$OPTARG
;;
i) export PLUGIN_IMAGE=$OPTARG
;;
I) export PLUGIN_IMAGE_VERSION=$OPTARG
;;
m) export SERVICE_MEMORY=$OPTARG
;;
p) export SERVICE_PASSWORD=$OPTARG
;;
q) export SERVICE_QUERYSTRING=$OPTARG
;;
r) export SERVICE_ROOT_PASSWORD=$OPTARG
;;
u) export SERVICE_USER=$OPTARG
;;
esac
done
shift "$(( OPTIND - 1 ))" # remove options from positional parameters
}

service_port_expose() {
declare desc="Wrapper for exposing service ports"
declare SERVICE="$1"
Expand Down
3 changes: 3 additions & 0 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ service_create() {
[[ ! -d "$PLUGIN_DATA_ROOT/$SERVICE" ]] || dokku_log_fail "$PLUGIN_SERVICE service $SERVICE already exists"
SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS"

service_parse_args "${@:2}"

if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then
docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"
fi
Expand All @@ -24,6 +26,7 @@ service_create() {
mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory"
touch "$LINKS_FILE"

[[ -n "$SERVICE_CUSTOM_ENV" ]] && ELASTICSEARCH_CUSTOM_ENV="$SERVICE_CUSTOM_ENV"
if [[ -n $ELASTICSEARCH_CUSTOM_ENV ]]; then
echo "$ELASTICSEARCH_CUSTOM_ENV" | tr ';' "\n" > "$SERVICE_ROOT/ENV"
else
Expand Down
2 changes: 1 addition & 1 deletion subcommands/create
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ elasticsearch-create-cmd() {
local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"

service_create "$SERVICE"
service_create "$SERVICE" "${@:2}"
}

elasticsearch-create-cmd "$@"

0 comments on commit 6c191ec

Please sign in to comment.