3d996f7fec8d29fbb2d3b302ee45beb7e3a1ae48
[apex-tripleo-heat-templates.git] / docker / services / pacemaker / database / mysql.yaml
1 heat_template_version: pike
2
3 description: >
4   MySQL service deployment with pacemaker bundle
5
6 parameters:
7   DockerNamespace:
8     description: namespace
9     default: 'tripleoupstream'
10     type: string
11   DockerMysqlImage:
12     description: image
13     default: 'centos-binary-mariadb:latest'
14     type: string
15   DockerMysqlConfigImage:
16     description: The container image to use for the mysql config_volume
17     default: 'centos-binary-mariadb:latest'
18     type: string
19   EndpointMap:
20     default: {}
21     description: Mapping of service endpoint -> protocol. Typically set
22                  via parameter_defaults in the resource registry.
23     type: json
24   ServiceNetMap:
25     default: {}
26     description: Mapping of service_name -> network name. Typically set
27                  via parameter_defaults in the resource registry.  This
28                  mapping overrides those in ServiceNetMapDefaults.
29     type: json
30   DefaultPasswords:
31     default: {}
32     type: json
33   MysqlRootPassword:
34     type: string
35     hidden: true
36     default: ''
37   RoleName:
38     default: ''
39     description: Role name on which the service is applied
40     type: string
41   RoleParameters:
42     default: {}
43     description: Parameters specific to the role
44     type: json
45
46 resources:
47
48   ContainersCommon:
49     type: ../../containers-common.yaml
50
51   MysqlPuppetBase:
52     type: ../../../../puppet/services/pacemaker/database/mysql.yaml
53     properties:
54       EndpointMap: {get_param: EndpointMap}
55       ServiceNetMap: {get_param: ServiceNetMap}
56       DefaultPasswords: {get_param: DefaultPasswords}
57       RoleName: {get_param: RoleName}
58       RoleParameters: {get_param: RoleParameters}
59
60 outputs:
61   role_data:
62     description: Containerized service MySQL using composable services.
63     value:
64       service_name: {get_attr: [MysqlPuppetBase, role_data, service_name]}
65       config_settings:
66         map_merge:
67           - {get_attr: [MysqlPuppetBase, role_data, config_settings]}
68           - tripleo::profile::pacemaker::database::mysql_bundle::mysql_docker_image: &mysql_image
69               list_join:
70                 - '/'
71                 - - {get_param: DockerNamespace}
72                   - {get_param: DockerMysqlImage}
73       step_config: ""
74       # BEGIN DOCKER SETTINGS #
75       puppet_config:
76         config_volume: mysql
77         puppet_tags: file # set this even though file is the default
78         step_config:
79           list_join:
80             - "\n"
81             - - "['Mysql_datadir', 'Mysql_user', 'Mysql_database', 'Mysql_grant', 'Mysql_plugin'].each |String $val| { noop_resource($val) }"
82               - "exec {'wait-for-settle': command => '/bin/true' }"
83               - "include ::tripleo::profile::pacemaker::database::mysql_bundle"
84         config_image:
85           list_join:
86             - '/'
87             - [ {get_param: DockerNamespace}, {get_param: DockerMysqlConfigImage} ]
88       kolla_config:
89         /var/lib/kolla/config_files/mysql.json:
90           command: /usr/sbin/pacemaker_remoted
91           config_files:
92             - dest: /etc/libqb/force-filesystem-sockets
93               source: /dev/null
94               owner: root
95               perm: '0644'
96             - source: "/var/lib/kolla/config_files/src/*"
97               dest: "/"
98               merge: true
99               preserve_properties: true
100       docker_config:
101         step_1:
102           mysql_data_ownership:
103             start_order: 0
104             detach: false
105             image: *mysql_image
106             net: host
107             user: root
108             # Kolla does only non-recursive chown
109             command: ['chown', '-R', 'mysql:', '/var/lib/mysql']
110             volumes:
111               - /var/lib/mysql:/var/lib/mysql
112           mysql_bootstrap:
113             start_order: 1
114             detach: false
115             image: *mysql_image
116             net: host
117             # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
118             command: ['bash', '-c', 'test -e /var/lib/mysql/mysql || kolla_start']
119             volumes: &mysql_volumes
120               list_concat:
121                 - {get_attr: [ContainersCommon, volumes]}
122                 -
123                   - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
124                   - /var/lib/config-data/puppet-generated/mysql/:/var/lib/kolla/config_files/src:ro
125                   - /var/lib/mysql:/var/lib/mysql
126             environment:
127               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
128               - KOLLA_BOOTSTRAP=True
129               # NOTE(mandre) skip wsrep cluster status check
130               - KOLLA_KUBERNETES=True
131               -
132                 list_join:
133                   - '='
134                   - - 'DB_ROOT_PASSWORD'
135                     -
136                       yaql:
137                         expression: $.data.passwords.where($ != '').first()
138                         data:
139                           passwords:
140                             - {get_param: MysqlRootPassword}
141                             - {get_param: [DefaultPasswords, mysql_root_password]}
142         step_2:
143           mysql_init_bundle:
144             start_order: 1
145             detach: false
146             net: host
147             user: root
148             command:
149               - '/bin/bash'
150               - '-c'
151               - str_replace:
152                   template:
153                     list_join:
154                       - '; '
155                       - - "cp -a /tmp/puppet-etc/* /etc/puppet; echo '{\"step\": 2}' > /etc/puppet/hieradata/docker.json"
156                         - "FACTER_uuid=docker puppet apply --tags file,file_line,concat,augeas,TAGS -v -e 'CONFIG'"
157                   params:
158                     TAGS: 'pacemaker::resource::bundle,pacemaker::property,pacemaker::resource::ocf,pacemaker::constraint::order,pacemaker::constraint::colocation,galera_ready,mysql_database,mysql_grant,mysql_user'
159                     CONFIG: 'include ::tripleo::profile::base::pacemaker;include ::tripleo::profile::pacemaker::database::mysql_bundle'
160             image: *mysql_image
161             volumes:
162               - /etc/hosts:/etc/hosts:ro
163               - /etc/localtime:/etc/localtime:ro
164               - /etc/puppet:/tmp/puppet-etc:ro
165               - /usr/share/openstack-puppet/modules:/usr/share/openstack-puppet/modules:ro
166               - /etc/corosync/corosync.conf:/etc/corosync/corosync.conf:ro
167               - /dev/shm:/dev/shm:rw
168               - /var/lib/mysql:/var/lib/mysql:rw
169       host_prep_tasks:
170         - name: create /var/lib/mysql
171           file:
172             path: /var/lib/mysql
173             state: directory
174       upgrade_tasks:
175         - name: Stop and disable mysql service
176           tags: step2
177           service: name=mariadb state=stopped enabled=no