blob: c0e1e2605affa7986638f130f1a06eb92ad36640 [file] [log] [blame]
Gabriel Oginski95875772022-07-08 07:46:32 +00001#!/bin/bash
2
3DOCKER_IMAGE_NAME="vppstrongswan"
4DOCKER_IMAGE_TAG="0.1"
5DOCKER_IMAGE_NAME_FULL="$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG"
6
7if [ "_$1" == "_build_docker_image" ];
8then
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
20elif [ "_$1" == "_create_docker1" ];
21then
22 if [ "_$2" == "_" ];
23 then
24 exit 1
25 fi
26 DOCKER_CONTAINER_NAME="$2"
27
28 echo "### Creating container $DOCKER_CONTAINER_NAME"
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 -v /sys/fs/cgroup:/sys/fs/cgroup:ro "$DOCKER_IMAGE_NAME_FULL"
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
36elif [ "_$1" == "_create_docker2" ];
37then
38 if [ "_$2" == "_" ];
39 then
40 exit 1
41 fi
42 DOCKER_CONTAINER_NAME="$2"
43
44 echo "### Creating container $DOCKER_CONTAINER_NAME"
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 -v /sys/fs/cgroup:/sys/fs/cgroup:ro "$DOCKER_IMAGE_NAME_FULL"
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
52elif [ "_$1" == "_clean" ];
53then
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
64elif [ "_$1" == "_clean_image" ];
65then
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
70fi