testing: touch MySQL files when starting bmoweb container draft
authorGregory Szorc <gps@mozilla.com>
Mon, 31 Jul 2017 15:27:28 -0700
changeset 11429 500f518b05bd5c1061291e47d5d313e6df21db00
parent 11428 13ef978e7d8c098ed56aa1aa2e6eb263f909bcf9
child 11430 248f4187095ae4b268c258989ef612963c628d39
push id1746
push userbmo:gps@mozilla.com
push dateThu, 03 Aug 2017 02:22:07 +0000
testing: touch MySQL files when starting bmoweb container See the inline comment for rationale. So hacky. MozReview-Commit-ID: 8NActQDyha5
testing/docker/builder-bmoweb/entrypoint.py
--- a/testing/docker/builder-bmoweb/entrypoint.py
+++ b/testing/docker/builder-bmoweb/entrypoint.py
@@ -108,16 +108,27 @@ with open(answers, 'wb') as fh:
 
     writeanswer(fh, 'db_user', db_user)
     writeanswer(fh, 'db_pass', db_pass)
     writeanswer(fh, 'db_name', db_name)
     writeanswer(fh, 'ADMIN_EMAIL', admin_email)
     writeanswer(fh, 'ADMIN_PASSWORD', admin_password)
     writeanswer(fh, 'urlbase', bmo_url)
 
+# There is a weird interaction between Docker, filesystems, and MySQL where
+# a subsequent container invocation can't access MySQL data from a previous
+# one. It is suspected this has something to do with overlayfs and accessing
+# data from previous layers. This can produce failures like ``Fatal error: Can't
+# open and lock privilege tables: Table storage engine for 'db' doesn't have
+# this option``.
+#
+# We work around it by chowning everything in /var/lib/mysql, which effectively
+# copies the file to the current filesystem layer.
+subprocess.check_call(['/bin/chown', '-R', 'mysql:mysql', '/var/lib/mysql'])
+
 # Start a MySQL process. mysqld_safe restarts the process when it
 # terminates, so don't use that.
 mysqld = subprocess.Popen([
     '/usr/sbin/mysqld',
     '--datadir=/var/lib/mysql',
     '--user=mysql',
     '--init-file=/tmp/mysql-init.sh'])
 
@@ -125,16 +136,17 @@ mysqld = subprocess.Popen([
 # ready.
 time_start = time.time()
 while True:
     try:
         print('attempting to connect to database...')
 
         if mysqld.poll() is not None:
             print('mysqld process exited %d' % mysqld.returncode)
+            time.sleep(500)
             sys.exit(1)
 
         # There appear to be race conditions between MySQL opening the socket
         # and MySQL actually responding. So we wait on a successful MySQL
         # connection before continuing.
         mysql.connector.connect(user=db_user, password=db_pass,
                                 unix_socket='/dev/shm/mysqld.sock')
         print('connected to MySQL database as %s' % db_user)