| 
									
										
										
										
											2018-11-15 11:09:57 +08:00
										 |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-12 19:09:01 +08:00
										 |  |  | from g import templates_dir | 
					
						
							| 
									
										
										
										
											2019-03-18 15:07:19 +08:00
										 |  |  | from .configs import parse_versions | 
					
						
							| 
									
										
										
										
											2018-11-15 11:09:57 +08:00
										 |  |  | from .jinja import render_jinja | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | docker_compose_template_path = os.path.join(templates_dir, 'docker_compose', 'docker-compose.yml.jinja') | 
					
						
							| 
									
										
										
										
											2019-03-12 19:09:01 +08:00
										 |  |  | docker_compose_yml_path = '/compose_location/docker-compose.yml' | 
					
						
							| 
									
										
										
										
											2018-11-15 11:09:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-18 15:07:19 +08:00
										 |  |  | # render docker-compose | 
					
						
							| 
									
										
										
										
											2020-02-10 23:46:26 +08:00
										 |  |  | def prepare_docker_compose(configs, with_clair, with_trivy, with_notary, with_chartmuseum): | 
					
						
							| 
									
										
										
										
											2019-03-18 15:07:19 +08:00
										 |  |  |     versions = parse_versions() | 
					
						
							|  |  |  |     VERSION_TAG = versions.get('VERSION_TAG') or 'dev' | 
					
						
							| 
									
										
										
										
											2018-11-15 11:09:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     rendering_variables = { | 
					
						
							|  |  |  |         'version': VERSION_TAG, | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:21 +08:00
										 |  |  |         'reg_version': VERSION_TAG, | 
					
						
							| 
									
										
										
										
											2019-03-18 15:07:19 +08:00
										 |  |  |         'redis_version': VERSION_TAG, | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:21 +08:00
										 |  |  |         'notary_version': VERSION_TAG, | 
					
						
							|  |  |  |         'clair_version': VERSION_TAG, | 
					
						
							|  |  |  |         'clair_adapter_version': VERSION_TAG, | 
					
						
							|  |  |  |         'trivy_adapter_version': VERSION_TAG, | 
					
						
							|  |  |  |         'chartmuseum_version': VERSION_TAG, | 
					
						
							| 
									
										
										
										
											2018-11-15 11:09:57 +08:00
										 |  |  |         'data_volume': configs['data_volume'], | 
					
						
							|  |  |  |         'log_location': configs['log_location'], | 
					
						
							| 
									
										
										
										
											2019-03-12 19:09:01 +08:00
										 |  |  |         'protocol': configs['protocol'], | 
					
						
							| 
									
										
										
										
											2019-04-02 20:08:26 +08:00
										 |  |  |         'http_port': configs['http_port'], | 
					
						
							| 
									
										
										
										
											2019-08-26 15:04:57 +08:00
										 |  |  |         'external_redis': configs['external_redis'], | 
					
						
							|  |  |  |         'external_database': configs['external_database'], | 
					
						
							| 
									
										
										
										
											2018-11-15 11:09:57 +08:00
										 |  |  |         'with_notary': with_notary, | 
					
						
							|  |  |  |         'with_clair': with_clair, | 
					
						
							| 
									
										
										
										
											2020-02-10 23:46:26 +08:00
										 |  |  |         'with_trivy': with_trivy, | 
					
						
							| 
									
										
										
										
											2018-11-15 11:09:57 +08:00
										 |  |  |         'with_chartmuseum': with_chartmuseum | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 13:47:55 +08:00
										 |  |  |     # if configs.get('registry_custom_ca_bundle_path'): | 
					
						
							|  |  |  |     #     rendering_variables['registry_custom_ca_bundle_path'] = configs.get('registry_custom_ca_bundle_path') | 
					
						
							|  |  |  |     #     rendering_variables['custom_ca_required'] = True | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 14:18:28 +08:00
										 |  |  |     # for gcs | 
					
						
							| 
									
										
										
										
											2019-04-02 20:08:26 +08:00
										 |  |  |     storage_config = configs.get('storage_provider_config') or {} | 
					
						
							| 
									
										
										
										
											2019-05-05 16:02:01 +08:00
										 |  |  |     if storage_config.get('keyfile') and configs['storage_provider_name'] == 'gcs': | 
					
						
							| 
									
										
										
										
											2019-04-02 20:08:26 +08:00
										 |  |  |         rendering_variables['gcs_keyfile'] = storage_config['keyfile'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 14:18:28 +08:00
										 |  |  |     # for http | 
					
						
							| 
									
										
										
										
											2019-04-03 16:19:04 +08:00
										 |  |  |     if configs['protocol'] == 'https': | 
					
						
							|  |  |  |         rendering_variables['cert_key_path'] = configs['cert_key_path'] | 
					
						
							|  |  |  |         rendering_variables['cert_path'] = configs['cert_path'] | 
					
						
							| 
									
										
										
										
											2019-04-30 17:05:27 +08:00
										 |  |  |         rendering_variables['https_port'] = configs['https_port'] | 
					
						
							| 
									
										
										
										
											2019-04-03 16:19:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 13:47:55 +08:00
										 |  |  |     # internal cert pairs | 
					
						
							|  |  |  |     rendering_variables['internal_tls'] = configs['internal_tls'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 14:18:28 +08:00
										 |  |  |     # for uaa | 
					
						
							| 
									
										
										
										
											2019-05-06 16:32:00 +08:00
										 |  |  |     uaa_config = configs.get('uaa') or {} | 
					
						
							|  |  |  |     if uaa_config.get('ca_file'): | 
					
						
							|  |  |  |         rendering_variables['uaa_ca_file'] = uaa_config['ca_file'] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 14:18:28 +08:00
										 |  |  |     # for log | 
					
						
							|  |  |  |     log_ep_host = configs.get('log_ep_host') | 
					
						
							|  |  |  |     if log_ep_host: | 
					
						
							|  |  |  |         rendering_variables['external_log_endpoint'] = True | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 15:17:35 +08:00
										 |  |  |     render_jinja(docker_compose_template_path, docker_compose_yml_path,  mode=0o644, **rendering_variables) |