Skip to content

Commit a2242c7

Browse files
committed
Allow to pass custom args to the createdb command
1 parent f1d60d6 commit a2242c7

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ dokku postgres:create <service> [--create-flags...]
6666
flags:
6767

6868
- `-c|--config-options "--args --go=here"`: extra arguments to pass to the container create command (default: `None`)
69+
- `-c|--createdb-options "--locale=C"`: extra arguments to pass to the `createdb` command inside the container (default: `-E=UTF8`)
6970
- `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with
7071
- `-i|--image IMAGE`: the image name to start the service with
7172
- `-I|--image-version IMAGE_VERSION`: the image version to start the service with

common-functions

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ service_commit_config() {
269269
echo "$SERVICE_MEMORY" >"$SERVICE_ROOT/SERVICE_MEMORY"
270270
fi
271271

272+
if [[ -n "$CREATEDB_OPTIONS" ]]; then
273+
echo "$CREATEDB_OPTIONS" >"$SERVICE_ROOT/CREATEDB_OPTIONS"
274+
fi
275+
272276
if [[ -n "$SERVICE_SHM_SIZE" ]]; then
273277
echo "$SERVICE_SHM_SIZE" >"$SERVICE_ROOT/SHM_SIZE"
274278
fi
@@ -452,6 +456,7 @@ service_info() {
452456
local flag_map=(
453457
"--config-dir: ${SERVICE_ROOT}/${PLUGIN_CONFIG_SUFFIX}"
454458
"--config-options: $(cat "$SERVICE_ROOT/CONFIG_OPTIONS")"
459+
"--createdb-options: $(cat "$SERVICE_ROOT/CREATEDB_OPTIONS")"
455460
"--data-dir: ${SERVICE_ROOT}/data"
456461
"--dsn: ${SERVICE_URL}"
457462
"--exposed-ports: $(service_exposed_ports "$SERVICE")"

functions

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ service_create_container() {
7373
export CONFIG_OPTIONS="$(cat "$SERVICE_ROOT/CONFIG_OPTIONS")"
7474
fi
7575

76+
if [[ -f "$SERVICE_ROOT/CREATEDB_OPTIONS" ]]; then
77+
export CREATEDB_OPTIONS="$(cat "$SERVICE_ROOT/CREATEDB_OPTIONS")"
78+
fi
79+
7680
[[ -f "$SERVICE_ROOT/SERVICE_MEMORY" ]] && SERVICE_MEMORY="$(cat "$SERVICE_ROOT/SERVICE_MEMORY")"
7781
if [[ -n "$SERVICE_MEMORY" ]]; then
7882
MEMORY_LIMIT="--memory=${SERVICE_MEMORY}m"
@@ -94,7 +98,7 @@ service_create_container() {
9498
docker run --rm --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" "$PLUGIN_WAIT_IMAGE" -p "$PLUGIN_DATASTORE_WAIT_PORT" >/dev/null
9599

96100
dokku_log_verbose_quiet "Creating container database"
97-
docker exec "$SERVICE_NAME" su - postgres -c "createdb -E utf8 $DATABASE_NAME" 2>/dev/null || dokku_log_verbose_quiet 'Already exists'
101+
docker exec "$SERVICE_NAME" su - postgres -c "createdb -E=UTF8 $CREATEDB_OPTIONS $DATABASE_NAME" 2>/dev/null || dokku_log_verbose_quiet 'Already exists'
98102

99103
dokku_log_verbose_quiet "Securing connection to database"
100104
service_stop "$SERVICE" >/dev/null

plugin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[plugin]
22
description = "dokku postgres service plugin"
3-
version = "1.14.1"
3+
version = "1.15.1"
44
[plugin.config]

subcommands/create

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ service-create-cmd() {
1919
#E dokku $PLUGIN_COMMAND_PREFIX:create lollipop
2020
#A service, service to run command against
2121
#F -c|--config-options "--args --go=here", extra arguments to pass to the container create command
22+
#F -c|--createdb-options "--locale=C ", extra arguments to pass to the createdb command inside the container
2223
#F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
2324
#F -i|--image IMAGE, the image name to start the service with
2425
#F -I|--image-version IMAGE_VERSION, the image version to start the service with

0 commit comments

Comments
 (0)