def get_replicas(self, service): if 'deploy' not in service: raise DeploymentError('Could not find a deploy section in docker-stack.yml.') # Handle global services if 'mode' in service['deploy'] and service['deploy']['mode'].strip() == 'global'.strip(): return 'global' if 'replicas' not in service['deploy']: raise DeploymentError('Could not find the "replicas" attribute in docker-stack.yml.') return service['deploy']['replicas']
def run_step(self, pipeline_data): for i, service in pipeline_data_utils.get_enumerated_services( pipeline_data): image_data = service[data_defs.S_IMAGE] self.log.debug('Image data is "%s"', image_data) if image_data[data_defs.IMG_IS_SEMVER]: tags_url = self.get_tags_url(image_data) self.log.debug('Got url for tag fetching "%s"', tags_url) try: image_data[ data_defs.IMG_TAGS] = self.get_tags_from_registry( image_data, tags_url) self.log.debug('Tags set to "%s"', image_data[data_defs.IMG_TAGS]) except Exception as e: self.log.info('Fail to get tags for url {} {}'.format( tags_url, e)) if "404" in str(e): raise DeploymentError( 'There are no images named {} in the Docker registry, as specified in the docker-stack.yml. Misspelling or not pushed yet?' .format(image_data[data_defs.IMG_NAME])) else: raise e pipeline_data[data_defs.SERVICES][i][ data_defs.S_IMAGE] = image_data return pipeline_data
def verify_parsed_environment(self, pipeline_data): for _, service in pipeline_data_utils.get_parsed_services(pipeline_data): if 'environment' in service: if not isinstance(service['environment'], (dict,)): raise DeploymentError('Malformed docker-stack file. ' 'Service environment should be on the ' 'format `name: value`')
def run_step(self, pipeline_data): file_path = pipeline_data[data_defs.STACK_FILE_PATH] try: with open(file_path, 'r') as content_file: raw_data = content_file.read() pipeline_data[data_defs.STACK_FILE_RAW_CONTENT] = raw_data pipeline_data[data_defs.STACK_FILE_PARSED_CONTENT] = yaml.load( raw_data) return pipeline_data except yaml.YAMLError as yaml_err: if hasattr(yaml_err, 'problem_mark'): mark = yaml_err.problem_mark raise DeploymentError( f'Error when parsing docker-stack.yml ' f'(position {mark.line+1}:{mark.column+1}): {yaml_err}') else: raise DeploymentError( f'Error when parsing docker-stack.yml (): {yaml_err}') except FileNotFoundError: raise DeploymentError('No docker-stack.yml file found')
def has_image(self, service): if not 'image' in service: raise DeploymentError('Service is missing image')
def parse_version(self, service): match = re.match(regex.get_image_version_regex(), service['image']) if match: return match.group(3) raise DeploymentError('Image is missing version')
def parse_image_name(self, service): match = re.match(regex.get_image_name_regex(), service['image']) if match: return match.group(2) raise DeploymentError('Image is missing image name')
def verify_restart_policy(self, policy_struct): if not ('condition' in policy_struct and 'delay' in policy_struct and 'max_attempts' in policy_struct): raise DeploymentError('docker-stack.yml has bad restart policy')
def has_restart_policy(self, service): if not 'deploy' in service or not 'restart_policy' in service['deploy']: raise DeploymentError('docker-stack.yml missing restart policy')
def verify_deploy_labels(self, pipeline_data): for service in pipeline_data_utils.get_services(pipeline_data): if not isinstance(service[data_defs.S_DEPLOY_LABELS], (list,)): raise DeploymentError('Malformed docker-stack file. ' 'Service deploy labels should be on the ' 'format `name=value`')
def verify_services(self, pipeline_data): services = pipeline_data[data_defs.SERVICES] if not isinstance(services, (list,)): raise DeploymentError('Malformed docker-stack file. ' 'Services is not a list.')
def verify_logging_policy(self, policy_struct): if not ('options' in policy_struct and 'max-size' in policy_struct['options'] and 'max-file' in policy_struct['options']): raise DeploymentError('docker-stack.yml has bad logging policy')
def has_logging_policy(self, service): if not 'logging' in service: raise DeploymentError('docker-stack.yml missing logging policy')