Skip to content

Commit 18a296b

Browse files
authored
Merge pull request #262 from dovetail/add-device-limits
Add device-level IO limit options
2 parents 2c5f542 + 216a54c commit 18a296b

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,30 @@ Enables debug mode, which outputs the full Docker commands that will be run on t
209209

210210
Default: `false`
211211

212+
### `device-read-bps` (optional, array)
213+
214+
Limit read rate from a device (format: `<device-path>:<number>[<unit>]`). Number is a positive integer. Unit can be one of `kb`, `mb`, or `gb`.
215+
216+
Example: `["/dev/sda1:200mb"]`
217+
218+
### `device-read-iops` (optional, array)
219+
220+
Limit read rate (IO per second) from a device (format: `<device-path>:<number>`). Number is a positive integer.
221+
222+
Example: `["/dev/sda1:400"]`
223+
224+
### `device-write-bps` (optional, array)
225+
226+
Limit write rate to a device (format: `<device-path>:<number>[<unit>]`). Number is a positive integer. Unit can be one of `kb`, `mb`, or `gb`.
227+
228+
Example: `["/dev/sda1:200mb"]`
229+
230+
### `device-write-iops` (optional, array)
231+
232+
Limit write rate (IO per second) to a device (format: `<device-path>:<number>`). Number is a positive integer.
233+
234+
Example: `["/dev/sda1:400"]`
235+
212236
### `entrypoint` (optional, string)
213237

214238
Override the image’s default entrypoint, and defaults the `shell` option to `false`. See the [docker run --entrypoint documentation](https://docs.docker.com/engine/reference/run/#entrypoint-default-command-to-execute-at-runtime) for more details. Set it to `""` (empty string) to disable the default entrypoint for the image, but note that you may need to use this plugin's `command` option instead of the top-level `command` option or set a `shell` instead (depending on the command you want/need to run - see [Issue 138](https://github.com/buildkite-plugins/docker-buildkite-plugin/issues/138) for more information).

commands/run.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,34 @@ if [[ -n "${BUILDKITE_PLUGIN_DOCKER_MEMORY_SWAPPINESS:-}" ]]; then
413413
args+=("--memory-swappiness=${BUILDKITE_PLUGIN_DOCKER_MEMORY_SWAPPINESS}")
414414
fi
415415

416+
# Handle setting device read throughput if provided
417+
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_BPS; then
418+
for arg in "${result[@]}"; do
419+
args+=("--device-read-bps" "$arg")
420+
done
421+
fi
422+
423+
# Handle setting device write throughput if provided
424+
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_BPS; then
425+
for arg in "${result[@]}"; do
426+
args+=("--device-write-bps" "$arg")
427+
done
428+
fi
429+
430+
# Handle setting device read IOPS if provided
431+
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_IOPS; then
432+
for arg in "${result[@]}"; do
433+
args+=("--device-read-iops" "$arg")
434+
done
435+
fi
436+
437+
# Handle setting device write IOPS if provided
438+
if plugin_read_list_into_result BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_IOPS; then
439+
for arg in "${result[@]}"; do
440+
args+=("--device-write-iops" "$arg")
441+
done
442+
fi
443+
416444
# Handle entrypoint if set, and default shell to disabled
417445
if [[ -n ${BUILDKITE_PLUGIN_DOCKER_ENTRYPOINT+x} ]]; then
418446
args+=("--entrypoint" "${BUILDKITE_PLUGIN_DOCKER_ENTRYPOINT}")

plugin.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ configuration:
1717
type: string
1818
debug:
1919
type: boolean
20+
device-read-bps:
21+
type: array
22+
device-read-iops:
23+
type: array
24+
device-write-bps:
25+
type: array
26+
device-write-iops:
27+
type: array
2028
entrypoint:
2129
type: string
2230
environment:

tests/command.bats

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,74 @@ EOF
10281028
unstub docker
10291029
}
10301030

1031+
@test "Runs BUILDKITE_COMMAND with multiple added device read bps" {
1032+
export BUILDKITE_COMMAND="echo hello world"
1033+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_BPS_0='bps-0'
1034+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_BPS_1='bps-1'
1035+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_BPS_2='bps-2'
1036+
1037+
stub docker \
1038+
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --device-read-bps bps-0 --device-read-bps bps-1 --device-read-bps bps-2 --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"
1039+
1040+
run "$PWD"/hooks/command
1041+
1042+
assert_success
1043+
assert_output --partial "ran command in docker"
1044+
1045+
unstub docker
1046+
}
1047+
1048+
@test "Runs BUILDKITE_COMMAND with multiple added device write bps" {
1049+
export BUILDKITE_COMMAND="echo hello world"
1050+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_BPS_0='bps-0'
1051+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_BPS_1='bps-1'
1052+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_BPS_2='bps-2'
1053+
1054+
stub docker \
1055+
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --device-write-bps bps-0 --device-write-bps bps-1 --device-write-bps bps-2 --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"
1056+
1057+
run "$PWD"/hooks/command
1058+
1059+
assert_success
1060+
assert_output --partial "ran command in docker"
1061+
1062+
unstub docker
1063+
}
1064+
1065+
@test "Runs BUILDKITE_COMMAND with multiple added device read iops" {
1066+
export BUILDKITE_COMMAND="echo hello world"
1067+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_IOPS_0='iops-0'
1068+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_IOPS_1='iops-1'
1069+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_READ_IOPS_2='iops-2'
1070+
1071+
stub docker \
1072+
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --device-read-iops iops-0 --device-read-iops iops-1 --device-read-iops iops-2 --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"
1073+
1074+
run "$PWD"/hooks/command
1075+
1076+
assert_success
1077+
assert_output --partial "ran command in docker"
1078+
1079+
unstub docker
1080+
}
1081+
1082+
@test "Runs BUILDKITE_COMMAND with multiple added device write iops" {
1083+
export BUILDKITE_COMMAND="echo hello world"
1084+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_IOPS_0='iops-0'
1085+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_IOPS_1='iops-1'
1086+
export BUILDKITE_PLUGIN_DOCKER_DEVICE_WRITE_IOPS_2='iops-2'
1087+
1088+
stub docker \
1089+
"run -t -i --rm --init --volume $PWD:/workdir --workdir /workdir --device-write-iops iops-0 --device-write-iops iops-1 --device-write-iops iops-2 --label com.buildkite.job-id=1-2-3-4 image:tag /bin/sh -e -c 'echo hello world' : echo ran command in docker"
1090+
1091+
run "$PWD"/hooks/command
1092+
1093+
assert_success
1094+
assert_output --partial "ran command in docker"
1095+
1096+
unstub docker
1097+
}
1098+
10311099
@test "Runs BUILDKITE_COMMAND with one added capability" {
10321100
export BUILDKITE_COMMAND="echo hello world"
10331101
export BUILDKITE_PLUGIN_DOCKER_ADD_CAPS_0='cap-0'

0 commit comments

Comments
 (0)