2021-09-09 14:56:37 +02:00
cd " ${ 0 %/* } " || ( echo "Could not chdir to this script's dir!" && exit ) # Change the working directory to the script's directory, when running from other location.
justInstall = 0
2022-02-04 14:49:56 +01:00
shouldRunInDocker = 0
2021-09-09 14:56:37 +02:00
if [ [ $# -eq 1 ] ] ; then
justInstall = $1
2022-02-04 14:49:56 +01:00
elif [ [ $# -eq 2 ] ] ; then
justInstall = $1
shouldRunInDocker = $2
elif [ [ $# -gt 2 ] ] ; then
echo -e " Wrong number of arguments given: ${# } \nPlease execute it like: script.sh <justInstall: 0 | 1> <shouldRunInDocker: 0 | 1> " ; exit 1
fi
if [ [ justInstall -eq 1 && shouldRunInDocker -eq 1 ] ] ; then
echo -e "Cannot run in docker without re-building the project (just to be safe). Setting \"justInstall\" to < 0 >"
justInstall = 0
2021-09-09 14:56:37 +02:00
fi
2022-11-10 15:50:21 +01:00
gradleVersion = "7.5.1"
2021-09-09 14:56:37 +02:00
if [ [ justInstall -eq 0 ] ] ; then
2021-10-14 01:46:33 +02:00
if [ [ ! -d /opt/gradle/gradle-${ gradleVersion } ] ] ; then
wget https://services.gradle.org/distributions/gradle-${ gradleVersion } -bin.zip
echo -e "\nAsking for sudo, in order to install 'gradle'..\n"
sudo mkdir /opt/gradle
sudo apt install -y unzip && sudo unzip -d /opt/gradle gradle-${ gradleVersion } -bin.zip
#ls /opt/gradle/gradle-${gradleVersion} # For debugging installation
fi
2021-09-09 14:56:37 +02:00
2022-01-21 14:45:12 +01:00
export PATH = /opt/gradle/gradle-${ gradleVersion } /bin:$PATH
2021-09-09 14:56:37 +02:00
gradle wrapper --gradle-version= ${ gradleVersion } --distribution-type= bin
#gradle tasks # For debugging installation
#gradle -v # For debugging installation
2022-02-04 14:49:56 +01:00
gradle clean build
if [ [ shouldRunInDocker -eq 1 ] ] ; then
echo "Give the username for the Docker Hub:"
read -r username
echo -e "\nBuilding docker image..\n"
sudo docker --version || ( echo -e "Docker was not found!" ; exit 9)
dockerImage = ${ username } "/urls_controller:latest"
sudo docker build -t " ${ dockerImage } " .
2022-02-23 16:40:06 +01:00
echo -e "\nPushing docker image.. (the account password is required, otherwise it will not be pushed, but it will continue to run)..\n"
2022-02-04 14:49:56 +01:00
( sudo docker login -u " ${ username } " && sudo docker push " ${ dockerImage } " ) || true
2022-02-14 11:36:00 +01:00
( sudo mkdir -p " $HOME " /tmp/config && sudo cp ./src/main/resources/application.properties " $HOME " /tmp/config) || true # This also replaces an existing "application.properties".
2022-02-04 14:49:56 +01:00
sudo docker run -d --mount type = bind,source= " $HOME " /tmp/config,target= /mnt/config -p 1880:1880 " ${ dockerImage } " && echo "The docker container started running."
# Run in "detached mode" (in the background).
fi
2021-09-09 14:56:37 +02:00
else
2022-01-21 14:45:12 +01:00
export PATH = /opt/gradle/gradle-${ gradleVersion } /bin:$PATH # Make sure the gradle is still accessible (it usually isn't without the "export").
2021-09-09 14:56:37 +02:00
fi
2022-02-04 14:49:56 +01:00
if [ [ shouldRunInDocker -ne 1 ] ] ; then
gradle bootRun
fi