Gabriel Oginski | 9587577 | 2022-07-08 07:46:32 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | DOCKER_IMAGE_NAME="vppstrongswan" |
| 4 | DOCKER_IMAGE_TAG="0.1" |
| 5 | DOCKER_IMAGE_NAME_FULL="$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG" |
| 6 | |
| 7 | if [ "_$1" == "_build_docker_image" ]; |
| 8 | then |
| 9 | count=`docker image list | grep -c "$DOCKER_IMAGE_NAME.*$DOCKER_IMAGE_TAG"` |
| 10 | if [ $count -ne 0 ]; |
| 11 | then |
| 12 | echo "Error: docker image $DOCKER_IMAGE_NAME_FULL already exists" |
| 13 | echo "Re-use it or remove to build new image" |
| 14 | exit 0 |
| 15 | else |
| 16 | echo "### Building docker image $DOCKER_IMAGE_NAME ..." |
| 17 | cd ../ && docker build -t $DOCKER_IMAGE_NAME_FULL -f ./docker/Dockerfile . |
| 18 | echo "### Building docker image $DOCKER_IMAGE_NAME finished" |
| 19 | fi |
| 20 | elif [ "_$1" == "_create_docker1" ]; |
| 21 | then |
| 22 | if [ "_$2" == "_" ]; |
| 23 | then |
| 24 | exit 1 |
| 25 | fi |
| 26 | DOCKER_CONTAINER_NAME="$2" |
| 27 | |
| 28 | echo "### Creating container $DOCKER_CONTAINER_NAME" |
Gabriel Oginski | b953532 | 2023-09-25 10:41:06 +0000 | [diff] [blame] | 29 | docker run -itd --name="$DOCKER_CONTAINER_NAME" --privileged --cap-add=ALL -p 8022:22 -v /mnt/huge:/mnt/huge -v /sys/bus/pci/devices:/sys/bus/pci/devices -v /sys/devices/system/node:/sys/devices/system/node -v /lib/modules:/lib/modules -v /dev:/dev --tmpfs /tmp --tmpfs /run --tmpfs /run/lock --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw "$DOCKER_IMAGE_NAME_FULL" |
Gabriel Oginski | 9587577 | 2022-07-08 07:46:32 +0000 | [diff] [blame] | 30 | if [ $? -eq 0 ]; |
| 31 | then |
| 32 | docker exec -i "$DOCKER_CONTAINER_NAME" "/root/init_docker1.sh" || { echo "call init_docker1.sh failed"; exit 127; } |
| 33 | fi |
| 34 | echo "### Creating container $DOCKER_CONTAINER_NAME finished" |
| 35 | exit 0 |
| 36 | elif [ "_$1" == "_create_docker2" ]; |
| 37 | then |
| 38 | if [ "_$2" == "_" ]; |
| 39 | then |
| 40 | exit 1 |
| 41 | fi |
| 42 | DOCKER_CONTAINER_NAME="$2" |
| 43 | |
| 44 | echo "### Creating container $DOCKER_CONTAINER_NAME" |
Gabriel Oginski | b953532 | 2023-09-25 10:41:06 +0000 | [diff] [blame] | 45 | docker run -itd --name="$DOCKER_CONTAINER_NAME" --privileged --cap-add=ALL -p 8023:22 -v /mnt/huge:/mnt/huge -v /sys/bus/pci/devices:/sys/bus/pci/devices -v /sys/devices/system/node:/sys/devices/system/node -v /lib/modules:/lib/modules -v /dev:/dev --tmpfs /tmp --tmpfs /run --tmpfs /run/lock --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw "$DOCKER_IMAGE_NAME_FULL" |
Gabriel Oginski | 9587577 | 2022-07-08 07:46:32 +0000 | [diff] [blame] | 46 | if [ $? -eq 0 ]; |
| 47 | then |
| 48 | docker exec -i "$DOCKER_CONTAINER_NAME" "/root/init_docker2.sh" || { echo "call init_docker2.sh failed"; exit 127; } |
| 49 | fi |
| 50 | echo "### Creating container $DOCKER_CONTAINER_NAME finished" |
| 51 | exit 0 |
| 52 | elif [ "_$1" == "_clean" ]; |
| 53 | then |
| 54 | if [ "_$2" == "_" ]; |
| 55 | then |
| 56 | exit 1 |
| 57 | fi |
| 58 | DOCKER_CONTAINER_NAME="$2" |
| 59 | |
| 60 | echo "### Deleting container $DOCKER_CONTAINER_NAME" |
| 61 | sudo docker rm -f $DOCKER_CONTAINER_NAME |
| 62 | echo "### Deleting container $DOCKER_CONTAINER_NAME finished" |
| 63 | exit 0 |
| 64 | elif [ "_$1" == "_clean_image" ]; |
| 65 | then |
| 66 | echo "### Deleting image $DOCKER_IMAGE_NAME_FULL" |
| 67 | sudo docker rmi -f $DOCKER_IMAGE_NAME_FULL |
| 68 | echo "### Deleting image $DOCKER_IMAGE_NAME_FULL finished" |
| 69 | exit 0 |
| 70 | fi |