#!/bin/bash
# Copyright ETSI
# See LICESEN files
#
# Stops or restarts the Docker image containing the web-app for doc2tosca and tosca2doc
#

CNT=$(docker ps | grep tosca-ie | cut -d " " -f1)

if [ "$CNT" != "" ] ; then
    docker stop "$CNT"
fi

if [ "$1" == "stop" ] ; then
    exit 0
fi 

sed -i -E "s/(LAST_COMMIT=).+/\1$(git log -n 1 --oneline)/" env

docker build -t tosca-ie-sample:latest .

docker run -d --restart unless-stopped -t -p 5000:5000 --env-file ./env tosca-ie-sample

