mocha-suv/docker-run

68 lines
1.1 KiB
Bash

#!/bin/bash
./docker-build
USE_SSL=false
Q=$?
if [ $Q -ne 0 ]; then
exit $Q
fi
PORT_FORWARD=""
if [ "$1" == "--port" ]; then
PORT_FORWARD="$2"
shift; shift
fi
# generate random UUID for new SUV
# thanks https://stackoverflow.com/questions/34328759
# SUV_ID=$(hexdump -vn8 -e'2/4 "%08x" 1 "\n"' /dev/urandom)
SUV_ID=$(head -c8 < /dev/urandom | xxd -p)
if [ $? -ne 0 ]; then
echo "failed to generate SUV ID"
exit
fi
SUV_NAME=i-0$SUV_ID
echo "provisioning new Docker-based SUV with id $SUV_NAME"
if [ $? -ne 0 ]; then
echo "'docker build' failed; is it properly installed?"
exit
fi
# create the network configuration
docker network create --subnet=10.8.0.0/16 mocha-docker
# initiate a container (i.e. 'mocha suv up i-0...' )
if [ $PORT_FORWARD != "" ]; then
if [ "$USE_SSL" == "true" ]; then
docker run --name $SUV_NAME -d -p $PORT_FORWARD:443 mocha-httpd
else
docker run --name $SUV_NAME -d -p $PORT_FORWARD:80 mocha-httpd
fi
else
docker run --name $SUV_NAME -d --net mocha-docker -it mocha-httpd # -p 8000:80 mocha-httpd
fi
echo "waiting for network to settle..."
sleep 3
docker inspect $SUV_NAME