#!/bin/bash
TOSCA_PARSER="Cloudnet-TOSCA-toolbox"
GIT_URL_TOSCA_TOOLBOX="https://github.com/Orange-OpenSource/Cloudnet-TOSCA-toolbox.git"
TOSCA_PARSER_FOLDER="tosca-parser/"

while getopts v: flag
do
        case "${flag}" in
                v) TOSCA_PARSER=${OPTARG};;
        esac
done

if [ ${TOSCA_PARSER} == "Cloudnet-TOSCA-toolbox" ] ; then
	# clone robot tests
    git clone $GIT_URL_TOSCA_TOOLBOX $TOSCA_PARSER_FOLDER
    cd $TOSCA_PARSER_FOLDER
    docker build -t cloudnet/toscaware bin/toscaware
	
	echo docker run --mount="${PWD}:/work" --mount="${PWD}/bin/cloudnet:/cloudnet" --workdir="/work" cloudnet/toscaware /bin/sh -c "echo Building image"
	docker run --mount="${PWD}:/work" --mount="${PWD}/bin/cloudnet:/cloudnet" --workdir="/work" cloudnet/toscaware /bin/sh -c "echo Building image"
	sleep 5;
	container_to_update=`docker ps -n 1 --format '{{.Names}}'`
	echo "Creating updated image from container ${container_to_update}"
	docker container commit ${container_to_update} cloudnet/toscaware:latest
	echo "Deleting old container ${container_to_update}"
	docker container rm ${container_to_update}

fi