From d57adde26c08b6ffe44643078bce5545cfec0fc4 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 25 Sep 2016 04:06:57 -0600 Subject: [PATCH 1/4] Use PLUGIN_IMAGE_VERSION for env var --- functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions b/functions index b02edb4..649369b 100755 --- a/functions +++ b/functions @@ -22,7 +22,7 @@ service_create() { mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory" mkdir -p "$SERVICE_ROOT/data" || dokku_log_fail "Unable to create service data directory" mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory" - curl -sSL "https://raw.githubusercontent.com/antirez/redis/${REDIS_IMAGE_VERSION:0:3}/redis.conf" > "$SERVICE_ROOT/config/redis.conf" || dokku_log_fail "Unable to download the default redis.conf to the config directory" + curl -sSL "https://raw.githubusercontent.com/antirez/redis/${PLUGIN_IMAGE_VERSION:0:3}/redis.conf" > "$SERVICE_ROOT/config/redis.conf" || dokku_log_fail "Unable to download the default redis.conf to the config directory" PASSWORD=$(openssl rand -hex 32) echo "$PASSWORD" > "$SERVICE_ROOT/PASSWORD" chmod 640 "$SERVICE_ROOT/PASSWORD" From 0a1a0b9a47ae575bb3c8db0d6e4de4dedf847e04 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 25 Sep 2016 04:43:13 -0600 Subject: [PATCH 2/4] Add argument parser to common-functions --- common-functions | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/common-functions b/common-functions index 0674f7b..ad0cb04 100755 --- a/common-functions +++ b/common-functions @@ -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" From d4c9a4044ffdcc24ba54cc3efdfb820a4289c7a9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 25 Sep 2016 15:04:51 -0600 Subject: [PATCH 3/4] Parse arguments in service_create calls Refs #64 --- functions | 4 ++++ subcommands/clone | 2 +- subcommands/create | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 649369b..e095d00 100755 --- a/functions +++ b/functions @@ -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 @@ -24,11 +26,13 @@ service_create() { mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory" curl -sSL "https://raw.githubusercontent.com/antirez/redis/${PLUGIN_IMAGE_VERSION:0:3}/redis.conf" > "$SERVICE_ROOT/config/redis.conf" || dokku_log_fail "Unable to download the default redis.conf to the config directory" PASSWORD=$(openssl rand -hex 32) + [[ -n "$SERVICE_PASSWORD" ]] && PASSWORD="$SERVICE_PASSWORD" echo "$PASSWORD" > "$SERVICE_ROOT/PASSWORD" chmod 640 "$SERVICE_ROOT/PASSWORD" sed -i.bak "s/# requirepass.*/requirepass ${PASSWORD}/" "$SERVICE_ROOT/config/redis.conf" && rm "$SERVICE_ROOT/config/redis.conf.bak" touch "$LINKS_FILE" + [[ -n "$SERVICE_CUSTOM_ENV" ]] && REDIS_CUSTOM_ENV="$SERVICE_CUSTOM_ENV" if [[ -n $REDIS_CUSTOM_ENV ]]; then echo "$REDIS_CUSTOM_ENV" | tr ';' "\n" > "$SERVICE_ROOT/ENV" else diff --git a/subcommands/clone b/subcommands/clone index a26b042..94e912e 100755 --- a/subcommands/clone +++ b/subcommands/clone @@ -17,7 +17,7 @@ redis-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" diff --git a/subcommands/create b/subcommands/create index 1082e39..efbd1a0 100755 --- a/subcommands/create +++ b/subcommands/create @@ -9,7 +9,7 @@ redis-create-cmd() { local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 declare SERVICE="$1" - service_create "$SERVICE" + service_create "$SERVICE" "${@:2}" } redis-create-cmd "$@" From b2066c32c0bb7888cc5def3d85abaf472c907f9f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 26 Aug 2017 05:49:56 -0400 Subject: [PATCH 4/4] fix: warn that a specified password may not be as secure as the autogenerated one --- functions | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions b/functions index e095d00..0802e93 100755 --- a/functions +++ b/functions @@ -26,7 +26,10 @@ service_create() { mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory" curl -sSL "https://raw.githubusercontent.com/antirez/redis/${PLUGIN_IMAGE_VERSION:0:3}/redis.conf" > "$SERVICE_ROOT/config/redis.conf" || dokku_log_fail "Unable to download the default redis.conf to the config directory" PASSWORD=$(openssl rand -hex 32) - [[ -n "$SERVICE_PASSWORD" ]] && PASSWORD="$SERVICE_PASSWORD" + 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" sed -i.bak "s/# requirepass.*/requirepass ${PASSWORD}/" "$SERVICE_ROOT/config/redis.conf" && rm "$SERVICE_ROOT/config/redis.conf.bak"