示例#1
0
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
示例#2
0
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
示例#3
0
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)
示例#4
0
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)
示例#5
0
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
示例#6
0
文件: repository.py 项目: zjcy/harbor
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