summaryrefslogtreecommitdiffstats
path: root/extras/strongswan/vpp_sswan/docker/init_containers.sh
diff options
context:
space:
mode:
authorGabriel Oginski <gabrielx.oginski@intel.com>2022-07-08 07:46:32 +0000
committerFan Zhang <royzhang1980@hotmail.com>2022-09-28 17:46:04 +0000
commit95875774bc69a81b1a17963642fc574070ba37d0 (patch)
tree3792511fa634de36caad77279f8d04c381c4474b /extras/strongswan/vpp_sswan/docker/init_containers.sh
parent4e88e041ad47bf422bbb2a0940f77aba11ea2178 (diff)
vpp-swan: Add scripts for testing
Added scripts to reparing setups for testing To prepare and run containers: sudo ./extras/strongswan/vpp_sswan/docker/run.sh prepare_containers To prepare setups: sudo ./extras/strongswan/vpp_sswan/docker/run.sh config To clean-up settups: sudo ./extras/strongswan/vpp_sswan/docker/run.sh clean To deleted all containers and images in Docker: sudo ./extras/strongswan/vpp_sswan/docker/run.sh deleted Type: feature Signed-off-by: Gabriel Oginski <gabrielx.oginski@intel.com> Change-Id: I77f01c0419dccc95f610046c8552ae825f2c7e12
Diffstat (limited to 'extras/strongswan/vpp_sswan/docker/init_containers.sh')
-rwxr-xr-xextras/strongswan/vpp_sswan/docker/init_containers.sh70
1 files changed, 70 insertions, 0 deletions
diff --git a/extras/strongswan/vpp_sswan/docker/init_containers.sh b/extras/strongswan/vpp_sswan/docker/init_containers.sh
new file mode 100755
index 00000000000..c0e1e2605af
--- /dev/null
+++ b/extras/strongswan/vpp_sswan/docker/init_containers.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+DOCKER_IMAGE_NAME="vppstrongswan"
+DOCKER_IMAGE_TAG="0.1"
+DOCKER_IMAGE_NAME_FULL="$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG"
+
+if [ "_$1" == "_build_docker_image" ];
+then
+ count=`docker image list | grep -c "$DOCKER_IMAGE_NAME.*$DOCKER_IMAGE_TAG"`
+ if [ $count -ne 0 ];
+ then
+ echo "Error: docker image $DOCKER_IMAGE_NAME_FULL already exists"
+ echo "Re-use it or remove to build new image"
+ exit 0
+ else
+ echo "### Building docker image $DOCKER_IMAGE_NAME ..."
+ cd ../ && docker build -t $DOCKER_IMAGE_NAME_FULL -f ./docker/Dockerfile .
+ echo "### Building docker image $DOCKER_IMAGE_NAME finished"
+ fi
+elif [ "_$1" == "_create_docker1" ];
+then
+ if [ "_$2" == "_" ];
+ then
+ exit 1
+ fi
+ DOCKER_CONTAINER_NAME="$2"
+
+ echo "### Creating container $DOCKER_CONTAINER_NAME"
+ 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"
+ if [ $? -eq 0 ];
+ then
+ docker exec -i "$DOCKER_CONTAINER_NAME" "/root/init_docker1.sh" || { echo "call init_docker1.sh failed"; exit 127; }
+ fi
+ echo "### Creating container $DOCKER_CONTAINER_NAME finished"
+ exit 0
+elif [ "_$1" == "_create_docker2" ];
+then
+ if [ "_$2" == "_" ];
+ then
+ exit 1
+ fi
+ DOCKER_CONTAINER_NAME="$2"
+
+ echo "### Creating container $DOCKER_CONTAINER_NAME"
+ 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"
+ if [ $? -eq 0 ];
+ then
+ docker exec -i "$DOCKER_CONTAINER_NAME" "/root/init_docker2.sh" || { echo "call init_docker2.sh failed"; exit 127; }
+ fi
+ echo "### Creating container $DOCKER_CONTAINER_NAME finished"
+ exit 0
+elif [ "_$1" == "_clean" ];
+then
+ if [ "_$2" == "_" ];
+ then
+ exit 1
+ fi
+ DOCKER_CONTAINER_NAME="$2"
+
+ echo "### Deleting container $DOCKER_CONTAINER_NAME"
+ sudo docker rm -f $DOCKER_CONTAINER_NAME
+ echo "### Deleting container $DOCKER_CONTAINER_NAME finished"
+ exit 0
+elif [ "_$1" == "_clean_image" ];
+then
+ echo "### Deleting image $DOCKER_IMAGE_NAME_FULL"
+ sudo docker rmi -f $DOCKER_IMAGE_NAME_FULL
+ echo "### Deleting image $DOCKER_IMAGE_NAME_FULL finished"
+ exit 0
+fi