-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdocker-entrypoint.sh
executable file
·161 lines (133 loc) · 3.59 KB
/
docker-entrypoint.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# Docker entrypoint for nshmp-haz-ws:
# - Downloads nshmp-haz and all models
# - Builds nshmp-haz-ws
# - Deploys nshmp-haz-ws
####
set -o errexit;
set -o errtrace;
readonly LOG_FILE="/var/log/docker-entrypoint-haz-ws.log";
# Docker usage
readonly USAGE="
docker run -p <PORT>:8080 -d usgs/nshmp-haz-ws
";
####
# Build and deploy nshmp-haz-ws.
# Globals:
# (string) LOG_FILE - The log file
# (string) TOMCAT_WEBAPPS - Path to Tomcat webapps directory
# (string) WAR_PATH - Path to nshmp-haz-ws.war
# Arguments:
# None
# Returns:
# None
####
main() {
# Set trap for uncaught errors
trap 'error_exit "${BASH_COMMAND}" "$(< ${LOG_FILE})" "${USAGE}"' ERR;
# Download repositories
download_repos;
# Build nshmp-haz-ws
./gradlew assemble 2> ${LOG_FILE};
# Move war file
mv "${WAR_PATH}" "${TOMCAT_WEBAPPS}" 2> ${LOG_FILE};
# Run Tomcat
catalina.sh run 1> ${LOG_FILE};
}
####
# Download a repository from Github.
# Globals:
# (string) CENTOS_LOG_FILE - The log file
# Arguments:
# (string) user - The Github user
# (string) repo - The project to download
# (string) version - The version to download
# (string) directory - The direcotry name for repo download
# Returns:
# None
####
download_repo() {
local usage="download_repo <user> <repo> <version>";
local user=${1};
local repo=${2};
local version=${3};
local directory=${4};
local url="https://github.com/${user}/${repo}/archive/${version}.tar.gz";
if [ "${version}" == "null" ]; then
printf "\n Skipping download of [%s/%s]\n" "${user}" "${repo}";
return;
fi
printf "\n Downloading [%s] \n\n" "${url}";
if [ -z "${directory}" ]; then
directory=${repo};
fi
curl -L "${url}" | tar -xz 2> "${LOG_FILE}" || \
error_exit "Could not download [${url}]" "$(< "${LOG_FILE}")" "${usage}";
mv "${repo}-${version#v*}" "${directory}";
}
####
# Download nshmp-haz and all models.
# Globals:
# (string) HOME - app home
# (string) LOG_FILE - The log file
# (string) NSHM_AK_2007_VERSION - nshm-ak-2007 repository version
# (string) NSHM_COUS_2008_VERSION - nshm-cous-2008 repository version
# (string) NSHM_COUS_2014_VERSION - nshm-cous-2014 repository version
# (string) NSHM_COUS_2014B_VERSION - nshm-cous-2014b repository version
# (string) NSHM_COUS_2018_VERSION - nshm-cous-2018 repository version
# (string) NSHMP_HAZ_VERSION - nshmp-haz repository version
# (string) WORKDIR - The Docker working directory
# Arguments:
# None
# Returns:
# None
####
download_repos() {
pushd .. > /dev/null 2>&1;
# Download nshmp-haz
download_repo "usgs" "nshmp-haz" "${NSHMP_HAZ_VERSION}";
# Download nshm-ak-2007
download_repo "usgs" "nshm-ak-2007" "${NSHM_AK_2007_VERSION}";
# Download nshm-cous-2008
download_repo "usgs" "nshm-cous-2008" "${NSHM_COUS_2008_VERSION}";
# Download nshm-cous-2014
download_repo "usgs" "nshm-cous-2014" "${NSHM_COUS_2014_VERSION}";
# Download nshm-cous-2014
download_repo "usgs" "nshm-cous-2014" "${NSHM_COUS_2014B_VERSION}" "nshm-cous-2014b";
# Download nshm-cous-2018
download_repo "usgs" "nshm-cous-2018" "${NSHM_COUS_2018_VERSION}";
popd > /dev/null 2>&1;
}
####
# Exit script with error.
# Globals:
# None
# Arguments:
# (string) err - The error message
# (string) logs - The log for the error
# (string) usage - The Docker usage
# Returns:
# None
####
error_exit() {
local err="${1}";
local logs="${2}";
local usage="${3}";
local message="
Error:
${err}
----------
Logs:
${logs}
----------
Usage:
${usage}
";
echo "${message}";
exit 0;
}
####
# Run main
####
main "$@";