-
Notifications
You must be signed in to change notification settings - Fork 4
/
jetty-website.sh
executable file
·342 lines (274 loc) · 7.72 KB
/
jetty-website.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/bash
#set -x
#
# This script will grow over time to support a proper staged site leveraging local ui build.
#
function usage() {
echo "Usage: ";
echo " ./jetty-website.sh [options]";
echo " -s,--stage-dir: directory to stage build website"
echo " -r,--release-dir: directory to release build website"
echo " -f,--follow-log: to have logs in the console"
echo " -u,--user-sudo: User to use for sudo copy"
echo " -d,--directive: directive to use"
echo " settings : print configured settings";
echo " stage : build and stage the latest version of the website";
echo " release : build and deploy the latest version of the website";
echo " promote-from-stage : copy stage files to release sans build"
echo " -h,--help: display help information"
echo "";
SHORT=s:r:fd:h
LONG=stage-dir,release-dir:,follow-log,directive:,help
}
function print_settings() {
echo "Staging Directory: $STAGE_DIR";
echo "Release Directory: $RELEASE_DIR";
echo "Compress Directories: $COMPRESS_PATHS";
echo "Compress Extensions : $COMPRESS_EXTENSIONS";
echo "SUDO_USER: $SUDO_USER";
echo "Log File: $LOG_FILE";
echo "follow logs: $FOLLOW_LOGS"
}
function check_environment() {
echo "$FUNCNAME";
# check java
if [[ -z "${JAVA_HOME}" ]]; then
echo "Error: JAVA_HOME environment variable not set, required for javadoc generation."
exit 1
fi
local java_version=$(java -version 2>&1 | head -n1 | sed -r 's/.*version "([0-9]*).*$/\1/');
if [[ $java_version < $MIN_JAVA_VERSION ]]; then
echo "Error: java version $java_version must be $MIN_JAVA_VERSION+";
fi
# check maven
local maven_version=$(./mvnw -version 2>&1 | head -n1 | sed -r 's/.*Maven ([0-9.]*).([0-9]*).([0-9]*).*$/\1\2\3/');
if [[ $maven_version < $MIN_MAVEN_VERSION ]]; then
echo "Error: mvn version must be $MIN_MAVEN_VERSION+";
fi
}
function set_log_file() {
echo "$FUNCNAME";
if [[ -e "$LOG_FILE" ]]; then
rm $LOG_FILE;
fi
mkdir -p $SCRIPT_OUTPUT_DIR;
touch $LOG_FILE;
}
# maybe we shouldn't bother with this, just pull from the published ui github action artifact
# though if we are staging we should build and use that artifact
function build_ui() {
echo "$FUNCNAME";
local owd=$(pwd);
cd ui;
echo " - building ui";
mvn process-resources &>>"$LOG_FILE";
local mvn_status=$?;
if [[ mvn_status -ne 0 ]]; then
echo " - error building ui";
exit 1;
fi
cd $owd;
}
function copy_files() {
local from_dir=$1;
local to_dir=$2;
if [ ! -z "$SUDO_USER" ]; then
echo " - copying files from $from_dir to $to_dir as user $SUDO_USER";
run_cmd "sudo -u $SUDO_USER rsync -avh --delete --checksum $from_dir $to_dir"
else
echo " - copying files from $from_dir to $to_dir";
run_cmd "rsync -avh --delete --checksum $from_dir $to_dir"
fi
local rsync_status=$?;
if [[ rsync_status -ne 0 ]]; then
echo " - error deploying site";
exit 1;
fi
}
function compress_files() {
echo "$FUNCNAME";
for directory in ${COMPRESS_PATHS[@]}; do
for extension in ${COMPRESS_EXTENSIONS[@]}; do
find $directory -type f -name $extension -print0 | while IFS= read -r -d '' file; do
# always overwrite the file in case the source file changed and the build was not cleared
gzip -f -9 -k $file;
done
done
done
}
function init_site() {
echo "$FUNCNAME";
echo " - building site";
echo " - this may take up to 10+ minutes";
run_cmd "./mvnw -B -e -V -ntp -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss antora:antora@full";
local mvn_status=$?;
if [[ mvn_status -ne 0 ]]; then
echo " - error building site";
exit 1;
fi
}
function build_ui() {
echo "$FUNCNAME";
echo " - building ui";
echo " - this may take up 5 minutes";
echo " - Follow: tail -f $LOG_FILE";
cd ui;
run_cmd "./mvnw -B -e -V -ntp -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss process-resources"
local mvn_status=$?;
cd ..;
if [[ mvn_status -ne 0 ]]; then
echo " - error building ui";
exit 1;
fi
if [[ ! -f "$UI_BUNDLE_FILE" ]]; then
echo " - successfully built website";
else
echo " - error building website, no index.html";
exit 1;
fi
}
function build_site() {
echo "$FUNCNAME";
echo " - building site";
echo " - this may take up to 10 minutes";
run_cmd "./mvnw -B -e -V -ntp -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss antora:antora@full"
local mvn_status=$?;
if [[ mvn_status -ne 0 ]]; then
echo " - error building site";
exit 1;
fi
if [[ ! -f "$$BUILT_SITE_DIR/index.html" ]]; then
echo " - successfully built website";
else
echo " - error building website, no index.html";
exit 1;
fi
}
function deploy_site() {
echo "$FUNCNAME";
local site_dir=$1;
local deploy_dir=$2;
if [[ ! -d "$site_dir" ]]; then
echo " - error, no files to deploy in $site_dir";
exit 1;
fi
if [[ ! -d "$deploy_dir" ]]; then
echo " - creating deployment directory"
mkdir -p $deploy_dir;
fi
echo " - deploying $site_dir to $deploy_dir";
copy_files "$BUILT_SITE_DIR/" $deploy_dir;
echo " - site deployed";
}
function run_cmd() {
if [[ "$FOLLOW_LOGS" == "true" ]]; then
eval "$1";
else
echo " - Follow: tail -f $LOG_FILE";
eval "$1 &>> $LOG_FILE";
fi
}
function main() {
local directive=$DIRECTIVE
if [[ $directive == "settings" ]]; then
check_environment;
print_settings;
exit 0;
fi
if [[ $directive == "stage" ]]; then
check_environment;
#build_ui;
build_site;
compress_files;
deploy_site "$BUILT_SITE_DIR" "$STAGE_DIR";
exit 0;
fi
if [[ $directive == "release" ]]; then
check_environment;
build_site;
compress_files;
deploy_site "$BUILT_SITE_DIR" "$RELEASE_DIR";
exit 0;
fi
if [[ $directive == "promote-from-stage" ]]; then
check_environment;
deploy_site "$STAGE_DIR" "$RELEASE_DIR";
exit 0;
fi
# print usage
usage;
exit 0;
}
function set_environment() {
echo "$FUNCNAME";
set_global_variables;
set_log_file;
}
function set_global_variables() {
##
## Update these settings accordingly, read from cfg file if exists
##
if [[ -e jetty-website.cfg ]]; then
source ./jetty-website.cfg
else
SUDO_USER=www-data
STAGE_DIR=$(pwd)/target/stage;
RELEASE_DIR=$(pwd)/target/release;
COMPRESS_PATHS=("_");
COMPRESS_EXTENSIONS=("*.woff" "*.woff2" "*.js" "*.css" "*.svg");
fi
export CI=true
MIN_JAVA_VERSION=17
MIN_MAVEN_VERION=3.9.4
SCRIPT_OUTPUT_DIR="$(pwd)/target";
BUILT_SITE_DIR=$(pwd)/target/site;
UI_BUNDLE_FILE="$(pwd)/ui/build/ui-bundle.zip"
LOG_FILE="$SCRIPT_OUTPUT_DIR/jetty-website.log";
FOLLOW_LOGS=false
}
set_environment
# Parse command-line options
# Option strings
SHORT=s:r:fd:hu:
LONG=stage-dir,release-dir:,follow-log,directive:,help,user-sudo:
# read the options
OPTS=$(getopt --options $SHORT --long $LONG --name "$0" -- "$@")
if [ $? != 0 ] ; then echo "Failed to parse options...exiting." >&2 ; exit 1 ; fi
eval set -- "$OPTS"
while true; do
case "$1" in
-s | --stage-dir )
STAGE_DIR=$2
shift 2
;;
-r | --release-dir )
RELEASE_DIR=$2
shift 2
;;
-f | --follow-log )
FOLLOW_LOGS=true
shift
;;
-h | --help )
HELP=true
shift
;;
-d | --directive )
DIRECTIVE=$2
shift 2
;;
-u | --user-sudo )
SUDO_USER=$2
shift 2
;;
-- )
shift
break
;;
esac
done
if [[ "$HELP" == "true" ]]; then
usage
exit 0
fi
main;