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 a42c69c765
commit a3a2183ec8
6 changed files with 91 additions and 7 deletions

View File

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

View File

@@ -1,7 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" 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" [[ " 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 set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x [[ $DOKKU_TRACE ]] && set -x

View File

@@ -3,7 +3,8 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
set -eo pipefail set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x [[ $DOKKU_TRACE ]] && set -x
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions" 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" source "$PLUGIN_AVAILABLE_PATH/config/functions"
if [[ -f "$PLUGIN_AVAILABLE_PATH/docker-options/functions" ]]; then if [[ -f "$PLUGIN_AVAILABLE_PATH/docker-options/functions" ]]; then
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions" source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
@@ -84,21 +85,42 @@ service_create_container() {
export CONFIG_OPTIONS="$(cat "$SERVICE_ROOT/CONFIG_OPTIONS")" export CONFIG_OPTIONS="$(cat "$SERVICE_ROOT/CONFIG_OPTIONS")"
fi fi
declare -a DOCKER_ARGS
DOCKER_ARGS=()
DOCKER_ARGS+=("--detach")
DOCKER_ARGS+=("--env-file=$SERVICE_ROOT/ENV")
DOCKER_ARGS+=("--env=MYSQL_DATABASE=$DATABASE_NAME")
DOCKER_ARGS+=("--env=MYSQL_PASSWORD=$PASSWORD")
DOCKER_ARGS+=("--env=MYSQL_ROOT_PASSWORD=$ROOTPASSWORD")
DOCKER_ARGS+=("--env=MYSQL_USER=mysql")
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:/etc/mysql/conf.d")
DOCKER_ARGS+=("--volume=$SERVICE_HOST_ROOT/data:/var/lib/mysql")
[[ -f "$SERVICE_ROOT/SERVICE_MEMORY" ]] && SERVICE_MEMORY="$(cat "$SERVICE_ROOT/SERVICE_MEMORY")" [[ -f "$SERVICE_ROOT/SERVICE_MEMORY" ]] && SERVICE_MEMORY="$(cat "$SERVICE_ROOT/SERVICE_MEMORY")"
if [[ -n "$SERVICE_MEMORY" ]]; then if [[ -n "$SERVICE_MEMORY" ]]; then
MEMORY_LIMIT="--memory=${SERVICE_MEMORY}m" DOCKER_ARGS+=("--memory=${SERVICE_MEMORY}m")
fi fi
[[ -f "$SERVICE_ROOT/SHM_SIZE" ]] && SERVICE_SHM_SIZE="$(cat "$SERVICE_ROOT/SHM_SIZE")" [[ -f "$SERVICE_ROOT/SHM_SIZE" ]] && SERVICE_SHM_SIZE="$(cat "$SERVICE_ROOT/SHM_SIZE")"
if [[ -n "$SERVICE_SHM_SIZE" ]]; then if [[ -n "$SERVICE_SHM_SIZE" ]]; then
SHM_SIZE="--shm-size=${SERVICE_SHM_SIZE}" DOCKER_ARGS+=("--shm-size=${SERVICE_SHM_SIZE}")
fi fi
[[ -f "$SERVICE_ROOT/IMAGE" ]] && PLUGIN_IMAGE="$(cat "$SERVICE_ROOT/IMAGE")" [[ -f "$SERVICE_ROOT/IMAGE" ]] && PLUGIN_IMAGE="$(cat "$SERVICE_ROOT/IMAGE")"
[[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && PLUGIN_IMAGE_VERSION="$(cat "$SERVICE_ROOT/IMAGE_VERSION")" [[ -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 # shellcheck disable=SC2086
ID=$("$DOCKER_BIN" container run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/var/lib/mysql" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/etc/mysql/conf.d" -e "MYSQL_ROOT_PASSWORD=$ROOTPASSWORD" -e MYSQL_USER=mysql -e "MYSQL_PASSWORD=$PASSWORD" -e "MYSQL_DATABASE=$DATABASE_NAME" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=mysql "$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" echo "$ID" >"$SERVICE_ROOT/ID"
dokku_log_verbose_quiet "Waiting for container to be ready" dokku_log_verbose_quiet "Waiting for container to be ready"

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env bash #!/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)/config"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/functions" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/functions"
set -eo pipefail 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
}