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 c29b6e4 commit ac2302d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
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
7 changes: 7 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,9 +26,14 @@ service_create() {
mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory"
touch "$LINKS_FILE"
PASSWORD=$(openssl rand -hex 32)
if [[ -n "$SERVICE_PASSWORD" ]]; then
PASSWORD="$SERVICE_PASSWORD"
dokku_log_warn "Specified password may not be as secure as the auto-generated password"
fi
echo "$PASSWORD" > "$SERVICE_ROOT/PASSWORD"
chmod 640 "$SERVICE_ROOT/PASSWORD"

[[ -n "$SERVICE_CUSTOM_ENV" ]] && COUCHDB_CUSTOM_ENV="$SERVICE_CUSTOM_ENV"
if [[ -n $COUCHDB_CUSTOM_ENV ]]; then
echo "$COUCHDB_CUSTOM_ENV" | tr ';' "\n" > "$SERVICE_ROOT/ENV"
else
Expand Down
2 changes: 1 addition & 1 deletion subcommands/clone
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ couchdb-clone-cmd() {
PLUGIN_IMAGE=$(service_version "$SERVICE" | grep -o "^.*:" | sed -r "s/://g")
PLUGIN_IMAGE_VERSION=$(service_version "$SERVICE" | grep -o ":.*$" | sed -r "s/://g")

service_create "$NEW_SERVICE"
service_create "$NEW_SERVICE" "${@:3}"
dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE"
service_export "$SERVICE" | service_import "$NEW_SERVICE" > /dev/null 2>&1 || true
dokku_log_info1 "Done"
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 @@ couchdb-create-cmd() {
local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"

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

couchdb-create-cmd "$@"

0 comments on commit ac2302d

Please sign in to comment.