feat: add the ability to constrain memory on service start/clone

Refs dokku/dokku-redis#86
This commit is contained in:
Jose Diaz-Gonzalez
2021-09-12 07:43:02 -04:00
parent 0657f47442
commit e85d96b3a1
4 changed files with 15 additions and 1 deletions

View File

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

View File

@@ -60,6 +60,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"
@@ -75,7 +79,13 @@ service_create_container() {
local DATABASE_NAME="$(get_database_name "$SERVICE")"
local PREVIOUS_ID
ID=$(docker run --name "$SERVICE_NAME" -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")
[[ -f "$SERVICE_ROOT/SERVICE_MEMORY" ]] && SERVICE_MEMORY="$(cat "$SERVICE_ROOT/SERVICE_MEMORY")"
if [[ -n "$SERVICE_MEMORY" ]]; then
MEMORY_LIMIT="--memory=${SERVICE_MEMORY}m"
fi
# shellcheck disable=SC2086
ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT -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")
echo "$ID" >"$SERVICE_ROOT/ID"
dokku_log_verbose_quiet "Waiting for container to be ready"

View File

@@ -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 <new-name> then copy data from <name> into <new-name>"

View File

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