Merge "scenario001: containerize services for CI"
[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   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   RoleName:
34     default: ''
35     description: Role name on which the service is applied
36     type: string
37   RoleParameters:
38     default: {}
39     description: Parameters specific to the role
40     type: json
41   MysqlRootPassword:
42     type: string
43     hidden: true
44     default: ''
45
46 resources:
47
48   MysqlPuppetBase:
49     type: ../../../puppet/services/database/mysql.yaml
50     properties:
51       EndpointMap: {get_param: EndpointMap}
52       ServiceNetMap: {get_param: ServiceNetMap}
53       DefaultPasswords: {get_param: DefaultPasswords}
54       RoleName: {get_param: RoleName}
55       RoleParameters: {get_param: RoleParameters}
56
57 outputs:
58   role_data:
59     description: Containerized service MySQL using composable services.
60     value:
61       service_name: {get_attr: [MysqlPuppetBase, role_data, service_name]}
62       config_settings:
63         map_merge:
64           - {get_attr: [MysqlPuppetBase, role_data, config_settings]}
65           # Set PID file to what kolla mariadb bootstrap script expects
66           - tripleo::profile::base::database::mysql::mysql_server_options:
67               mysqld:
68                 pid-file: /var/lib/mysql/mariadb.pid
69               mysqld_safe:
70                 pid-file: /var/lib/mysql/mariadb.pid
71       step_config: &step_config
72         list_join:
73           - "\n"
74           - - "['Mysql_datadir', 'Mysql_user', 'Mysql_database', 'Mysql_grant', 'Mysql_plugin'].each |String $val| { noop_resource($val) }"
75             - {get_attr: [MysqlPuppetBase, role_data, step_config]}
76       # BEGIN DOCKER SETTINGS #
77       puppet_config:
78         config_volume: mysql
79         puppet_tags: file # set this even though file is the default
80         step_config: *step_config
81         config_image: &mysql_config_image
82           list_join:
83             - '/'
84             - [ {get_param: DockerNamespace}, {get_param: DockerMysqlConfigImage} ]
85       kolla_config:
86         /var/lib/kolla/config_files/mysql.json:
87           command: /usr/bin/mysqld_safe
88           permissions:
89             - path: /var/lib/mysql
90               owner: mysql:mysql
91               recurse: true
92       docker_config:
93         # Kolla_bootstrap runs before permissions set by kolla_config
94         step_1:
95           mysql_init_logs:
96             image: &mysql_image
97               list_join:
98                 - '/'
99                 - [ {get_param: DockerNamespace}, {get_param: DockerMysqlImage} ]
100             privileged: false
101             user: root
102             volumes:
103               - /var/log/containers/mysql:/var/log/mariadb
104             command: ['/bin/bash', '-c', 'chown -R mysql:mysql /var/log/mariadb']
105         step_2:
106           mysql_bootstrap:
107             detach: false
108             image: *mysql_image
109             net: host
110             # Kolla bootstraps aren't idempotent, explicitly checking if bootstrap was done
111             command: ['bash', '-c', 'test -e /var/lib/mysql/mysql || kolla_start']
112             volumes: &mysql_volumes
113               - /var/lib/kolla/config_files/mysql.json:/var/lib/kolla/config_files/config.json
114               - /var/lib/config-data/mysql/etc/my.cnf.d:/etc/my.cnf.d:ro
115               - /etc/localtime:/etc/localtime:ro
116               - /etc/hosts:/etc/hosts:ro
117               - /var/lib/mysql:/var/lib/mysql
118               - /var/log/containers/mysql:/var/log/mariadb
119             environment:
120               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
121               - KOLLA_BOOTSTRAP=True
122               # NOTE(mandre) skip wsrep cluster status check
123               - KOLLA_KUBERNETES=True
124               -
125                 list_join:
126                   - '='
127                   - - 'DB_ROOT_PASSWORD'
128                     -
129                       yaql:
130                         expression: $.data.passwords.where($ != '').first()
131                         data:
132                           passwords:
133                             - {get_param: MysqlRootPassword}
134                             - {get_param: [DefaultPasswords, mysql_root_password]}
135           mysql:
136             start_order: 2
137             image: *mysql_image
138             restart: always
139             net: host
140             volumes: *mysql_volumes
141             environment:
142               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
143       docker_puppet_tasks:
144         # MySQL database initialization occurs only on single node
145         step_2:
146           config_volume: 'mysql_init_tasks'
147           puppet_tags: 'mysql_database,mysql_grant,mysql_user'
148           step_config: 'include ::tripleo::profile::base::database::mysql'
149           config_image: *mysql_config_image
150           volumes:
151             - /var/lib/mysql:/var/lib/mysql/:ro
152             - /var/log/containers/mysql:/var/log/mariadb
153             - /var/lib/config-data/mysql/root:/root:ro #provides .my.cnf
154       host_prep_tasks:
155         - name: create persistent directories
156           file:
157             path: "{{ item }}"
158             state: directory
159           with_items:
160             - /var/log/containers/mysql
161             - /var/lib/mysql
162       upgrade_tasks:
163         - name: Stop and disable mysql service
164           tags: step2
165           service: name=mariadb state=stopped enabled=no