feat: add support for specifying an initial-network property
This network is the network that is associated with the container on creation. If specified, then the bridge network is not attached to the service. Only a single initial network can be specified at this time.
This commit is contained in:
20
README.md
20
README.md
@@ -45,6 +45,7 @@ mongo:logs <service> [-t|--tail] <tail-num-optional> # print the most recent log
|
||||
mongo:pause <service> # pause a running mongo service
|
||||
mongo:promote <service> <app> # promote service <service> as MONGO_URL in <app>
|
||||
mongo:restart <service> # graceful shutdown and restart of the mongo service container
|
||||
mongo:set <service> <key> <value> # set or clear a property for a service
|
||||
mongo:start <service> # start a previously stopped mongo service
|
||||
mongo:stop <service> # stop a running mongo service
|
||||
mongo:unexpose <service> # unexpose a previously exposed mongo service
|
||||
@@ -251,6 +252,25 @@ You can unlink a mongo service:
|
||||
dokku mongo:unlink lollipop playground
|
||||
```
|
||||
|
||||
### set or clear a property for a service
|
||||
|
||||
```shell
|
||||
# usage
|
||||
dokku mongo:set <service> <key> <value>
|
||||
```
|
||||
|
||||
Set the network to attach after the service container is started:
|
||||
|
||||
```shell
|
||||
dokku mongo:set lollipop post-create-network custom-network
|
||||
```
|
||||
|
||||
Unset the post-create-network value:
|
||||
|
||||
```shell
|
||||
dokku mongo:set lollipop post-create-network
|
||||
```
|
||||
|
||||
### Service Lifecycle
|
||||
|
||||
The lifecycle of each service can be managed through the following commands:
|
||||
|
||||
@@ -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(
|
||||
|
||||
3
commands
3
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
|
||||
|
||||
|
||||
26
functions
26
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"
|
||||
@@ -81,21 +82,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=MONGO_INITDB_DATABASE=$DATABASE_NAME")
|
||||
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:/data/db")
|
||||
|
||||
[[ -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:/data/db" --env-file="$SERVICE_ROOT/ENV" --env "MONGO_INITDB_DATABASE=$DATABASE_NAME" -d --restart always --label dokku=service --label dokku.service=mongo "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" mongod $CONFIG_OPTIONS)
|
||||
ID=$("$DOCKER_BIN" container run "${DOCKER_ARGS[@]}" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" mongod $CONFIG_OPTIONS)
|
||||
echo "$ID" >"$SERVICE_ROOT/ID"
|
||||
|
||||
dokku_log_verbose_quiet "Waiting for container to be ready"
|
||||
|
||||
@@ -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
|
||||
|
||||
40
subcommands/set
Executable file
40
subcommands/set
Executable file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user