Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass custom args to the createdb command #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 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 Expand Up @@ -399,6 +400,7 @@ dokku postgres:upgrade <service> [--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
Expand Down Expand Up @@ -469,6 +471,7 @@ dokku postgres:clone <service> <new-service> [--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
Expand Down
2 changes: 2 additions & 0 deletions bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")"
Expand Down Expand Up @@ -606,6 +611,7 @@ service_parse_args() {
case "$arg" in
"--alias") set -- "$@" "-a" ;;
"--config-options") set -- "$@" "-c" ;;
"--createdb-options") set -- "$@" "-o" ;;
timaschew marked this conversation as resolved.
Show resolved Hide resolved
"--custom-env") set -- "$@" "-C" ;;
"--database") set -- "$@" "-d" ;;
"--image-version") set -- "$@" "-I" ;;
Expand All @@ -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^^}"
Expand All @@ -631,6 +637,9 @@ service_parse_args() {
c)
export PLUGIN_CONFIG_OPTIONS=$OPTARG
;;
o)
export CREATEDB_OPTIONS=$OPTARG
;;
C)
export SERVICE_CUSTOM_ENV=$OPTARG
;;
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
timaschew marked this conversation as resolved.
Show resolved Hide resolved
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'
josegonzalez marked this conversation as resolved.
Show resolved Hide resolved

dokku_log_verbose_quiet "Securing connection to database"
service_stop "$SERVICE" >/dev/null
Expand Down
1 change: 1 addition & 0 deletions subcommands/clone
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
1 change: 1 addition & 0 deletions subcommands/upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/service_info.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down