def push_image_to_project(project_name, registry, username, password, image, tag, expected_login_error_message=None, expected_error_message=None): _docker_api = DockerAPI() _docker_api.docker_login( registry, username, password, expected_error_message=expected_login_error_message) time.sleep(2) if expected_login_error_message != None: return _docker_api.docker_image_pull(image, tag=tag) time.sleep(2) new_harbor_registry, new_tag = _docker_api.docker_image_tag( r'{}:{}'.format(image, tag), r'{}/{}/{}'.format(registry, project_name, image)) time.sleep(2) _docker_api.docker_image_push( new_harbor_registry, new_tag, expected_error_message=expected_error_message) return r'{}/{}'.format(project_name, image), new_tag
def push_self_build_image_to_project(project_name, registry, username, password, image, tag, size=2, expected_login_error_message=None, expected_error_message=None): _docker_api = DockerAPI() _docker_api.docker_login( registry, username, password, expected_error_message=expected_login_error_message) time.sleep(2) if expected_login_error_message in [None, ""]: push_special_image_to_project( project_name, registry, username, password, image, tags=[tag], size=size, expected_login_error_message=expected_login_error_message, expected_error_message=expected_error_message) return r'{}/{}'.format(project_name, image), tag
def pull_harbor_image(registry, username, password, image, tag, expected_login_error_message = None, expected_error_message = None): _docker_api = DockerAPI() _docker_api.docker_login(registry, username, password, expected_error_message = expected_login_error_message) if expected_login_error_message != None: return time.sleep(2) _docker_api.docker_image_pull(r'{}/{}'.format(registry, image), tag = tag, expected_error_message = expected_error_message)
def push_special_image_to_project(project_name, registry, username, password, image, tags=None, size=1, expected_login_error_message=None, expected_error_message = None): _docker_api = DockerAPI() _docker_api.docker_login(registry, username, password, expected_error_message = expected_login_error_message) time.sleep(2) if expected_login_error_message != None: return return _docker_api.docker_image_build(r'{}/{}/{}'.format(registry, project_name, image), tags = tags, size=int(size), expected_error_message=expected_error_message)
def push_image_to_project(project_name, registry, username, password, image, tag): _docker_api = DockerAPI() _docker_api.docker_login(registry, username, password) time.sleep(2) _docker_api.docker_image_pull(image, tag = tag) time.sleep(2) new_harbor_registry, new_tag = _docker_api.docker_image_tag(image, r'{}/{}/{}'.format(registry, project_name, image)) time.sleep(2) _docker_api.docker_image_push(new_harbor_registry, new_tag) return r'{}/{}'.format(project_name, image), new_tag
def push_image_to_project(project_name, registry, username, password, image, tag, expected_login_error_message=None, expected_error_message=None, profix_for_image=None, new_image=None): print("Start to push image {}/{}/{}:{}".format(registry, project_name, image, tag)) _docker_api = DockerAPI() _docker_api.docker_login("docker", DOCKER_USER, DOCKER_PWD) _docker_api.docker_image_pull(image, tag=tag) _docker_api.docker_login( registry, username, password, expected_error_message=expected_login_error_message) time.sleep(2) if expected_login_error_message != None: return time.sleep(2) original_name = image image = new_image or image if profix_for_image == None: new_harbor_registry, new_tag = _docker_api.docker_image_tag( r'{}:{}'.format(original_name, tag), r'{}/{}/{}'.format(registry, project_name, image), tag=tag) else: new_harbor_registry, new_tag = _docker_api.docker_image_tag( r'{}:{}'.format(original_name, tag), r'{}/{}/{}/{}'.format(registry, project_name, profix_for_image, image), tag=tag) time.sleep(2) _docker_api.docker_image_push( new_harbor_registry, new_tag, expected_error_message=expected_error_message) return r'{}/{}'.format(project_name, image), new_tag