Skip to content

Commit 2ed8959

Browse files
committed
[CI] Allow Limit CPUs in Docker
This PR adds a new flag `--cpus` in `./docker/bash.sh`, which is passed to docker command that allows limiting the number of CPU cores of a docker container. Related materials: https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler
1 parent 04ee895 commit 2ed8959

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

docker/bash.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ set -euo pipefail
3838
function show_usage() {
3939
cat <<EOF
4040
Usage: docker/bash.sh [-i|--interactive] [--net=host] [-t|--tty]
41-
[--mount MOUNT_DIR] [--repo-mount-point REPO_MOUNT_POINT]
42-
[--dry-run] [--name NAME]
43-
<DOCKER_IMAGE_NAME> [--] [COMMAND]
41+
[--cpus NUM_CPUS] [--mount MOUNT_DIR]
42+
[--repo-mount-point REPO_MOUNT_POINT]
43+
[--dry-run] [--name NAME]
44+
<DOCKER_IMAGE_NAME> [--] [COMMAND]
45+
4446
4547
-h, --help
4648
@@ -54,6 +56,10 @@ Usage: docker/bash.sh [-i|--interactive] [--net=host] [-t|--tty]
5456
5557
Start the docker session with a pseudo terminal (tty).
5658
59+
--cpus NUM_CPUS
60+
61+
Limit the number of CPU cores to be used.
62+
5763
--net=host
5864
5965
Expose servers run into the container to the host, passing the
@@ -184,6 +190,11 @@ while (( $# )); do
184190
eval $break_joined_flag
185191
;;
186192

193+
--cpus)
194+
DOCKER_FLAGS+=(--cpus "$2")
195+
shift 2
196+
;;
197+
187198
--net=host)
188199
USE_NET_HOST=true
189200
shift

0 commit comments

Comments
 (0)