diff --git a/README.md b/README.md index 7a60252d..819f2a7d 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ dokku postgres:create [--create-flags...] flags: - `-c|--config-options "--args --go=here"`: extra arguments to pass to the container create command (default: `None`) +- `-c|--createdb-options "--locale=C"`: extra arguments to pass to the `createdb` command inside the container (default: `-E=UTF8`) - `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with - `-i|--image IMAGE`: the image name to start the service with - `-I|--image-version IMAGE_VERSION`: the image version to start the service with @@ -399,6 +400,7 @@ dokku postgres:upgrade [--upgrade-flags...] flags: - `-c|--config-options "--args --go=here"`: extra arguments to pass to the container create command (default: `None`) +- `-c|--createdb-options "--locale=C"`: extra arguments to pass to the `createdb` command inside the container (default: `-E=UTF8`) - `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with - `-i|--image IMAGE`: the image name to start the service with - `-I|--image-version IMAGE_VERSION`: the image version to start the service with @@ -469,6 +471,7 @@ dokku postgres:clone [--clone-flags...] flags: - `-c|--config-options "--args --go=here"`: extra arguments to pass to the container create command (default: `None`) +- `-c|--createdb-options "--locale=C"`: extra arguments to pass to the `createdb` command inside the container (default: `-E=UTF8`) - `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with - `-i|--image IMAGE`: the image name to start the service with - `-I|--image-version IMAGE_VERSION`: the image version to start the service with diff --git a/bin/generate b/bin/generate index 2e19392e..53b28e3b 100755 --- a/bin/generate +++ b/bin/generate @@ -302,6 +302,8 @@ def command_help(command, service, variable, alias, image, scheme, ports, option for flag in data["flags"]: if "--config-options" in flag and options != "": flag = f"{flag} (default: `{options}`)" + if "--createdb-options" in flag and options != "": + flag = f"{flag} (default: `-E=UTF8`)" content.append(f"- {flag}") if len(data["examples"]) > 0: diff --git a/common-functions b/common-functions index 5fe6a43e..8e7fd936 100755 --- a/common-functions +++ b/common-functions @@ -265,6 +265,10 @@ service_commit_config() { echo "" >"$SERVICE_ROOT/CONFIG_OPTIONS" fi + if [[ -n "$CREATEDB_OPTIONS" ]]; then + echo "$CREATEDB_OPTIONS" >"$SERVICE_ROOT/CREATEDB_OPTIONS" + fi + if [[ -n "$SERVICE_MEMORY" ]]; then echo "$SERVICE_MEMORY" >"$SERVICE_ROOT/SERVICE_MEMORY" fi @@ -452,6 +456,7 @@ service_info() { local flag_map=( "--config-dir: ${SERVICE_ROOT}/${PLUGIN_CONFIG_SUFFIX}" "--config-options: $(cat "$SERVICE_ROOT/CONFIG_OPTIONS")" + "--createdb-options: ${CREATEDB_OPTIONS}" "--data-dir: ${SERVICE_ROOT}/data" "--dsn: ${SERVICE_URL}" "--exposed-ports: $(service_exposed_ports "$SERVICE")" @@ -606,6 +611,7 @@ service_parse_args() { case "$arg" in "--alias") set -- "$@" "-a" ;; "--config-options") set -- "$@" "-c" ;; + "--createdb-options") set -- "$@" "-o" ;; "--custom-env") set -- "$@" "-C" ;; "--database") set -- "$@" "-d" ;; "--image-version") set -- "$@" "-I" ;; @@ -622,7 +628,7 @@ service_parse_args() { done OPTIND=1 - while getopts "a:c:C:d:i:I:m:p:q:R:r:s:u:" opt; do + while getopts "a:c:o:C:d:i:I:m:p:q:R:r:s:u:" opt; do case "$opt" in a) SERVICE_ALIAS="${OPTARG^^}" @@ -631,6 +637,9 @@ service_parse_args() { c) export PLUGIN_CONFIG_OPTIONS=$OPTARG ;; + o) + export CREATEDB_OPTIONS=$OPTARG + ;; C) export SERVICE_CUSTOM_ENV=$OPTARG ;; diff --git a/functions b/functions index d571f047..c85de3bc 100755 --- a/functions +++ b/functions @@ -73,6 +73,10 @@ service_create_container() { export CONFIG_OPTIONS="$(cat "$SERVICE_ROOT/CONFIG_OPTIONS")" fi + if [[ -f "$SERVICE_ROOT/CREATEDB_OPTIONS" ]]; then + export CREATEDB_OPTIONS="$(cat "$SERVICE_ROOT/CREATEDB_OPTIONS")" + fi + [[ -f "$SERVICE_ROOT/SERVICE_MEMORY" ]] && SERVICE_MEMORY="$(cat "$SERVICE_ROOT/SERVICE_MEMORY")" if [[ -n "$SERVICE_MEMORY" ]]; then MEMORY_LIMIT="--memory=${SERVICE_MEMORY}m" @@ -94,7 +98,7 @@ service_create_container() { docker run --rm --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" "$PLUGIN_WAIT_IMAGE" -p "$PLUGIN_DATASTORE_WAIT_PORT" >/dev/null dokku_log_verbose_quiet "Creating container database" - docker exec "$SERVICE_NAME" su - postgres -c "createdb -E utf8 $DATABASE_NAME" 2>/dev/null || dokku_log_verbose_quiet 'Already exists' + docker exec "$SERVICE_NAME" su - postgres -c "createdb -E=UTF8 $CREATEDB_OPTIONS $DATABASE_NAME" 2>/dev/null || dokku_log_verbose_quiet 'Already exists' dokku_log_verbose_quiet "Securing connection to database" service_stop "$SERVICE" >/dev/null diff --git a/subcommands/clone b/subcommands/clone index e4444787..b336a149 100755 --- a/subcommands/clone +++ b/subcommands/clone @@ -11,6 +11,7 @@ service-clone-cmd() { #A service, service to run command against #A new-service, name of new service #F -c|--config-options "--args --go=here", extra arguments to pass to the container create command + #F -c|--createdb-options "--locale=C", extra arguments to pass to the `createdb` command inside the container #F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with #F -i|--image IMAGE, the image name to start the service with #F -I|--image-version IMAGE_VERSION, the image version to start the service with diff --git a/subcommands/create b/subcommands/create index a2f5ef5a..4a49fea7 100755 --- a/subcommands/create +++ b/subcommands/create @@ -19,6 +19,7 @@ service-create-cmd() { #E dokku $PLUGIN_COMMAND_PREFIX:create lollipop #A service, service to run command against #F -c|--config-options "--args --go=here", extra arguments to pass to the container create command + #F -c|--createdb-options "--locale=C", extra arguments to pass to the `createdb` command inside the container #F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with #F -i|--image IMAGE, the image name to start the service with #F -I|--image-version IMAGE_VERSION, the image version to start the service with diff --git a/subcommands/upgrade b/subcommands/upgrade index 899f7e2d..6632de15 100755 --- a/subcommands/upgrade +++ b/subcommands/upgrade @@ -11,6 +11,7 @@ service-upgrade-cmd() { #E dokku $PLUGIN_COMMAND_PREFIX:upgrade lollipop #A service, service to run command against #F -c|--config-options "--args --go=here", extra arguments to pass to the container create command + #F -c|--createdb-options "--locale=C", extra arguments to pass to the `createdb` command inside the container #F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with #F -i|--image IMAGE, the image name to start the service with #F -I|--image-version IMAGE_VERSION, the image version to start the service with diff --git a/tests/service_info.bats b/tests/service_info.bats index 77ffb877..096ca0fe 100755 --- a/tests/service_info.bats +++ b/tests/service_info.bats @@ -41,6 +41,9 @@ teardown() { run dokku "$PLUGIN_COMMAND_PREFIX:info" l --config-dir assert_success + run dokku "$PLUGIN_COMMAND_PREFIX:info" l --createdb-options + assert_success + run dokku "$PLUGIN_COMMAND_PREFIX:info" l --data-dir assert_success