Keep existing data when moving to containerized MariaDB
authorJiri Stransky <jistr@redhat.com>
Fri, 3 Mar 2017 14:00:37 +0000 (15:00 +0100)
committerJiri Stransky <jistr@redhat.com>
Tue, 14 Mar 2017 13:52:55 +0000 (13:52 +0000)
We used named Docker volume for MariaDB storage, which meant that when
moving from BM to containerized wit MariaDB, we lost data and
reinitialized the storage from scratch.

With this commit we keep the data by mounting the original data into the
container.

We also need to make sure that file ownership is correct according to
the MariaDB container image used, and that Kolla bootstrap mechanisms
aren't retriggered, as they aren't idempotent.

Change-Id: I1fc955021c6dd83f1a366495dd8c7281fb9e7cc5

docker/services/database/mysql.yaml

index 46b856e..531c1eb 100644 (file)
@@ -82,17 +82,29 @@ outputs:
             perm: '0644'
       docker_config:
         step_2:
-          mysql_bootstrap:
+          mysql_data_ownership:
             start_order: 0
             detach: false
             image: *mysql_image
             net: host
+            user: root
+            # Kolla does only non-recursive chown
+            command: ['chown', '-R', 'mysql:', '/var/lib/mysql']
+            volumes:
+              - /var/lib/mysql:/var/lib/mysql
+          mysql_bootstrap:
+            start_order: 1
+            detach: false
+            image: *mysql_image
+            net: host
+            # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
+            command: ['bash', '-c', 'test -e /var/lib/mysql/mysql || kolla_start']
             volumes: &mysql_volumes
               - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
               - /var/lib/config-data/mysql/:/var/lib/kolla/config_files/src:ro
               - /etc/localtime:/etc/localtime:ro
               - /etc/hosts:/etc/hosts:ro
-              - mariadb:/var/lib/mysql/
+              - /var/lib/mysql:/var/lib/mysql
             environment:
               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
               - KOLLA_BOOTSTRAP=True
@@ -110,7 +122,7 @@ outputs:
                             - {get_param: MysqlRootPassword}
                             - {get_param: [DefaultPasswords, mysql_root_password]}
           mysql:
-            start_order: 1
+            start_order: 2
             image: *mysql_image
             restart: always
             net: host
@@ -128,8 +140,13 @@ outputs:
               - '/'
               - [ {get_param: DockerNamespace}, {get_param: DockerMysqlImage} ]
           volumes:
-            - "mariadb:/var/lib/mysql/:ro"
+            - "/var/lib/mysql:/var/lib/mysql/:ro"
             - "/var/lib/config-data/mysql/root:/root:ro" #provides .my.cnf
+      host_prep_tasks:
+        - name: create /var/lib/mysql
+          file:
+            path: /var/lib/mysql
+            state: directory
       upgrade_tasks:
         - name: Stop and disable mysql service
           tags: step2