Skip to content

Commit

Permalink
feat(kpack): print out build logs after build result is succeeded or …
Browse files Browse the repository at this point in the history
…failed (Azure#4)
  • Loading branch information
Junyi Yi committed May 25, 2021
1 parent f068547 commit 8d78e35
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def load_arguments(self, _):

with self.argument_context('spring-cloud tanzu app') as c:
c.argument('service', service_name_type)
c.argument('name', name_type, help='Name of app.')

with self.argument_context('spring-cloud tanzu app create') as c:
c.argument('assign_endpoint', arg_type=get_three_state_flag(),
Expand Down
6 changes: 5 additions & 1 deletion src/spring-cloud/azext_spring_cloud/tanzu.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def tanzu_app_deploy(cmd, client, resource_group, service, name, artifact_path=N
builder="default-tanzu-builder",
name=name,
relative_path=relative_path,
env={"BP_JVM_VERSION": "8.*", "BP_MAVEN_BUILT_MODULE": target_module} if target_module else None)
env={"BP_MAVEN_BUILT_MODULE": target_module} if target_module else None)
# create or update build
logger.warning("[3/5] Creating or Updating build '{}'.".format(name))
build_result_id = None
Expand All @@ -234,6 +234,10 @@ def tanzu_app_deploy(cmd, client, resource_group, service, name, artifact_path=N
while result.properties.status == "Building" or result.properties.status == "Queuing":
sleep(5)
result = client.build_service.get_build_result(resource_group, service, name, build_result_name)
build_logs = client.build_service.get_build_result_log(resource_group, service, name, build_result_name, "all")
if build_logs and build_logs.properties and build_logs.properties.blob_url:
output = requests.get(build_logs.properties.blob_url).text
sys.stdout.write(output)
if result.properties.status != "Succeeded":
raise CLIError("Failed to get a successful build result.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from ._models_py3 import BuildContainerImageReference
from ._models_py3 import BuildProperties
from ._models_py3 import BuildResult
from ._models_py3 import BuildResultLog
from ._models_py3 import BuildResultLogProperties
from ._models_py3 import BuildResultProperties
from ._models_py3 import ConfigurationServiceGitPropertyValidateResult
from ._models_py3 import ConfigurationServiceProperties
Expand Down Expand Up @@ -47,6 +49,8 @@
from ._models import BuildContainerImageReference
from ._models import BuildProperties
from ._models import BuildResult
from ._models import BuildResultLog
from ._models import BuildResultLogProperties
from ._models import BuildResultProperties
from ._models import ConfigurationServiceGitPropertyValidateResult
from ._models import ConfigurationServiceProperties
Expand Down Expand Up @@ -88,6 +92,8 @@
'BuildContainerImageReference',
'BuildProperties',
'BuildResult',
'BuildResultLog',
'BuildResultLogProperties',
'BuildResultProperties',
'ConfigurationServiceGitPropertyValidateResult',
'ConfigurationServiceProperties',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,57 @@ def __init__(self, **kwargs):
self.properties = kwargs.get('properties', None)


class BuildResultLog(ProxyResource):
"""Build result log resource payload.
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Fully qualified resource Id for the resource.
:vartype id: str
:ivar name: The name of the resource.
:vartype name: str
:ivar type: The type of the resource.
:vartype type: str
:param properties: Properties of the build result log resource
:type properties:
~azure.mgmt.appplatform.v2021_03_01_preview.models.BuildResultLogProperties
"""

_validation = {
'id': {'readonly': True},
'name': {'readonly': True},
'type': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'properties': {'key': 'properties', 'type': 'BuildResultLogProperties'},
}

def __init__(self, **kwargs):
super(BuildResultLog, self).__init__(**kwargs)
self.properties = kwargs.get('properties', None)


class BuildResultLogProperties(Model):
"""Build result log resource properties payload.
:param blob_url: The public download URL of this build result log
:type blob_url: str
"""

_attribute_map = {
'blob_url': {'key': 'blobUrl', 'type': 'str'},
}

def __init__(self, **kwargs):
super(BuildResultLogProperties, self).__init__(**kwargs)
self.blob_url = kwargs.get('blob_url', None)


class BuildResultProperties(Model):
"""Build result resource properties payload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,57 @@ def __init__(self, *, properties=None, **kwargs) -> None:
self.properties = properties


class BuildResultLog(ProxyResource):
"""Build result log resource payload.
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Fully qualified resource Id for the resource.
:vartype id: str
:ivar name: The name of the resource.
:vartype name: str
:ivar type: The type of the resource.
:vartype type: str
:param properties: Properties of the build result log resource
:type properties:
~azure.mgmt.appplatform.v2021_03_01_preview.models.BuildResultLogProperties
"""

_validation = {
'id': {'readonly': True},
'name': {'readonly': True},
'type': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'properties': {'key': 'properties', 'type': 'BuildResultLogProperties'},
}

def __init__(self, *, properties=None, **kwargs) -> None:
super(BuildResultLog, self).__init__(**kwargs)
self.properties = properties


class BuildResultLogProperties(Model):
"""Build result log resource properties payload.
:param blob_url: The public download URL of this build result log
:type blob_url: str
"""

_attribute_map = {
'blob_url': {'key': 'blobUrl', 'type': 'str'},
}

def __init__(self, *, blob_url: str=None, **kwargs) -> None:
super(BuildResultLogProperties, self).__init__(**kwargs)
self.blob_url = blob_url


class BuildResultProperties(Model):
"""Build result resource properties payload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,77 @@ def get_build_result(

return deserialized
get_build_result.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Tanzu/{serviceName}/buildservice/default/builds/{buildName}/results/{buildResultName}'}

def get_build_result_log(
self, resource_group_name, service_name, build_name, build_result_name, build_result_log_name, custom_headers=None, raw=False, **operation_config):
"""Get a KPack build result log download URL.
:param resource_group_name: The name of the resource group that
contains the resource. You can obtain this value from the Azure
Resource Manager API or the portal.
:type resource_group_name: str
:param service_name: The name of the Service resource.
:type service_name: str
:param build_name: The name of the build resource.
:type build_name: str
:param build_result_name: The name of the build result resource.
:type build_result_name: str
:param build_result_log_name: The name of the build result log
resource.
:type build_result_log_name: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: BuildResultLog or ClientRawResponse if raw=true
:rtype:
~azure.mgmt.appplatform.v2021_03_01_preview.models.BuildResultLog or
~msrest.pipeline.ClientRawResponse
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
"""
# Construct URL
url = self.get_build_result_log.metadata['url']
path_format_arguments = {
'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'serviceName': self._serialize.url("service_name", service_name, 'str'),
'buildName': self._serialize.url("build_name", build_name, 'str'),
'buildResultName': self._serialize.url("build_result_name", build_result_name, 'str'),
'buildResultLogName': self._serialize.url("build_result_log_name", build_result_log_name, 'str')
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str', min_length=1)

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
if self.config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
if custom_headers:
header_parameters.update(custom_headers)
if self.config.accept_language is not None:
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

# Construct and send request
request = self._client.get(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
exp = CloudError(response)
exp.request_id = response.headers.get('x-ms-request-id')
raise exp

deserialized = None
if response.status_code == 200:
deserialized = self._deserialize('BuildResultLog', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
get_build_result_log.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AppPlatform/Tanzu/{serviceName}/buildservice/default/builds/{buildName}/results/{buildResultName}/logs/{buildResultLogName}'}

0 comments on commit 8d78e35

Please sign in to comment.