-
Notifications
You must be signed in to change notification settings - Fork 5
/
rebuild.sh
executable file
·102 lines (91 loc) · 2.5 KB
/
rebuild.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
#!/usr/bin/env bash
# Author: Patrick Huang
# This script will:
# - stop running containers
# - rebuild the package
# - rebuild the docker container
# - start the docker container
# - tail the container log
SKIP_FRONTEND=false
GOOGLE_CREDENTIAL_FILE=""
GOOGLE_OPTION=""
MS_OPTION=""
DEFAULT_PROVIDER_OPTION="-DDEFAULT_TRANSLATION_PROVIDER=DEV"
TEST="-DskipTests"
clean=clean
runDocker=true
while getopts ":CDfehtg:m:d:" opt; do
case ${opt} in
h)
echo "Usage: $0 [-g google_credentials] [-m microsoft_key] [-d default_provider] [-CDefht]" >&2
echo "-h This help" >&2
echo "-C Skip 'clean'" >&2
echo "-D Skip starting Docker container after build" >&2
echo "-f Skip frontend build" >&2
echo "-g Google credentials JSON file location" >&2
echo "-m Microsoft translate API key" >&2
echo "-d Default provider - DEV, MS, GOOGLE" >&2
echo "-e enable DEV backend" >&2
echo "-t Run tests" >&2
exit 0
;;
C)
echo "Skipping clean" >&2
clean=
;;
D)
echo "Skipping Docker" >&2
runDocker=false
;;
f)
SKIP_FRONTEND=true
;;
g)
GOOGLE_CREDENTIAL_FILE="$OPTARG"
;;
m)
MS_OPTION="-DMT_AZURE_KEY=$OPTARG"
;;
d)
DEFAULT_PROVIDER_OPTION="-DDEFAULT_TRANSLATION_PROVIDER=$OPTARG"
;;
e)
ENABLE_DEV="-DDEV_BACKEND=true"
;;
t)
echo "Tests enabled" >&2
TEST=""
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
set -ex
# Use Google Default Application Credential json file path. If absent, it will
# create an empty temp file and use that path as the argument for container start.
if [ -z "$GOOGLE_CREDENTIAL_FILE" ]
then
# create an empty file so we can get bind it in docker volume
EMPTY_JSON=/tmp/g11n-mt-empty.json
touch ${EMPTY_JSON}
GOOGLE_CREDENTIAL_FILE=${EMPTY_JSON}
echo "Google application credential file path not specified"
echo "Using an empty file instead"
fi
GOOGLE_OPTION="-DGOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_CREDENTIAL_FILE"
./mvnw docker:stop -pl :mt-server || true
if ${SKIP_FRONTEND}
then
echo "Skipping frontend build..."
./mvnw ${clean} install ${TEST} -pl \!frontend
else
echo "Full build..."
./mvnw ${clean} install ${TEST}
fi
if ${runDocker}; then
./mvnw docker:build -pl :mt-server -DskipTests && \
./mvnw docker:start -pl :mt-server ${GOOGLE_OPTION} ${MS_OPTION} \
${ENABLE_DEV} ${DEFAULT_PROVIDER_OPTION}
docker logs --follow MT
fi