From 4441a63d5cdf932aa4af9cab8fa2405252bd8634 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 12 Sep 2021 07:43:01 -0400 Subject: [PATCH] feat: add the ability to constrain memory on service start/clone Refs dokku/dokku-redis#86 --- README.md | 2 ++ functions | 11 ++++++++--- subcommands/clone | 1 + subcommands/create | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 61f9dba..6c39e69 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ flags: - `-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 +- `-m|--memory MEMORY`: container memory limit (default: unlimited) - `-p|--password PASSWORD`: override the user-level service password - `-r|--root-password PASSWORD`: override the root-level service password @@ -425,6 +426,7 @@ flags: - `-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 +- `-m|--memory MEMORY`: container memory limit (default: unlimited) - `-p|--password PASSWORD`: override the user-level service password - `-r|--root-password PASSWORD`: override the root-level service password diff --git a/functions b/functions index 68af7a8..2a72189 100755 --- a/functions +++ b/functions @@ -70,6 +70,10 @@ service_create() { echo "" >"$SERVICE_ROOT/ENV" fi + if [[ -n "$SERVICE_MEMORY" ]]; then + echo "$SERVICE_MEMORY" >"$SERVICE_ROOT/SERVICE_MEMORY" + fi + write_database_name "$SERVICE" plugn trigger service-action post-create "$SERVICE" service_create_container "$SERVICE" @@ -86,11 +90,12 @@ service_create_container() { local DATABASE_NAME="$(get_database_name "$SERVICE")" local MEMORY_LIMIT="" - if [[ ! -z "$SERVICE_MEMORY" ]]; then + if [[ -n "$SERVICE_MEMORY" ]]; then MEMORY_LIMIT="--memory=${SERVICE_MEMORY}m" fi - - ID=$(docker run --name "$SERVICE_NAME" "$MEMORY_LIMIT" -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") + + # shellcheck disable=SC2086 + ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT -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") echo "$ID" >"$SERVICE_ROOT/ID" dokku_log_verbose_quiet "Waiting for container to be ready" diff --git a/subcommands/clone b/subcommands/clone index 744e28a..647aa19 100755 --- a/subcommands/clone +++ b/subcommands/clone @@ -13,6 +13,7 @@ service-clone-cmd() { #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 + #F -m|--memory MEMORY, container memory limit (default: unlimited) #F -p|--password PASSWORD, override the user-level service password #F -r|--root-password PASSWORD, override the root-level service password declare desc="create container then copy data from into " diff --git a/subcommands/create b/subcommands/create index 6b7edac..62a4df9 100755 --- a/subcommands/create +++ b/subcommands/create @@ -21,6 +21,7 @@ service-create-cmd() { #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 + #F -m|--memory MEMORY, container memory limit (default: unlimited) #F -p|--password PASSWORD, override the user-level service password #F -r|--root-password PASSWORD, override the root-level service password declare desc="create a $PLUGIN_SERVICE service"