container: support bind mounted db data directory and mysql config
This commit is contained in:
@@ -28,6 +28,39 @@
|
||||
db_container_data: /data/db
|
||||
when: docker_database == 'mongo'
|
||||
|
||||
- name: Reset db container mount definition var
|
||||
set_fact:
|
||||
db_container_mount_definition: []
|
||||
|
||||
- name: Set up database container data bind mount
|
||||
when: docker_volume_type == 'bind'
|
||||
block:
|
||||
- name: Create db data bind mount directory for {{ docker_service_name }}
|
||||
file:
|
||||
path: "{{ docker_mounts_dir }}/db"
|
||||
state: directory
|
||||
|
||||
- name: Set db_container_mount_definition for db data bind mount
|
||||
set_fact:
|
||||
db_container_mount_definition: "{{ db_container_mount_definition + [{'source': docker_mounts_dir + '/db', 'target': db_container_data, 'type': 'bind'}] }}"
|
||||
|
||||
- name: Set up database container config bind mount
|
||||
when: db_config_mounts_needed
|
||||
block:
|
||||
- name: Put mariadb config in place
|
||||
template:
|
||||
src: mariadb.cnf.j2
|
||||
dest: "{{ docker_mounts_dir }}/mariadb.cnf"
|
||||
|
||||
- name: Set db_container_mount_definition for db config bind mount
|
||||
set_fact:
|
||||
db_container_mount_definition: "{{ db_container_mount_definition + [{'source': docker_mounts_dir + '/mariadb.cnf', 'target': '/etc/mysql/conf.d/custom.cnf', 'type': 'bind', 'read_only': true}] }}"
|
||||
|
||||
- name: Set db_container_mount_definition for db data named volume
|
||||
set_fact:
|
||||
db_container_mount_definition: "{{ db_container_mount_definition + [{'source': docker_service_name + '_db', 'target': db_container_data, 'type': 'volume'}] }}"
|
||||
when: docker_volume_type == 'named'
|
||||
|
||||
- name: Set db published ports var
|
||||
set_fact:
|
||||
db_published_ports: ["127.0.0.1:{{ ports[docker_service_name].db }}:{{ db_image_port }}"]
|
||||
@@ -41,8 +74,6 @@
|
||||
env: "{{ db_container_env | default(omit) }}"
|
||||
published_ports: "{{ db_published_ports | default(omit) }}"
|
||||
restart_policy: always
|
||||
mounts:
|
||||
- source: "{{ docker_service_name + '_db' }}"
|
||||
target: "{{ db_container_data }}"
|
||||
mounts: "{{ db_container_mount_definition }}"
|
||||
networks: "{{ container_networks | default(omit) }}"
|
||||
log_driver: local
|
||||
|
||||
Reference in New Issue
Block a user