Merge "Refactor setup_docker_host.sh as host_prep_tasks"
[apex-tripleo-heat-templates.git] / docker / services / database / mysql.yaml
1 heat_template_version: pike
2
3 description: >
4   MySQL service deployment using puppet
5
6 parameters:
7   DockerMysqlImage:
8     description: image
9     type: string
10   DockerMysqlConfigImage:
11     description: The container image to use for the mysql config_volume
12     type: string
13   EndpointMap:
14     default: {}
15     description: Mapping of service endpoint -> protocol. Typically set
16                  via parameter_defaults in the resource registry.
17     type: json
18   ServiceData:
19     default: {}
20     description: Dictionary packing service data
21     type: json
22   ServiceNetMap:
23     default: {}
24     description: Mapping of service_name -> network name. Typically set
25                  via parameter_defaults in the resource registry.  This
26                  mapping overrides those in ServiceNetMapDefaults.
27     type: json
28   DefaultPasswords:
29     default: {}
30     type: json
31   RoleName:
32     default: ''
33     description: Role name on which the service is applied
34     type: string
35   RoleParameters:
36     default: {}
37     description: Parameters specific to the role
38     type: json
39   MysqlRootPassword:
40     type: string
41     hidden: true
42     default: ''
43   EnableInternalTLS:
44     type: boolean
45     default: false
46   InternalTLSCAFile:
47     default: '/etc/ipa/ca.crt'
48     type: string
49     description: Specifies the default CA cert to use if TLS is used for
50                  services in the internal network.
51
52 conditions:
53
54   internal_tls_enabled: {equals: [{get_param: EnableInternalTLS}, true]}
55
56 resources:
57
58   MysqlPuppetBase:
59     type: ../../../puppet/services/database/mysql.yaml
60     properties:
61       EndpointMap: {get_param: EndpointMap}
62       ServiceData: {get_param: ServiceData}
63       ServiceNetMap: {get_param: ServiceNetMap}
64       DefaultPasswords: {get_param: DefaultPasswords}
65       RoleName: {get_param: RoleName}
66       RoleParameters: {get_param: RoleParameters}
67
68 outputs:
69   role_data:
70     description: Containerized service MySQL using composable services.
71     value:
72       service_name: {get_attr: [MysqlPuppetBase, role_data, service_name]}
73       config_settings:
74         map_merge:
75           - {get_attr: [MysqlPuppetBase, role_data, config_settings]}
76           # Set PID file to what kolla mariadb bootstrap script expects
77           - tripleo::profile::base::database::mysql::mysql_server_options:
78               mysqld:
79                 pid-file: /var/lib/mysql/mariadb.pid
80               mysqld_safe:
81                 pid-file: /var/lib/mysql/mariadb.pid
82       step_config: &step_config
83         list_join:
84           - "\n"
85           - - "['Mysql_datadir', 'Mysql_user', 'Mysql_database', 'Mysql_grant', 'Mysql_plugin'].each |String $val| { noop_resource($val) }"
86             - {get_attr: [MysqlPuppetBase, role_data, step_config]}
87       # BEGIN DOCKER SETTINGS #
88       puppet_config:
89         config_volume: mysql
90         puppet_tags: file # set this even though file is the default
91         step_config: *step_config
92         config_image: &mysql_config_image {get_param: DockerMysqlConfigImage}
93       kolla_config:
94         /var/lib/kolla/config_files/mysql.json:
95           command: /usr/bin/mysqld_safe
96           config_files:
97             - source: "/var/lib/kolla/config_files/src/*"
98               dest: "/"
99               merge: true
100               preserve_properties: true
101             - source: "/var/lib/kolla/config_files/src-tls/*"
102               dest: "/"
103               merge: true
104               preserve_properties: true
105               optional: true
106           permissions:
107             - path: /var/lib/mysql
108               owner: mysql:mysql
109               recurse: true
110             - path: /etc/pki/tls/certs/mysql.crt
111               owner: mysql:mysql
112               optional: true
113             - path: /etc/pki/tls/private/mysql.key
114               owner: mysql:mysql
115               optional: true
116       docker_config:
117         # Kolla_bootstrap runs before permissions set by kolla_config
118         step_1:
119           mysql_init_logs:
120             image: &mysql_image {get_param: DockerMysqlImage}
121             privileged: false
122             user: root
123             volumes:
124               - /var/log/containers/mysql:/var/log/mariadb
125             command: ['/bin/bash', '-c', 'chown -R mysql:mysql /var/log/mariadb']
126         step_2:
127           mysql_bootstrap:
128             detach: false
129             image: *mysql_image
130             net: host
131             # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
132             command: ['bash', '-c', 'test -e /var/lib/mysql/mysql || kolla_start']
133             volumes: &mysql_volumes
134               list_concat:
135               -
136                 - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
137                 - /var/lib/config-data/puppet-generated/mysql/:/var/lib/kolla/config_files/src:ro
138                 - /etc/localtime:/etc/localtime:ro
139                 - /etc/hosts:/etc/hosts:ro
140                 - /var/lib/mysql:/var/lib/mysql
141                 - /var/log/containers/mysql:/var/log/mariadb
142               - if:
143                 - internal_tls_enabled
144                 - 
145                   - list_join:
146                     - ':'
147                     - - {get_param: InternalTLSCAFile}
148                       - {get_param: InternalTLSCAFile}
149                       - 'ro'
150                   - /etc/pki/tls/certs/mysql.crt:/var/lib/kolla/config_files/src-tls/etc/pki/tls/certs/mysql.crt:ro
151                   - /etc/pki/tls/private/mysql.key:/var/lib/kolla/config_files/src-tls/etc/pki/tls/private/mysql.key:ro
152                 - null 
153             environment:
154               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
155               - KOLLA_BOOTSTRAP=True
156               # NOTE(mandre) skip wsrep cluster status check
157               - KOLLA_KUBERNETES=True
158               -
159                 list_join:
160                   - '='
161                   - - 'DB_ROOT_PASSWORD'
162                     -
163                       yaql:
164                         expression: $.data.passwords.where($ != '').first()
165                         data:
166                           passwords:
167                             - {get_param: MysqlRootPassword}
168                             - {get_param: [DefaultPasswords, mysql_root_password]}
169           mysql:
170             start_order: 2
171             image: *mysql_image
172             restart: always
173             net: host
174             volumes: *mysql_volumes
175             environment:
176               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
177       docker_puppet_tasks:
178         # MySQL database initialization occurs only on single node
179         step_2:
180           config_volume: 'mysql_init_tasks'
181           puppet_tags: 'mysql_database,mysql_grant,mysql_user'
182           step_config: 'include ::tripleo::profile::base::database::mysql'
183           config_image: *mysql_config_image
184           volumes:
185             list_concat:
186             -
187               - /var/lib/mysql:/var/lib/mysql/:ro
188               - /var/log/containers/mysql:/var/log/mariadb
189               - /var/lib/config-data/mysql/root:/root:ro #provides .my.cnf
190             - if:
191               - internal_tls_enabled
192               - 
193                 - list_join:
194                   - ':'
195                   - - {get_param: InternalTLSCAFile}
196                     - {get_param: InternalTLSCAFile}
197                     - 'ro'
198                 - /etc/pki/tls/certs/mysql.crt:/var/lib/kolla/config_files/src-tls/etc/pki/tls/certs/mysql.crt:ro
199                 - /etc/pki/tls/private/mysql.key:/var/lib/kolla/config_files/src-tls/etc/pki/tls/private/mysql.key:ro
200               - null 
201       metadata_settings:
202         get_attr: [MysqlPuppetBase, role_data, metadata_settings]
203       host_prep_tasks:
204         - name: create persistent directories
205           file:
206             path: "{{ item }}"
207             state: directory
208           with_items:
209             - /var/log/containers/mysql
210             - /var/lib/mysql
211       upgrade_tasks:
212         - name: Stop and disable mysql service
213           tags: step2
214           service: name=mariadb state=stopped enabled=no