Gazebo_simulation-Backend/executor.sh

64 lines
1.7 KiB
Bash

#!/bin/bash
'''
Command to run this script :
executor.sh -e "prod" -b true -r false
"environment:clean_build:run:"
e -> environment
b -> clean_build
r -> run
'''
helpFunction()
{
echo ""
echo "Usage: $0 -e environment -b clean_build -r run"
echo -e "\t-e Environment for the deplyment"
echo -e "\t-b Cleaning docker workspace and building a new docker file"
echo -e "\t-r Running the docker file"
exit 1 # Exit script after printing help
}
while getopts "e:b:r:" opt
do
case "$opt" in
e ) environment="$OPTARG" ;;
b ) clean_build="$OPTARG" ;;
r ) run="$OPTARG" ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
done
# Print helpFunction in case parameters are empty
if [ -z "$environment" ] || [ -z "$clean_build" ] || [ -z "$run" ]
then
echo "Some or all of the parameters are empty";
helpFunction
fi
if [ "$environment" == "prod" ]
then
if [ "$clean_build" == "true" ];
then
echo "Cleaning the existing docker images"
docker container stop springbootapp productdb
docker container rm springbootapp productdb
docker image rm mariadb:latest spiri-backend-image_test_1:latest openjdk:8-jdk-alpine
#echo "Cleaning the target folder"
#rm -r ~/target
#echo "Builing the jar file"
#mvn clean install
echo "Building the docker image"
docker build -t spiri-backend-image_test_1 .
fi
if [ "$run" == "true" ];
then
echo "Starting to run the docker services mentioned in docker-compose file"
docker-compose up -d
fi
elif [ "$environment" == "dev"] && ["$run" == "true"]
then
mvn clean install
mvn spring-boot:run
fi