diff --git a/README.md b/README.md index 21e927f..200c1a5 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ postgres:logs [-t|--tail] # print the most recent postgres:pause # pause a running postgres service postgres:promote # promote service as DATABASE_URL in postgres:restart # graceful shutdown and restart of the postgres service container +postgres:set # set or clear a property for a service postgres:start # start a previously stopped postgres service postgres:stop # stop a running postgres service postgres:unexpose # unexpose a previously exposed postgres service @@ -256,6 +257,25 @@ You can unlink a postgres service: dokku postgres:unlink lollipop playground ``` +### set or clear a property for a service + +```shell +# usage +dokku postgres:set +``` + +Set the network to attach after the service container is started: + +```shell +dokku postgres:set lollipop post-create-network custom-network +``` + +Unset the post-create-network value: + +```shell +dokku postgres:set lollipop post-create-network +``` + ### Service Lifecycle The lifecycle of each service can be managed through the following commands: diff --git a/bin/generate b/bin/generate index c5aa616..89b9999 100755 --- a/bin/generate +++ b/bin/generate @@ -131,7 +131,7 @@ def usage_section(service, variable, alias, image, scheme, ports, options, unimp def usage_intro(service, variable, alias, image, scheme, ports, options, unimplemented): - commands = ["create", "info", "list", "logs", "link", "unlink"] + commands = ["create", "info", "list", "logs", "link", "unlink", "set"] content = ["### Basic Usage"] return fetch_commands_content( diff --git a/commands b/commands index 2fb4cda..5a878fe 100755 --- a/commands +++ b/commands @@ -1,7 +1,8 @@ #!/usr/bin/env bash source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" [[ " help $PLUGIN_COMMAND_PREFIX:help $PLUGIN_COMMAND_PREFIX $PLUGIN_COMMAND_PREFIX:default " == *" $1 "* ]] || [[ "$1" == "$PLUGIN_COMMAND_PREFIX:"* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_BASE_PATH/common/functions" + set -eo pipefail [[ $DOKKU_TRACE ]] && set -x diff --git a/functions b/functions index eeb22e4..3df1079 100755 --- a/functions +++ b/functions @@ -3,7 +3,8 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions" -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_BASE_PATH/common/property-functions" source "$PLUGIN_AVAILABLE_PATH/config/functions" if [[ -f "$PLUGIN_AVAILABLE_PATH/docker-options/functions" ]]; then source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" @@ -73,21 +74,38 @@ service_create_container() { export CONFIG_OPTIONS="$(cat "$SERVICE_ROOT/CONFIG_OPTIONS")" fi + declare -a DOCKER_ARGS + DOCKER_ARGS=() + DOCKER_ARGS+=("--detach") + DOCKER_ARGS+=("--env-file=$SERVICE_ROOT/ENV") + DOCKER_ARGS+=("--env=POSTGRES_PASSWORD=$PASSWORD") + DOCKER_ARGS+=("--hostname=$SERVICE") + DOCKER_ARGS+=("--label=dokku.service=$PLUGIN_COMMAND_PREFIX") + DOCKER_ARGS+=("--label=dokku=service") + DOCKER_ARGS+=("--name=$SERVICE_NAME") + DOCKER_ARGS+=("--restart=always") + DOCKER_ARGS+=("--volume=$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data") + [[ -f "$SERVICE_ROOT/SERVICE_MEMORY" ]] && SERVICE_MEMORY="$(cat "$SERVICE_ROOT/SERVICE_MEMORY")" if [[ -n "$SERVICE_MEMORY" ]]; then - MEMORY_LIMIT="--memory=${SERVICE_MEMORY}m" + DOCKER_ARGS+=("--memory=${SERVICE_MEMORY}m") fi [[ -f "$SERVICE_ROOT/SHM_SIZE" ]] && SERVICE_SHM_SIZE="$(cat "$SERVICE_ROOT/SHM_SIZE")" if [[ -n "$SERVICE_SHM_SIZE" ]]; then - SHM_SIZE="--shm-size=${SERVICE_SHM_SIZE}" + DOCKER_ARGS+=("--shm-size=${SERVICE_SHM_SIZE}") fi [[ -f "$SERVICE_ROOT/IMAGE" ]] && PLUGIN_IMAGE="$(cat "$SERVICE_ROOT/IMAGE")" [[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && PLUGIN_IMAGE_VERSION="$(cat "$SERVICE_ROOT/IMAGE_VERSION")" + local network="$(fn-plugin-property-get "$PLUGIN_COMMAND_PREFIX" "$SERVICE" "initial-network")" + if [[ -n "$network" ]]; then + DOCKER_ARGS+=("--network=${network}") + fi + # shellcheck disable=SC2086 - ID=$("$DOCKER_BIN" container run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/var/lib/postgresql/data" -e "POSTGRES_PASSWORD=$PASSWORD" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=postgres "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS) + ID=$("$DOCKER_BIN" container run "${DOCKER_ARGS[@]}" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS) echo "$ID" >"$SERVICE_ROOT/ID" dokku_log_verbose_quiet "Waiting for container to be ready" diff --git a/pre-delete b/pre-delete index d315464..1f565d5 100755 --- a/pre-delete +++ b/pre-delete @@ -1,5 +1,6 @@ #!/usr/bin/env bash -source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_BASE_PATH/common/functions" + source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/functions" set -eo pipefail diff --git a/subcommands/set b/subcommands/set new file mode 100755 index 0000000..823497b --- /dev/null +++ b/subcommands/set @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_BASE_PATH/common/functions" +source "$PLUGIN_BASE_PATH/common/property-functions" + +service-set-cmd() { + #E set the network to attach after the service container is started + #E dokku $PLUGIN_COMMAND_PREFIX:set lollipop post-create-network custom-network + #E unset the post-create-network value + #E dokku $PLUGIN_COMMAND_PREFIX:set lollipop post-create-network + #A service, service to run command against + #A key, property name to set + #A value, optional property value to set or empty to unset key + declare desc="set or clear a property for a service" + local cmd="$PLUGIN_COMMAND_PREFIX:set" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" KEY="$2" VALUE="$3" + local VALID_KEYS=("post-create-network" "post-start-network" "initial-network") + verify_service_name "$SERVICE" + + [[ -z "$KEY" ]] && dokku_log_fail "No key specified" + + if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then + dokku_log_fail "Invalid key specified, valid keys include: network" + fi + + if [[ -n "$VALUE" ]]; then + dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}" + fn-plugin-property-write "PLUGIN_COMMAND_PREFIX" "$SERVICE" "$KEY" "$VALUE" + else + dokku_log_info2_quiet "Unsetting ${KEY}" + if [[ "$KEY" == "rev-env-var" ]]; then + fn-plugin-property-write "PLUGIN_COMMAND_PREFIX" "$SERVICE" "$KEY" "$VALUE" + else + fn-plugin-property-delete "PLUGIN_COMMAND_PREFIX" "$SERVICE" "$KEY" + fi + fi +}