C-Docs: Set the version of hugo-book theme
[csit.git] / fdio.infra.ansible / roles / docker_images / files / csit-initialize-docker-tg.sh
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 case "${1:-start}" in
6     "start" )
7         # Run TG
8         for cnt in $(seq 1 ${2:-1}); do
9             docker network create --driver bridge csit-nw-tg${cnt} || true
10             # If the IMAGE is not already loaded then docker run will pull the
11             # IMAGE, and all image dependencies, before it starts the container.
12             dcr_image="base-ubuntu2204:local"
13             # Run the container in the background and print the new container
14             # ID.
15             dcr_stc_params="--detach=true "
16             # Give extended privileges to this container. A "privileged"
17             # container is given access to all devices and able to run nested
18             # containers.
19             dcr_stc_params+="--privileged "
20             # Publish all exposed ports to random ports on the host interfaces.
21             dcr_stc_params+="--publish 600${cnt}:2222 "
22             # Automatically remove the container when it exits.
23             dcr_stc_params+="--rm "
24             # Size of /dev/shm.
25             dcr_stc_params+="--shm-size 4G "
26             # Mount vfio to be able to bind to see binded interfaces. We cannot
27             # use --device=/dev/vfio as this does not see newly binded
28             # interfaces.
29             dcr_stc_params+="--volume /dev:/dev "
30             # Mount /opt/boot/ where VM kernel and initrd are located.
31             dcr_stc_params+="--volume /opt:/opt "
32             # Mount host hugepages for VMs.
33             dcr_stc_params+="--volume /dev/hugepages:/dev/hugepages "
34
35             params=(${dcr_stc_params} --name csit-tg-"${cnt}" "${dcr_image}")
36             docker run --network=csit-nw-tg${cnt} "${params[@]}"
37         done
38         ;;
39     "stop" )
40         docker rm --force $(docker ps --all --quiet --filter name=csit)
41         docker network rm $(docker network ls --filter name=csit --quiet)
42         ;;
43 esac