feat: add ability to specify custom flags on clone/create

Refs dokku/dokku-redis#64
This commit is contained in:
Jose Diaz-Gonzalez
2017-08-26 18:10:21 -04:00
parent 3c8439c256
commit e7802ca80e
4 changed files with 64 additions and 4 deletions

View File

@@ -339,6 +339,59 @@ service_logs() {
docker logs $DOKKU_LOGS_ARGS "$ID" 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() { service_port_expose() {
declare desc="Wrapper for exposing service ports" declare desc="Wrapper for exposing service ports"
declare SERVICE="$1" declare SERVICE="$1"

View File

@@ -15,6 +15,8 @@ service_create() {
[[ ! -d "$PLUGIN_DATA_ROOT/$SERVICE" ]] || dokku_log_fail "$PLUGIN_SERVICE service $SERVICE already exists" [[ ! -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_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 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" docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"
fi fi
@@ -22,10 +24,15 @@ service_create() {
mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory" 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/data" || dokku_log_fail "Unable to create service data directory"
touch "$LINKS_FILE" touch "$LINKS_FILE"
password=$(openssl rand -hex 16) PASSWORD=$(openssl rand -hex 16)
echo "$password" > "$SERVICE_ROOT/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" chmod 640 "$SERVICE_ROOT/PASSWORD"
[[ -n "$SERVICE_CUSTOM_ENV" ]] && POSTGRES_CUSTOM_ENV="$SERVICE_CUSTOM_ENV"
if [[ -n $POSTGRES_CUSTOM_ENV ]]; then if [[ -n $POSTGRES_CUSTOM_ENV ]]; then
echo "$POSTGRES_CUSTOM_ENV" | tr ';' "\n" > "$SERVICE_ROOT/ENV" echo "$POSTGRES_CUSTOM_ENV" | tr ';' "\n" > "$SERVICE_ROOT/ENV"
else else

View File

@@ -17,7 +17,7 @@ postgres-clone-cmd() {
PLUGIN_IMAGE=$(service_version "$SERVICE" | grep -o "^.*:" | sed -r "s/://g") PLUGIN_IMAGE=$(service_version "$SERVICE" | grep -o "^.*:" | sed -r "s/://g")
PLUGIN_IMAGE_VERSION=$(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" dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE"
service_export "$SERVICE" | service_import "$NEW_SERVICE" > /dev/null 2>&1 || true service_export "$SERVICE" | service_import "$NEW_SERVICE" > /dev/null 2>&1 || true
dokku_log_info1 "Done" dokku_log_info1 "Done"

View File

@@ -9,7 +9,7 @@ postgres-create-cmd() {
local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" declare SERVICE="$1"
service_create "$SERVICE" service_create "$SERVICE" "${@:2}"
} }
postgres-create-cmd "$@" postgres-create-cmd "$@"