/
lila-docker
executable file
·212 lines (183 loc) · 5.91 KB
/
lila-docker
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
#!/bin/bash -e
run_setup() {
rust_cmd setup
docker compose build
docker compose --profile utils build
docker compose up -d
run_ui_build --update
setup_bbppairings
setup_database
rust_cmd welcome
}
run_start() {
if [ -z "$(docker compose ps -a --services | xargs)" ]; then
run_setup
else
if [ ! -z "$(docker compose ps -a --services --status=exited | xargs)" ]; then
COMPOSE_PROFILES=$(all_profiles) docker compose start
else
echo "There are no stopped services to resume"
fi
fi
}
run_stop() {
COMPOSE_PROFILES=$(all_profiles) docker compose stop
}
run_down() {
COMPOSE_PROFILES=$(all_profiles) docker compose down -v
}
all_profiles() {
# return all Docker Compose profiles as a comma-separated string
docker compose config --profiles | xargs | sed -e 's/ /,/g'
}
build_all_profiles() {
COMPOSE_PROFILES=$(all_profiles) docker compose pull
COMPOSE_PROFILES=$(all_profiles) docker compose build
}
run_ui_build() {
docker compose run --rm ui /lila/ui/build --update --clean-build --debug $@
}
setup_database() {
if [ "$SETUP_DATABASE" != "true" ]; then
echo "Skipping database setup"
return
fi
while ! docker compose exec mongodb mongo --eval "db.adminCommand('ping')" > /dev/null 2>&1; do
echo "Waiting for mongodb to be ready..."
sleep 1
done
[[ $SETUP_API_TOKENS == "true" ]] && params+=(--tokens)
docker compose run --rm python python /lila-db-seed/spamdb/spamdb.py \
--uri=mongodb://mongodb/lichess \
--drop-db \
--password=$PASSWORD \
--su-password=$SU_PASSWORD \
--streamers \
--coaches \
--es --es-host=elasticsearch:9200 \
"${params[@]}"
echo "Creating database indexes..."
docker compose exec mongodb mongo --quiet lichess /lila/bin/mongodb/indexes.js
docker compose exec mongodb mongo --quiet lichess /lila/bin/mongodb/create-trophy-kinds.js
docker compose run --rm python python /scripts/users.py
}
setup_bbppairings() {
if [ "$SETUP_BBPPAIRINGS" != "true" ]; then
return
fi
docker build -f docker/bbpPairings.Dockerfile . -t bbppairings
docker run --rm -v ./repos/bbpPairings:/mnt bbppairings make
## verify it compiled
./repos/bbpPairings/bbpPairings.exe
}
reset_database() {
load_config_to_env
setup_database
}
run_formatter() {
docker compose run --rm -w /lila ui pnpm run format
docker compose exec chessground pnpm run format || echo "Skipping chessground"
docker compose exec pgn_viewer pnpm run format || echo "Skipping pgn-viewer"
docker compose exec lila sbt scalafmtAll || docker compose run --rm --entrypoint "sbt scalafmtAll" lila
}
run_hostname() {
rust_cmd hostname
if [ ! -z "$(docker compose ps -a --services | xargs)" ]; then
docker compose down lila lila_ws nginx
docker compose up -d lila lila_ws nginx
fi
}
run_mobile() {
rust_cmd mobile
docker compose exec mobile adb pair $PHONE_IP:$PAIRING_PORT $PAIRING_CODE
docker compose exec mobile adb connect $PHONE_IP:$CONNECTION_PORT
}
rust_cmd() {
if command -v rustup &> /dev/null; then
# if the host has Rust installed, use it directly
cargo build --release --manifest-path command/Cargo.toml
./command/target/release/command "$@"
elif [ "$(uname)" = "Darwin" ]; then
docker run --rm -v "$PWD/command:/command" -w /command messense/cargo-zigbuild:0.18.3 \
cargo zigbuild --release --target universal2-apple-darwin
./command/target/universal2-apple-darwin/release/command "$@"
else
docker run --rm -v "$PWD/command:/command" -w /command messense/cargo-zigbuild:0.18.3 \
cargo zigbuild --release
./command/target/release/command "$@"
fi
load_config_to_env
}
load_config_to_env() {
export $(cat settings.env | xargs)
}
show_help() {
echo "Usage: $0 <action>"
echo "Actions:"
echo " start Start the containers"
echo " stop Stop the containers"
echo " restart Restart the containers"
echo " down Stop the containers and remove their volumes"
echo " build Pre-fetch and pre-build all the images necessary for the containers"
echo " format Run the code formatter to match Lichess code style"
echo " hostname Set the hostname to something different than the default localhost"
echo " mobile For mobile app development.Pair and connect to a mobile device"
echo " flutter Get the 'flutter run' command with the URL arguments pre-configured"
echo " db Reset and re-seed the database with fresh fake data"
echo " lila clean Run 'sbt clean' in the lila container. Useful if there are compilation errors"
echo " lila restart Restart the lila container to apply changes to the codebase"
echo " gitpod public Make http port 8080 public on the Gitpod instance"
echo " ui Compile the frontend code. Runs in watch mode to automatically recompile on changes"
}
case "$@" in
--help|-h)
show_help
exit 0
;;
start)
run_start
;;
stop)
run_stop
;;
restart)
run_stop && run_start
;;
down)
run_down
;;
build)
build_all_profiles
;;
format)
run_formatter
;;
hostname)
run_hostname
;;
mobile)
run_mobile
;;
db)
reset_database
;;
"lila clean")
docker compose run --rm --entrypoint bash lila -c "rm .sbtopts || true; sbt clean"
;;
"lila restart")
docker compose restart lila
;;
ui)
run_ui_build --rebuild
;;
"gitpod public")
rust_cmd gitpod_public
;;
"flutter")
rust_cmd flutter
;;
*)
show_help
exit 1
;;
esac