Skip to content

Commit

Permalink
Allow to pass custom args to the createdb command
Browse files Browse the repository at this point in the history
  • Loading branch information
timaschew committed Oct 7, 2021
1 parent f1d60d6 commit a95fedc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dokku postgres:create <service> [--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
Expand Down
1 change: 1 addition & 0 deletions common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down
6 changes: 5 additions & 1 deletion functions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions subcommands/create
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a95fedc

Please sign in to comment.