-
Notifications
You must be signed in to change notification settings - Fork 10
/
utils.sh
executable file
·164 lines (129 loc) · 3.26 KB
/
utils.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
#!/usr/bin/env bash
set -e
WAS_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$WAS_DIR"
# Test for local environment file and use any overrides
if [ -r .env ]; then
echo "Using configuration overrides from .env file"
. .env
else
echo "Using default configuration values"
touch .env
fi
#Import source the .env file
set -a
source .env
# Which docker image to run
IMAGE=${IMAGE:-willow-application-server}
# UI Listen port
UI_LISTEN_PORT=${UI_LISTEN_PORT:-8501}
# API Listen Port
API_LISTEN_PORT=${API_LISTEN_PORT:-8502}
# Log level - acceptable values are debug, info, warning, error, critical. Suggest info or debug.
LOG_LEVEL=${LOG_LEVEL:-info}
# Listen IP
LISTEN_IP=${LISTEN_IP:-0.0.0.0}
TAG=${TAG:-latest}
# Torture delay
TORTURE_DELAY=${TORTURE_DELAY:-300}
# Web ui branch
WEB_UI_BRANCH="main"
# Local working directory for web ui
WEB_UI_DIR="willow-application-server-ui"
# Web ui URL
WEB_UI_URL="https://github.com/toverainc/willow-application-server-ui.git"
# Reachable WAS IP for the "default" interface
WAS_IP=$(ip route get 1.1.1.1 | grep -oP 'src \K\S+')
# Get WAS version
export WAS_VERSION=$(git describe --always --dirty --tags)
set +a
if [ -z "$WAS_IP" ]; then
echo "Could not determine WAS IP address - you will need to add it to .env"
exit 1
else
echo "WAS Web UI URL is http://$WAS_IP:$API_LISTEN_PORT"
fi
set +a
dep_check() {
return
}
freeze_requirements() {
if [ ! -f /.dockerenv ]; then
echo "This script is meant to be run inside the container - exiting"
exit 1
fi
# Freeze
pip freeze > requirements.txt
}
build-docker() {
docker build --build-arg "WAS_VERSION=$WAS_VERSION" -t "$IMAGE":"$TAG" .
}
build-web-ui() {
mkdir -p "$WAS_DIR"/work
cd "$WAS_DIR"/work
if [ -d "$WEB_UI_DIR/node_modules" ]; then
echo "Existing web ui working dir found, we need sudo to remove it because of docker"
sudo rm -rf willow-application-server-ui
fi
git clone "$WEB_UI_URL"
cd willow-application-server-ui
git checkout "$WEB_UI_BRANCH"
./utils.sh build-docker
./utils.sh install
# WAS_DIR is already set
export WAS_DIR
./utils.sh build
}
gen-tz() {
curl --output misc/gen-tz.py https://raw.githubusercontent.com/nayarsystems/posix_tz_db/master/gen-tz.py
python3 misc/gen-tz.py --json > tz.json
}
shell() {
docker run -it -v $WAS_DIR:/app -v $WAS_DIR/cache:/root/.cache -v willow-application-server_was-storage:/app/storage "$IMAGE":"$TAG" \
/usr/bin/env bash
}
case $1 in
build-docker|build)
gen-tz
build-docker
;;
build-web-ui)
build-web-ui
;;
freeze-requirements)
freeze_requirements
;;
gen-tz)
gen-tz
;;
start|run|up)
dep_check
shift
docker compose up --remove-orphans "$@"
;;
stop|down)
dep_check
shift
docker compose down "$@"
;;
shell|docker)
shell
;;
torture)
echo "Starting WAS device torture test"
docker compose down
while true; do
docker compose up -d
echo "Sleeping for $TORTURE_DELAY"
sleep $TORTURE_DELAY
docker compose down
"Sleeping for $TORTURE_DELAY"
sleep $TORTURE_DELAY
done
;;
*)
dep_check
echo "Passing unknown argument directly to docker compose"
docker compose "$@"
;;
esac