-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdocker-compose.yml
41 lines (38 loc) · 1.39 KB
/
docker-compose.yml
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
version: "3.8"
services:
mysql:
image: mysql:8.0
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_DATABASE: wca_development
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql
db_restore:
image: ubuntu:20.04
depends_on:
- mysql
entrypoint: >
sh -c "
apt update && apt install curl unzip mysql-client wget -y &&
result=$(mysql -h mysql -sN -u root -e 'use wca_development; select datediff(now(), max(results_posted_at)) from Competitions;' || echo 999) &&
echo 'Days since last update: ' $result &&
if [ -n \"$result\" ] && [ $result -lt 7 ]; then
echo 'Database is already up to date, skipping restoration.'
exit 0
else
echo 'Database is outdated, restoring...'
fi &&
echo 'Downloading WCA database dump, this may take a while...' &&
wget -q https://www.worldcubeassociation.org/wst/wca-developer-database-dump.zip &&
rm -rf wca-developer-database-dump.sql &&
unzip wca-developer-database-dump.zip &&
echo 'Restoring WCA database. This also may take a while...' &&
mysql -h mysql -u root -e 'drop database if exists wca_development; create database wca_development; use wca_development; source wca-developer-database-dump.sql;' &&
echo 'Restoration complete!'
"
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data: