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