Skip to content

Commit

Permalink
[Spring-Cloud] Add a new parameter "--build-env" for app deploy (#4443)
Browse files Browse the repository at this point in the history
* fix: fix the deploy of gradle project with multiple modules

* add a new parameter --build-env

* fix typos

* fix

* fix

* fix

* fix

* fix

* fix

* fix test

* fix test

* fix test

* fix test

* fix test

* fix

* Update src/spring-cloud/HISTORY.md

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

* update ClientRequestError to ArgumentUsageError

* fix test

* fix test

* fix test

* update validator

* add new line

* update history

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>
  • Loading branch information
smile37773 and zhoxing-ms authored Feb 25, 2022
1 parent e59e6bd commit 47fd457
Show file tree
Hide file tree
Showing 15 changed files with 4,855 additions and 2,097 deletions.
6 changes: 6 additions & 0 deletions src/spring-cloud/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Release History
===============
3.0.1
---
* `az spring-cloud app deploy` has new preview argument "--build-env" to specify build module and jvm version and so on.
* Raise error when `az spring-cloud app deploy` setting "--target-modules" and "--runtime-version for enterprise tier.
* Fix the jvm option clearance in enterprise tier.

3.0.0
---
* New preview argument `az spring-cloud create` has new argument "--sku=Enterprise" to support Azure Spring Cloud Enterprise creation.
Expand Down
21 changes: 3 additions & 18 deletions src/spring-cloud/azext_spring_cloud/_buildservices_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# pylint: disable=too-few-public-methods, unused-argument, redefined-builtin
import sys
import requests
import json
from time import sleep
from requests.auth import HTTPBasicAuth
from knack.log import get_logger
Expand Down Expand Up @@ -57,14 +58,14 @@ def _get_upload_info(self):
except AttributeError as e:
raise AzureInternalError("Failed to get a SAS URL to upload context. Error: {}".format(e))

def _queue_build(self, relative_path=None, builder=None, target_module=None, runtime_version=None, app=None, **_):
def _queue_build(self, relative_path=None, builder=None, build_env=None, app=None, **_):
subscription = get_subscription_id(self.cmd.cli_ctx)
service_resource_id = '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.AppPlatform/Spring/{}'.format(subscription, self.resource_group, self.service)
properties = models.BuildProperties(
builder='{}/buildservices/default/builders/{}'.format(service_resource_id, builder),
agent_pool='{}/buildservices/default/agentPools/default'.format(service_resource_id),
relative_path=relative_path,
env=self._get_build_env(target_module, runtime_version))
env=json.loads(build_env) if build_env else None)
build = models.Build(properties=properties)
try:
return self.client.build_service.create_or_update_build(self.resource_group,
Expand All @@ -75,22 +76,6 @@ def _queue_build(self, relative_path=None, builder=None, target_module=None, run
except (AttributeError, CloudError) as e:
raise DeploymentError("Failed to create or update a build. Error: {}".format(e.message))

def _get_build_env(self, target_module, runtime_version):
if all(x is None for x in [target_module, runtime_version]):
return None
env = {}
if target_module:
env['BP_MAVEN_BUILT_MODULE'] = target_module

runtime_version_table = {
SupportedRuntimeValue.JAVA8: '8.*',
SupportedRuntimeValue.JAVA11: '11.*',
SupportedRuntimeValue.JAVA17: '17.*'
}
if runtime_version:
env['BP_JVM_VERSION'] = runtime_version_table.get(runtime_version, '11.*')
return env

def _wait_build_finished(self, build_result_id):
'''
Wait build result finished and stream the log during the waiting
Expand Down
10 changes: 7 additions & 3 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
validate_routes, validate_gateway_instance_count,
validate_api_portal_instance_count,
validate_buildpack_binding_exist, validate_buildpack_binding_not_exist,
validate_buildpack_binding_properties, validate_buildpack_binding_secrets)
validate_buildpack_binding_properties, validate_buildpack_binding_secrets,
validate_build_env, validate_target_module, validate_runtime_version)
from ._app_validator import (fulfill_deployment_param, active_deployment_exist,
ensure_not_active_deployment, validate_deloy_path, validate_deloyment_create_path,
validate_cpu, validate_memory, fulfill_deployment_param_or_warning, active_deployment_exist_or_warning)
Expand Down Expand Up @@ -268,7 +269,7 @@ def prepare_logs_argument(c):
for scope in ['spring-cloud app update', 'spring-cloud app deployment create', 'spring-cloud app deploy', 'spring-cloud app create']:
with self.argument_context(scope) as c:
c.argument('runtime_version', arg_type=get_enum_type(SupportedRuntimeValue),
help='Runtime version of used language')
help='Runtime version of used language', validator=validate_runtime_version)
c.argument('jvm_options', type=str, validator=validate_jvm_options,
help="A string containing jvm options, use '=' instead of ' ' for this argument to avoid bash parse error, eg: --jvm-options='-Xms1024m -Xmx2048m'")
c.argument('env', env_type)
Expand Down Expand Up @@ -303,7 +304,8 @@ def prepare_logs_argument(c):
'main_entry', options_list=[
'--main-entry', '-m'], help="A string containing the path to the .NET executable relative to zip root.")
c.argument(
'target_module', help='Child module to be deployed, required for multiple jar packages built from source code.', arg_group='Source Code deploy')
'target_module', help='Child module to be deployed, required for multiple jar packages built from source code.',
arg_group='Source Code deploy', validator=validate_target_module)
c.argument(
'version', help='Deployment version, keep unchanged if not set.')
c.argument(
Expand All @@ -318,6 +320,8 @@ def prepare_logs_argument(c):
'container_command', help='The command of the container image.', nargs='*', arg_group='Custom Container')
c.argument(
'container_args', help='The arguments of the container image.', nargs='*', arg_group='Custom Container')
c.argument(
'build_env', help='The key-value pairs of env used in build phase.', validator=validate_build_env)

with self.argument_context('spring-cloud app deploy') as c:
c.argument('source_path', arg_type=source_path_type, validator=validate_deloy_path)
Expand Down
15 changes: 15 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_validators_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def not_support_enterprise(cmd, namespace):
raise ClientRequestError("'{}' doesn't support for Enterprise tier Spring instance.".format(namespace.command))


def validate_build_env(cmd, namespace):
if namespace.build_env is not None and namespace.resource_group and namespace.service and not is_enterprise_tier(cmd, namespace.resource_group, namespace.service):
raise ArgumentUsageError("'--build-env' only supports for Enterprise tier Spring instance.")


def validate_target_module(cmd, namespace):
if namespace.target_module is not None and namespace.resource_group and namespace.service and is_enterprise_tier(cmd, namespace.resource_group, namespace.service):
raise ArgumentUsageError("'--target-module' doesn't support for Enterprise tier Spring instance.")


def validate_runtime_version(cmd, namespace):
if namespace.runtime_version is not None and namespace.resource_group and namespace.service and is_enterprise_tier(cmd, namespace.resource_group, namespace.service):
raise ArgumentUsageError("'--runtime-version' doesn't support for Enterprise tier Spring instance.")


def validate_builder_create(cmd, namespace):
client = get_client(cmd)
try:
Expand Down
4 changes: 4 additions & 0 deletions src/spring-cloud/azext_spring_cloud/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def app_deploy(cmd, client, resource_group, service, name,
registry_password=None,
container_command=None,
container_args=None,
build_env=None,
builder=None,
# deployment.settings
env=None,
Expand Down Expand Up @@ -266,6 +267,7 @@ def app_deploy(cmd, client, resource_group, service, name,
'registry_password': registry_password,
'container_command': container_command,
'container_args': container_args,
'build_env': build_env,
'builder': builder,
'no_wait': no_wait
}
Expand Down Expand Up @@ -308,6 +310,7 @@ def deployment_create(cmd, client, resource_group, service, app, name,
registry_password=None,
container_command=None,
container_args=None,
build_env=None,
builder=None,
# deployment.settings
skip_clone_settings=False,
Expand Down Expand Up @@ -356,6 +359,7 @@ def deployment_create(cmd, client, resource_group, service, app, name,
'cpu': cpu,
'memory': memory,
'instance_count': instance_count,
'build_env': build_env,
'builder': builder,
'no_wait': no_wait
}
Expand Down
Loading

0 comments on commit 47fd457

Please sign in to comment.