Keep existing data when moving to containerized MariaDB

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
This commit is contained in:
Jiri Stransky 2017-03-03 15:00:37 +01:00
parent a681b98564
commit cd88f4d8e9
1 changed files with 21 additions and 4 deletions

View 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