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:01 -04:00
parent f1d7100475
commit dd8a5a41f0
4 changed files with 14 additions and 1 deletions

View File

@@ -69,6 +69,7 @@ flags:
- `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with - `-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 IMAGE`: the image name to start the service with
- `-I|--image-version IMAGE_VERSION`: the image version 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 - `-p|--password PASSWORD`: override the user-level service password
- `-r|--root-password PASSWORD`: override the root-level service password - `-r|--root-password PASSWORD`: override the root-level service password
@@ -426,6 +427,7 @@ flags:
- `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with - `-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 IMAGE`: the image name to start the service with
- `-I|--image-version IMAGE_VERSION`: the image version 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 - `-p|--password PASSWORD`: override the user-level service password
- `-r|--root-password PASSWORD`: override the root-level service password - `-r|--root-password PASSWORD`: override the root-level service password

View File

@@ -75,6 +75,10 @@ service_create() {
echo "" >"$SERVICE_ROOT/MONGO_CONFIG_OPTIONS" echo "" >"$SERVICE_ROOT/MONGO_CONFIG_OPTIONS"
fi fi
if [[ -n "$SERVICE_MEMORY" ]]; then
echo "$SERVICE_MEMORY" >"$SERVICE_ROOT/SERVICE_MEMORY"
fi
write_database_name "$SERVICE" write_database_name "$SERVICE"
plugn trigger service-action post-create "$SERVICE" plugn trigger service-action post-create "$SERVICE"
service_create_container "$SERVICE" service_create_container "$SERVICE"
@@ -94,8 +98,13 @@ service_create_container() {
export MONGO_CONFIG_OPTIONS="$(cat "$SERVICE_ROOT/MONGO_CONFIG_OPTIONS")" export MONGO_CONFIG_OPTIONS="$(cat "$SERVICE_ROOT/MONGO_CONFIG_OPTIONS")"
fi fi
[[ -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 # shellcheck disable=SC2086
ID=$(docker run --name "$SERVICE_NAME" -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 $MONGO_CONFIG_OPTIONS) ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT -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 $MONGO_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

@@ -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 -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 IMAGE, the image name to start the service with
#F -I|--image-version IMAGE_VERSION, the image version 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 -p|--password PASSWORD, override the user-level service password
#F -r|--root-password PASSWORD, override the root-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>" 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 -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 IMAGE, the image name to start the service with
#F -I|--image-version IMAGE_VERSION, the image version 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 -p|--password PASSWORD, override the user-level service password
#F -r|--root-password PASSWORD, override the root-level service password #F -r|--root-password PASSWORD, override the root-level service password
declare desc="create a $PLUGIN_SERVICE service" declare desc="create a $PLUGIN_SERVICE service"