Skip to content

Commit 3b3e662

Browse files
committed
Ship a database snapshot with the docker image, to speed up first use
- Legacy-Id: 19451
1 parent 19409b9 commit 3b3e662

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

docker/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ RUN rm /master.zip
109109
# Colorize the bash shell
110110
RUN sed -i 's/#force_color_prompt=/force_color_prompt=/' /root/.bashrc
111111

112+
# Make a database dump available as part of the image, for if a user doesn't
113+
# have one installed locally yet - this saves a bunch of time then
114+
ADD https://www.ietf.org/lib/dt/sprint/ietf_utf8.sql.gz /
115+
RUN pigz -v -d /ietf_utf8.sql.gz && \
116+
sed -i -e 's/ENGINE=MyISAM/ENGINE=InnoDB/' /ietf_utf8.sql
117+
RUN service mariadb start && \
118+
echo "This sequence will take a long time, please be patient" && \
119+
mysqladmin -u root --default-character-set=utf8 create ietf_utf8 && \
120+
bash -c "cd /mariadb-sys-master && mysql --user root < sys_10.sql" && \
121+
bash -c "mysql --user root ietf_utf8 <<< \"GRANT ALL PRIVILEGES ON *.* TO django@localhost IDENTIFIED BY 'RkTkDPFnKpko'; FLUSH PRIVILEGES;\"" && \
122+
bash -c "mysql --user=django --password=RkTkDPFnKpko -f ietf_utf8 < /ietf_utf8.sql" && \
123+
service mariadb stop && \
124+
rm -rf /ietf_utf8.sql /mariadb-sys-master && \
125+
mv /var/lib/mysql /
126+
112127
# Copy the startup file
113128
COPY docker-init.sh /docker-init.sh
114129
RUN chmod +x /docker-init.sh

docker/docker-init.sh

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ fi
1010
service rsyslog start
1111

1212
if [ -z "$(ls -A $MYSQLDIR/mysql 2>/dev/null)" ]; then
13-
echo "WARNING: Database seems to be empty."
14-
mysql_install_db > /dev/null || exit 1
13+
can=$(date -r /mysql +%s)
14+
now=$(date +%s)
15+
age=$((($now - $can)/86400))
16+
echo "NOTE: Database empty; populating it from canned snapshot ($age days old)"
17+
echo " This will take a little while..."
18+
cp -r /mysql/* $MYSQLDIR
1519
fi
1620

1721
service mariadb start
1822

1923
if ! service mariadb status; then
20-
echo "ERROR: MySQL isn't running."
24+
echo "ERROR: MySQL didn't start. Here are some possible causes:"
25+
echo "-------------------------------------------------------------------"
2126
grep mysqld /var/log/syslog
27+
echo "-------------------------------------------------------------------"
28+
echo "Such errors are usually due to a corrupt or outdated database."
29+
echo "Remove your local database and let the image install a clean copy."
2230
exit 1
2331
fi
2432

@@ -27,16 +35,6 @@ if [ ! -f /root/src/ietf/settings_local.py ]; then
2735
cp /root/src/docker/settings_local.py /root/src/ietf/settings_local.py
2836
fi
2937

30-
if [ ! -d $MYSQLDIR/ietf_utf8 ]; then
31-
echo "WARNING: IETF database seems to be missing; populating it from dump."
32-
mysqladmin -u root --default-character-set=utf8 create ietf_utf8
33-
pushd /mariadb-sys-master || exit
34-
mysql -u root < sys_10.sql
35-
popd || exit
36-
mysql -u root ietf_utf8 <<< "GRANT ALL PRIVILEGES ON *.* TO django@localhost IDENTIFIED BY 'RkTkDPFnKpko'; FLUSH PRIVILEGES;"
37-
/root/src/docker/updatedb
38-
fi
39-
4038
for sub in \
4139
test/id \
4240
test/staging \

0 commit comments

Comments
 (0)