-
Notifications
You must be signed in to change notification settings - Fork 5
/
build-and-deploy-webapp.sh
executable file
·75 lines (65 loc) · 2.31 KB
/
build-and-deploy-webapp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
ENV_FILE=${SCRIPT_DIR}/docker/dev.env
source ${ENV_FILE}
function show_usage {
echo "Usage: build-and-deploy-webapp.sh [OPTION]..."
echo "It is building and deploying our web application."
echo ""
echo "All options are disabled if omitted."
echo -e "-n\tUse this flag if you would not like to do any build, just execute the application."
echo -e "-f\tUse this flag if you would like to build the front-end javascript packages."
echo -e "-b\tUse this flag if you would like to build the back-end of the web application."
echo -e "-h\tDisplaying this help file."
echo -e "\nIf you don't give any flags or you add both then the script is going to build both front and back-end part of the web application."
}
function get_build_type() {
if [[ $BUILD_FRONTEND == "true" && $BUILD_BACKEND != "true" ]]; then
echo "-ui-only"
elif [[ $BUILD_FRONTEND != "true" && $BUILD_BACKEND == "true" ]]; then
echo "-war-only"
elif [[ $BUILD_FRONTEND == "true" && $BUILD_BACKEND == "true" ]] || [[ -z $BUILD_FRONTEND && -z $BUILD_BACKEND ]]; then
echo "-all"
elif [[ $BUILD_FRONTEND == "false" && $BUILD_BACKEND == "false" ]]; then
echo "-no"
fi
}
while getopts ":bfhn" opt; do
case $opt in
n)
BUILD_FRONTEND=false
BUILD_BACKEND=false
;;
f)
BUILD_FRONTEND=true
;;
b)
BUILD_BACKEND=true
;;
h)
show_usage
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo ""
show_usage
exit 1
;;
esac
done
BUILD_POSTFIX=$(get_build_type)
DOCKER_COMPOSE_COMMAND="docker compose \
--project-name ${PROJECT_NAME} \
--env-file=${ENV_FILE} \
-f ./docker/docker-compose-solrcloud.yml \
-f ./docker/docker-compose-postgres.yml \
-f ./docker/docker-compose-tomcat.yml \
-f ./docker/docker-compose-build${BUILD_POSTFIX}.yml"
DOCKER_COMPOSE_COMMAND_VARS="SCHEMA_VERSION=latest"
eval "${DOCKER_COMPOSE_COMMAND_VARS}" "${DOCKER_COMPOSE_COMMAND}" "up -d"
printf '%b\n\n' "👀 Keep an eye on Tomcat logs at container scxa-tomcat: docker logs -f scxa-tomcat-1"
printf '%b\n' "🧹 Press Enter to stop and remove the containers, or Ctrl+C to cancel..."
read -r -s
eval "${DOCKER_COMPOSE_COMMAND_VARS}" "${DOCKER_COMPOSE_COMMAND}" "down"