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:
Jose Diaz-Gonzalez
2023-02-07 14:31:11 -05:00
parent fbc5380a12
commit b6ccd491fd
6 changed files with 87 additions and 7 deletions

View File

@@ -44,6 +44,7 @@ redis:logs <service> [-t|--tail] <tail-num-optional> # print the most recent log
redis:pause <service> # pause a running redis service
redis:promote <service> <app> # promote service <service> as REDIS_URL in <app>
redis:restart <service> # graceful shutdown and restart of the redis service container
redis:set <service> <key> <value> # set or clear a property for a service
redis:start <service> # start a previously stopped redis service
redis:stop <service> # stop a running redis service
redis:unexpose <service> # unexpose a previously exposed redis service
@@ -250,6 +251,25 @@ You can unlink a redis service:
dokku redis:unlink lollipop playground
```
### set or clear a property for a service
```shell
# usage
dokku redis:set <service> <key> <value>
```
Set the network to attach after the service container is started:
```shell
dokku redis:set lollipop post-create-network custom-network
```
Unset the post-create-network value:
```shell
dokku redis:set lollipop post-create-network
```
### Service Lifecycle
The lifecycle of each service can be managed through the following commands:

View File

@@ -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(

View File

@@ -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

View File

@@ -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"
@@ -77,21 +78,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+=("--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/$PLUGIN_CONFIG_SUFFIX:/usr/local/etc/redis")
DOCKER_ARGS+=("--volume=$SERVICE_HOST_ROOT/data:/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:/data" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/usr/local/etc/redis" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=redis "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" redis-server /usr/local/etc/redis/redis.conf --bind 0.0.0.0 $CONFIG_OPTIONS)
ID=$("$DOCKER_BIN" container run "${DOCKER_ARGS[@]}" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" redis-server /usr/local/etc/redis/redis.conf --bind 0.0.0.0 $CONFIG_OPTIONS)
echo "$ID" >"$SERVICE_ROOT/ID"
dokku_log_verbose_quiet "Waiting for container to be ready"

View File

@@ -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
View 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
}