Fix containerized zaqar-api db_sync
[apex-tripleo-heat-templates.git] / docker / services / zaqar.yaml
1 heat_template_version: pike
2
3 description: >
4   OpenStack containerized Zaqar services
5
6 parameters:
7   DockerZaqarImage:
8     description: image
9     type: string
10   DockerZaqarConfigImage:
11     description: The container image to use for the zaqar config_volume
12     type: string
13   ZaqarManagementStore:
14     type: string
15     description: The management store for Zaqar
16     default: mongodb
17   EndpointMap:
18     default: {}
19     description: Mapping of service endpoint -> protocol. Typically set
20                  via parameter_defaults in the resource registry.
21     type: json
22   ServiceData:
23     default: {}
24     description: Dictionary packing service data
25     type: json
26   ServiceNetMap:
27     default: {}
28     description: Mapping of service_name -> network name. Typically set
29                  via parameter_defaults in the resource registry.  This
30                  mapping overrides those in ServiceNetMapDefaults.
31     type: json
32   DefaultPasswords:
33     default: {}
34     type: json
35   RoleName:
36     default: ''
37     description: Role name on which the service is applied
38     type: string
39   RoleParameters:
40     default: {}
41     description: Parameters specific to the role
42     type: json
43   EnableInternalTLS:
44     type: boolean
45     default: false
46
47 conditions:
48   zaqar_management_store_sqlalchemy: {equals : [{get_param: ZaqarManagementStore}, 'sqlalchemy']}
49   internal_tls_enabled: {get_param: EnableInternalTLS}
50
51 resources:
52
53   ContainersCommon:
54     type: ./containers-common.yaml
55
56   MySQLClient:
57     type: ../../puppet/services/database/mysql-client.yaml
58
59   ZaqarBase:
60     type: ../../puppet/services/zaqar-api.yaml
61     properties:
62       EndpointMap: {get_param: EndpointMap}
63       ServiceData: {get_param: ServiceData}
64       ServiceNetMap: {get_param: ServiceNetMap}
65       DefaultPasswords: {get_param: DefaultPasswords}
66       RoleName: {get_param: RoleName}
67       RoleParameters: {get_param: RoleParameters}
68       EnableInternalTLS: {get_param: EnableInternalTLS}
69
70 outputs:
71   role_data:
72     description: Role data for the Zaqar API role.
73     value:
74       service_name: {get_attr: [ZaqarBase, role_data, service_name]}
75       config_settings: {get_attr: [ZaqarBase, role_data, config_settings]}
76       step_config: &step_config
77         list_join:
78           - "\n"
79           - - {get_attr: [ZaqarBase, role_data, step_config]}
80             - {get_attr: [MySQLClient, role_data, step_config]}
81       service_config_settings: {get_attr: [ZaqarBase, role_data, service_config_settings]}
82       # BEGIN DOCKER SETTINGS
83       puppet_config:
84         config_volume: zaqar
85         puppet_tags: zaqar_config
86         step_config: *step_config
87         config_image: {get_param: DockerZaqarConfigImage}
88       kolla_config:
89         /var/lib/kolla/config_files/zaqar.json:
90           command: /usr/sbin/httpd -DFOREGROUND
91           config_files:
92             - source: "/var/lib/kolla/config_files/src/*"
93               dest: "/"
94               merge: true
95               preserve_properties: true
96         /var/lib/kolla/config_files/zaqar_websocket.json:
97           command: /usr/bin/zaqar-server --config-file /etc/zaqar/zaqar.conf --config-file /etc/zaqar/1.conf
98           config_files:
99             - source: "/var/lib/kolla/config_files/src/*"
100               dest: "/"
101               merge: true
102               preserve_properties: true
103           permissions:
104             - path: /var/log/zaqar
105               owner: zaqar:zaqar
106               recurse: true
107       docker_config:
108         map_merge:
109           -
110             if:
111             - zaqar_management_store_sqlalchemy
112             -
113               step_2:
114                 zaqar_init_log:
115                   image: &zaqar_image {get_param: DockerZaqarImage}
116                   user: root
117                   volumes:
118                     - /var/log/containers/zaqar:/var/log/zaqar
119                   command: ['/bin/bash', '-c', 'chown -R zaqar:zaqar /var/log/zaqar']
120               step_3:
121                 zaqar_db_sync:
122                   image: *zaqar_image
123                   net: host
124                   privileged: false
125                   detach: false
126                   user: root
127                   volumes:
128                     list_concat:
129                       - {get_attr: [ContainersCommon, volumes]}
130                       -
131                         - /var/lib/config-data/zaqar/etc/zaqar/:/etc/zaqar/:ro
132                         - /var/log/containers/zaqar:/var/log/zaqar
133                         - /var/log/containers/httpd/zaqar:/var/log/httpd
134                   command: "/usr/bin/bootstrap_host_exec zaqar_api su zaqar -s /bin/bash -c 'zaqar-sql-db-manage upgrade head'"
135             - {}
136           - step_4:
137               zaqar:
138                 image: *zaqar_image
139                 net: host
140                 privileged: false
141                 restart: always
142                 # NOTE(mandre) kolla image changes the user to 'zaqar', we need it
143                 # to be root to run httpd
144                 user: root
145                 volumes:
146                   list_concat:
147                     - {get_attr: [ContainersCommon, volumes]}
148                     -
149                       - /var/lib/kolla/config_files/zaqar.json:/var/lib/kolla/config_files/config.json:ro
150                       - /var/lib/config-data/puppet-generated/zaqar/:/var/lib/kolla/config_files/src:ro
151                       - /var/log/containers/zaqar:/var/log/zaqar
152                       -
153                         if:
154                           - internal_tls_enabled
155                           - /etc/pki/tls/certs/httpd:/etc/pki/tls/certs/httpd:ro
156                           - ''
157                       -
158                         if:
159                           - internal_tls_enabled
160                           - /etc/pki/tls/private/httpd:/etc/pki/tls/private/httpd:ro
161                           - ''
162                 environment:
163                   - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
164               zaqar_websocket:
165                 image: *zaqar_image
166                 net: host
167                 privileged: false
168                 restart: always
169                 volumes:
170                   list_concat:
171                     - {get_attr: [ContainersCommon, volumes]}
172                     -
173                       - /var/lib/kolla/config_files/zaqar_websocket.json:/var/lib/kolla/config_files/config.json:ro
174                       - /var/lib/config-data/puppet-generated/zaqar/:/var/lib/kolla/config_files/src:ro
175                       - /var/log/containers/zaqar:/var/log/zaqar
176                 environment:
177                   - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
178       host_prep_tasks:
179         - name: create persistent logs directory
180           file:
181             path: /var/log/containers/zaqar
182             state: directory
183       upgrade_tasks:
184         - name: Stop and disable zaqar service
185           tags: step2
186           service: name=httpd state=stopped enabled=no
187       metadata_settings:
188         get_attr: [ZaqarBase, role_data, metadata_settings]