Example #1
0
File: build.py Project: rowhit/shub
 def show(self):
     super(_BuildProgress, self).show()
     if self.bar:
         self.bar.close()
     if not self.is_built:
         raise shub_exceptions.RemoteErrorException(
             "Build image operation failed")
Example #2
0
def build_cmd(target, version, skip_tests):
    client = utils.get_docker_client()
    project_dir = utils.get_project_dir()
    config = load_shub_config()
    image = config.get_image(target)
    _create_setup_py_if_not_exists()
    image_name = utils.format_image_name(image, version)
    if not os.path.exists(os.path.join(project_dir, 'Dockerfile')):
        raise shub_exceptions.BadParameterException(
            "Dockerfile is not found, please use shub image 'init' command")
    is_built = False
    for data in client.build(path=project_dir, tag=image_name, decode=True):
        if 'stream' in data:
            utils.debug_log("{}".format(data['stream'][:-1]))
            is_built = re.search(r'Successfully built ([0-9a-f]+)',
                                 data['stream'])
        elif 'error' in data:
            click.echo("Error {}:\n{}".format(data['error'],
                                              data['errorDetail']))
    if not is_built:
        raise shub_exceptions.RemoteErrorException(
            "Build image operation failed")
    click.echo("The image {} build is completed.".format(image_name))
    # Test the image content after building it
    if not skip_tests:
        test_cmd(target, version)
Example #3
0
def push_cmd(target, version, username, password, email, apikey, insecure):
    client = utils.get_docker_client()
    config = utils.load_release_config()
    image = config.get_image(target)
    username, password = utils.get_credentials(
        username=username,
        password=password,
        insecure=insecure,
        apikey=apikey,
        target_apikey=config.get_apikey(target))

    if username:
        _execute_push_login(client, image, username, password, email)
    image_name = utils.format_image_name(image, version)
    click.echo("Pushing {} to the registry.".format(image_name))
    for data in client.push(image_name,
                            stream=True,
                            decode=True,
                            insecure_registry=not bool(username)):
        if 'status' in data:
            utils.debug_log("Logs:{} {}".format(data['status'],
                                                data.get('progress')))
        if 'error' in data:
            click.echo("Error {}: {}".format(data['error'],
                                             data['errorDetail']))
            raise shub_exceptions.RemoteErrorException(
                "Docker push operation failed")
    click.echo("The image {} pushed successfully.".format(image_name))
Example #4
0
 def handle_event(self, event):
     if 'status' in event:
         self.handle_status_event(event)
     if 'error' in event:
         click.echo("Error {}: {}".format(event['error'],
                                          event['errorDetail']))
         raise shub_exceptions.RemoteErrorException(
             "Docker push operation failed")
Example #5
0
def _execute_push_login(client, image, username, password, email, reauth):
    """Login if there're provided credentials for the registry"""
    registry = get_image_registry(image)
    resp = client.login(username=username, password=password,
                        email=email, registry=registry, reauth=reauth)
    if not (isinstance(resp, dict) and 'username' in resp or
            ('Status' in resp and resp['Status'] == 'Login Succeeded')):
        raise shub_exceptions.RemoteErrorException(
            "Docker registry login error.")
    click.echo("Login to {} succeeded.".format(registry))
Example #6
0
 def handle_event(self, event):
     if 'error' in event and LOGIN_ERROR_MSG in event['error']:
         click.echo(
            "Something went wrong when trying to authenticate to Docker "
            "registry when pushing the image. Please ensure your "
            "credentials are correct and try again with --reauth flag.")
         raise shub_exceptions.RemoteErrorException(
             "Docker registry authentication error")
     super(_LoggedPushProgress, self).handle_event(event)
     if 'status' in event:
         self.handle_status_event(event)
Example #7
0
def _execute_push_login(client, image, username, password, email):
    """Login if there're provided credentials for the registry"""
    components = image.split('/')
    registry = components[0] if len(components) == 3 else None
    resp = client.login(username=username, password=password,
                        email=email, registry=registry, reauth=False)
    if not (isinstance(resp, dict) and 'username' in resp or
            ('Status' in resp and resp['Status'] == 'Login Succeeded')):
        raise shub_exceptions.RemoteErrorException(
            "Docker registry login error.")
    click.echo("Login to {} succeeded.".format(registry))