-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·91 lines (76 loc) · 1.96 KB
/
deploy.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# Constants
SUBMODULE_DIR="k-cse-server-module"
DEVELOP_ENV_FILE=".env.develop"
RELEASE_ENV_FILE=".env.release"
# Global variables
DEV_VERSION=""
REL_VERSION=""
ENV_FILE=""
IS_DEV_BUILD=false
# Functions
get_version() {
local env_file=$1
grep '^# Version' "$env_file" | head -n 1 | cut -d' ' -f3-
}
select_build_type() {
echo "Select build type:"
echo "1) Development (Current Version: $DEV_VERSION)"
echo "2) Release (Current Version: $REL_VERSION)"
read -p "Choice build type: " build_type
case $build_type in
1)
ENV_FILE="$SUBMODULE_DIR/$DEVELOP_ENV_FILE"
IS_DEV_BUILD=true
;;
2)
ENV_FILE="$SUBMODULE_DIR/$RELEASE_ENV_FILE"
IS_DEV_BUILD=false
;;
*)
echo "deploy.sh: Invalid choice. Exiting script." && exit 1
;;
esac
}
check_env_file() {
if [ ! -f "$ENV_FILE" ]; then
echo "deploy.sh: File $ENV_FILE not found. Exiting script."
exit 1
fi
}
source_env_file() {
if [ -f "$ENV_FILE" ]; then
# shellcheck disable=SC1090
source "$ENV_FILE"
echo "deploy.sh: Environment variables from $ENV_FILE:"
else
echo "deploy.sh: File $ENV_FILE not found. Exiting script."
exit 1
fi
}
# Main script execution
DEV_VERSION=$(get_version "$SUBMODULE_DIR/$DEVELOP_ENV_FILE")
REL_VERSION=$(get_version "$SUBMODULE_DIR/$RELEASE_ENV_FILE")
select_build_type
check_env_file
source_env_file
echo ""
# Java Build
echo "---------------------------------"
echo "deploy.sh: Starting Java build..."
if [ "$IS_DEV_BUILD" = true ]; then
./gradlew clean build
else
./gradlew clean build -x test
fi
echo "deploy.sh: Java build completed."
echo "---------------------------------"
echo ""
# Run Docker Compose
echo "---------------------------------"
echo "deploy.sh: Starting Docker Compose..."
sudo docker compose --env-file "$ENV_FILE" up -d --build
echo "deploy.sh: Docker Compose up and running."
echo "---------------------------------"
echo ""
echo "deploy.sh: deploy complete"