From a95fedcd045c52658ad5d883e44b8ec22e93f38e Mon Sep 17 00:00:00 2001 From: Timaschew Date: Thu, 7 Oct 2021 12:29:17 +0200 Subject: [PATCH] Allow to pass custom args to the createdb command --- README.md | 1 + common-functions | 1 + functions | 6 +++++- subcommands/create | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a60252..1b76e3e 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 diff --git a/common-functions b/common-functions index 5fe6a43..532a85a 100755 --- a/common-functions +++ b/common-functions @@ -452,6 +452,7 @@ service_info() { local flag_map=( "--config-dir: ${SERVICE_ROOT}/${PLUGIN_CONFIG_SUFFIX}" "--config-options: $(cat "$SERVICE_ROOT/CONFIG_OPTIONS")" + "--createdb-options: $(cat "$SERVICE_ROOT/CREATEDB_OPTIONS")" "--data-dir: ${SERVICE_ROOT}/data" "--dsn: ${SERVICE_URL}" "--exposed-ports: $(service_exposed_ports "$SERVICE")" diff --git a/functions b/functions index d571f04..c85de3b 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/create b/subcommands/create index a2f5ef5..bac002c 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