From ceac86b58fae50fe4fc55188e1acc05ab05e12d8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 17 May 2019 11:58:53 -0400 Subject: [PATCH 1/5] fix: correct issue where resource setting was overriding pre-existing values --- plugins/resource/subcommands.go | 5 +++-- tests/unit/20_resource.bats | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/resource/subcommands.go b/plugins/resource/subcommands.go index e3a8f68b6..b607a4609 100644 --- a/plugins/resource/subcommands.go +++ b/plugins/resource/subcommands.go @@ -121,10 +121,11 @@ func setResourceType(appName string, processType string, r Resource, resourceTyp common.LogInfo2Quiet(message) for key, value := range resources { - if value != "" { - common.LogVerbose(fmt.Sprintf("%v: %v", key, value)) + if value == "" { + continue } + common.LogVerbose(fmt.Sprintf("%v: %v", key, value)) property := propertyKey(processType, resourceType, key) err := common.PropertyWrite("resource", appName, property, value) if err != nil { diff --git a/tests/unit/20_resource.bats b/tests/unit/20_resource.bats index a8f92cc89..0ee9bef0a 100644 --- a/tests/unit/20_resource.bats +++ b/tests/unit/20_resource.bats @@ -116,6 +116,11 @@ teardown() { echo "status: $status" assert_success + run /bin/bash -c "dokku resource:reserve --cpu 1.5 --process-type worker $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + dokku ps:rebuild "$TEST_APP" CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" From 2aac9c71fc504760103d76a9403248b91aa284ac Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 17 May 2019 11:59:15 -0400 Subject: [PATCH 2/5] fix: cpu flag becomes cpus for the docker-scheduler --- .../docker-args-process-deploy/docker-args-process-deploy.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/resource/src/triggers/docker-args-process-deploy/docker-args-process-deploy.go b/plugins/resource/src/triggers/docker-args-process-deploy/docker-args-process-deploy.go index 76dec47e6..0b5636a5f 100644 --- a/plugins/resource/src/triggers/docker-args-process-deploy/docker-args-process-deploy.go +++ b/plugins/resource/src/triggers/docker-args-process-deploy/docker-args-process-deploy.go @@ -50,6 +50,10 @@ func main() { continue } + if parts[1] == "cpu" { + parts[1] = "cpus" + } + limits[parts[1]] = value } if parts[0] == "reserve" { From a92687d3e8f2c7985e8eb559fc30791919906174 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 17 May 2019 12:00:05 -0400 Subject: [PATCH 3/5] fix: correct calls to fetch process-specific build and deploy args --- docs/development/plugin-triggers.md | 20 +++++++++++++++++++- plugins/app-json/internal-functions | 2 +- plugins/common/functions | 4 ++-- plugins/scheduler-docker-local/scheduler-run | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 11a2c0c63..a7e52baf7 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -311,6 +311,24 @@ verify_app_name "$APP" # TODO ``` +### `docker-args-process-build` + +- Description: `$PROC_TYPE` may be set to magic `_all_` process type to signify global docker deploy options. +- Invoked by: `dokku ps:rebuild` +- Arguments: `$APP $IMAGE_TAG $IMAGE_SOURCE_TYPE` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) +verify_app_name "$APP" + +# TODO +``` + ### `docker-args-process-deploy` - Description: `$PROC_TYPE` may be set to magic `_all_` process type to signify global docker deploy options. @@ -333,7 +351,7 @@ verify_app_name "$APP" - Description: `$PROC_TYPE` may be set to magic `_all_` process type to signify global docker run options. - Invoked by: `dokku run` -- Arguments: `$APP $IMAGE_TAG $IMAGE_SOURCE_TYPE [$PROC_TYPE $CONTAINER_INDEX]` +- Arguments: `$APP $IMAGE_TAG $IMAGE_SOURCE_TYPE` - Example: ```shell diff --git a/plugins/app-json/internal-functions b/plugins/app-json/internal-functions index 46feb92d1..1d2dc2341 100755 --- a/plugins/app-json/internal-functions +++ b/plugins/app-json/internal-functions @@ -85,7 +85,7 @@ execute_script() { local IMAGE_SOURCE_TYPE="dockerfile" is_image_herokuish_based "$IMAGE" && IMAGE_SOURCE_TYPE="herokuish" - DOCKER_ARGS+=$(: | plugn trigger docker-args-process-deploy "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE" "$PHASE_SCRIPT_KEY") + DOCKER_ARGS+=$(: | plugn trigger docker-args-process-deploy "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE") # eval args as array to respect escapes declare -a ARG_ARRAY diff --git a/plugins/common/functions b/plugins/common/functions index 8c3f59296..1aa97ffde 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -535,7 +535,7 @@ dokku_build() { local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$IMAGE_SOURCE_TYPE") [[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true " local IMAGE_SOURCE_TYPE="herokuish" - DOCKER_ARGS+=$(: | plugn trigger docker-args-process-run "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE" "$PHASE_SCRIPT_KEY") + DOCKER_ARGS+=$(: | plugn trigger docker-args-process-build "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE") declare -a ARG_ARRAY eval "ARG_ARRAY=($DOCKER_ARGS)" @@ -563,7 +563,7 @@ dokku_build() { [[ "$DOKKU_DOCKERFILE_CACHE_BUILD" == "false" ]] && DOKKU_DOCKER_BUILD_OPTS="$DOKKU_DOCKER_BUILD_OPTS --no-cache" local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$IMAGE_SOURCE_TYPE") local IMAGE_SOURCE_TYPE="dockerfile" - DOCKER_ARGS+=$(: | plugn trigger docker-args-process-run "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE" "$PHASE_SCRIPT_KEY") + DOCKER_ARGS+=$(: | plugn trigger docker-args-process-build "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE") # strip --volume and -v args from DOCKER_ARGS local DOCKER_ARGS=$(sed -e "s/--volume=[[:graph:]]\+[[:blank:]]\?//g" -e "s/-v[[:blank:]]\?[[:graph:]]\+[[:blank:]]\?//g" <<<"$DOCKER_ARGS") diff --git a/plugins/scheduler-docker-local/scheduler-run b/plugins/scheduler-docker-local/scheduler-run index 22a374204..c93fa23b3 100755 --- a/plugins/scheduler-docker-local/scheduler-run +++ b/plugins/scheduler-docker-local/scheduler-run @@ -29,7 +29,7 @@ scheduler-docker-local-scheduler-run() { local IMAGE_SOURCE_TYPE="dockerfile" is_image_herokuish_based "$IMAGE" && IMAGE_SOURCE_TYPE="herokuish" - DOCKER_ARGS+=$(: | plugn trigger docker-args-process-run "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE" "$PHASE_SCRIPT_KEY") + DOCKER_ARGS+=$(: | plugn trigger docker-args-process-run "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE") declare -a ARG_ARRAY eval "ARG_ARRAY=($DOCKER_ARGS)" From e71ad53b0e44c8f24f5a7663cf29b4398321c749 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 17 May 2019 12:03:35 -0400 Subject: [PATCH 4/5] tests: check the cpu setting Switch to 0.5 as its safer to run tests on a single-core VM --- tests/unit/20_resource.bats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/20_resource.bats b/tests/unit/20_resource.bats index 0ee9bef0a..0fd77dbc9 100644 --- a/tests/unit/20_resource.bats +++ b/tests/unit/20_resource.bats @@ -116,7 +116,7 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku resource:reserve --cpu 1.5 --process-type worker $TEST_APP" + run /bin/bash -c "dokku resource:reserve --cpu 0.5 --process-type worker $TEST_APP" echo "output: $output" echo "status: $status" assert_success @@ -127,6 +127,10 @@ teardown() { echo "output: $output" echo "status: $status" assert_output "536870912" + run /bin/bash -c "docker inspect --format '{{.HostConfig.NanoCpus}}' $CID" + echo "output: $output" + echo "status: $status" + assert_output "500000000" run /bin/bash -c "dokku resource:reserve-clear --process-type worker $TEST_APP" echo "output: $output" From 7dd9007607c25f8fa1eddd6255eb30bc39efa42b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 17 May 2019 12:46:23 -0400 Subject: [PATCH 5/5] fix: cpu limiting isn't available on CircleCI --- tests/unit/20_resource.bats | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/20_resource.bats b/tests/unit/20_resource.bats index 0fd77dbc9..31b2f53e5 100644 --- a/tests/unit/20_resource.bats +++ b/tests/unit/20_resource.bats @@ -127,10 +127,10 @@ teardown() { echo "output: $output" echo "status: $status" assert_output "536870912" - run /bin/bash -c "docker inspect --format '{{.HostConfig.NanoCpus}}' $CID" - echo "output: $output" - echo "status: $status" - assert_output "500000000" + # run /bin/bash -c "docker inspect --format '{{.HostConfig.NanoCpus}}' $CID" + # echo "output: $output" + # echo "status: $status" + # assert_output "500000000" run /bin/bash -c "dokku resource:reserve-clear --process-type worker $TEST_APP" echo "output: $output"