Skip to content

Commit

Permalink
feat: add arguments --build-cpu and --build-memory when deploying apps (
Browse files Browse the repository at this point in the history
  • Loading branch information
smile37773 authored May 23, 2022
1 parent d161598 commit 5bea677
Show file tree
Hide file tree
Showing 15 changed files with 1,683 additions and 2,062 deletions.
1 change: 1 addition & 0 deletions src/spring/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release History
---
* New command `az spring create` has new argument "--ingress-read-timeout" to set ingress read timeout when create Azure Spring App.
* New command `az spring update` has new argument "--ingress-read-timeout" to update ingress read timeout for Azure Spring App.
* Command `az spring app deploy` and `az spring app deployment create` has new argument "--build-cpu" and "--build-memory" to set cpu and memory during build process.

1.0.0
---
Expand Down
8 changes: 8 additions & 0 deletions src/spring/azext_spring/_app_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ def validate_cpu(namespace):
namespace.cpu = validate_cpu_value(namespace.cpu)


def validate_build_cpu(namespace):
namespace.build_cpu = validate_cpu_value(namespace.build_cpu)


def validate_memory(namespace):
namespace.memory = validate_memory_value(namespace.memory)


def validate_build_memory(namespace):
namespace.build_memory = validate_memory_value(namespace.build_memory)


def _get_app_name_from_namespace(namespace):
if hasattr(namespace, 'app'):
return namespace.app
Expand Down
10 changes: 7 additions & 3 deletions src/spring/azext_spring/_buildservices_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from msrestazure.tools import parse_resource_id
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.azure_exceptions import CloudError
from .vendored_sdks.appplatform.v2022_01_01_preview import models
from .vendored_sdks.appplatform.v2022_05_01_preview import models
from ._deployment_uploadable_factory import uploader_selector
from ._log_stream import LogStream
from .vendored_sdks.appplatform.v2022_01_01_preview.models._app_platform_management_client_enums import SupportedRuntimeValue
Expand Down Expand Up @@ -58,14 +58,18 @@ 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, build_env=None, app=None, **_):
def _queue_build(self, relative_path=None, builder=None, build_env=None, build_cpu=None, build_memory=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)
build_resource_requests = models.BuildResourceRequests(
cpu=build_cpu,
memory=build_memory)
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=build_env if build_env else None)
env=build_env if build_env else None,
resource_requests=build_resource_requests)
build = models.Build(properties=properties)
try:
return self.client.build_service.create_or_update_build(self.resource_group,
Expand Down
4 changes: 2 additions & 2 deletions src/spring/azext_spring/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,15 @@
short-summary: Create a builder.
examples:
- name: Create a builder using JSON file.
text: az spring build-service builder create --name my-builder --builder-json MyJson.json --service clitest --resource-group cli
text: az spring build-service builder create --name my-builder --builder-file MyJson.json --service clitest --resource-group cli
"""

helps['spring build-service builder update'] = """
type: command
short-summary: Update a builder.
examples:
- name: Update a builder using JSON file.
text: az spring build-service builder update --name my-builder --builder-json MyJson.json --service clitest --resource-group cli
text: az spring build-service builder update --name my-builder --builder-file MyJson.json --service clitest --resource-group cli
"""

helps['spring build-service builder show'] = """
Expand Down
17 changes: 12 additions & 5 deletions src/spring/azext_spring/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
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)
validate_cpu, validate_build_cpu, validate_memory, validate_build_memory,
fulfill_deployment_param_or_warning, active_deployment_exist_or_warning)
from ._app_managed_identity_validator import (validate_create_app_with_user_identity_or_warning,
validate_create_app_with_system_identity_or_warning,
validate_app_force_set_system_identity_or_warning,
Expand All @@ -51,7 +52,9 @@
arg_group='Source Code deploy')
# app cpu and memory
cpu_type = CLIArgumentType(type=str, help='CPU resource quantity. Should be 500m or number of CPU cores.', validator=validate_cpu)
memort_type = CLIArgumentType(type=str, help='Memory resource quantity. Should be 512Mi or #Gi, e.g., 1Gi, 3Gi.', validator=validate_memory)
memory_type = CLIArgumentType(type=str, help='Memory resource quantity. Should be 512Mi or #Gi, e.g., 1Gi, 3Gi.', validator=validate_memory)
build_cpu_type = CLIArgumentType(type=str, help='CPU resource quantity. Should be 500m or number of CPU cores.', validator=validate_build_cpu)
build_memory_type = CLIArgumentType(type=str, help='Memory resource quantity. Should be 512Mi or #Gi, e.g., 1Gi, 3Gi.', validator=validate_build_memory)


# pylint: disable=too-many-statements
Expand Down Expand Up @@ -216,7 +219,7 @@ def load_arguments(self, _):
validator=validate_create_app_with_user_identity_or_warning,
help="Space-separated user-assigned managed identity resource IDs to assgin to an app.")
c.argument('cpu', arg_type=cpu_type, default="1")
c.argument('memory', arg_type=memort_type, default="1Gi")
c.argument('memory', arg_type=memory_type, default="1Gi")
c.argument('instance_count', type=int,
default=1, help='Number of instance.', validator=validate_instance_count)
c.argument('persistent_storage', type=str,
Expand Down Expand Up @@ -341,7 +344,7 @@ def prepare_logs_argument(c):

with self.argument_context('spring app scale') as c:
c.argument('cpu', arg_type=cpu_type)
c.argument('memory', arg_type=memort_type)
c.argument('memory', arg_type=memory_type)
c.argument('instance_count', type=int, help='Number of instance.', validator=validate_instance_count)

for scope in ['spring app deploy', 'spring app deployment create']:
Expand Down Expand Up @@ -377,6 +380,10 @@ def prepare_logs_argument(c):
'container_args', help='The arguments of the container image.', nargs='*', arg_group='Custom Container')
c.argument(
'build_env', build_env_type)
c.argument(
'build_cpu', arg_type=build_cpu_type, default="1")
c.argument(
'build_memory', arg_type=build_memory_type, default="2Gi")

with self.argument_context('spring app deploy') as c:
c.argument('source_path', arg_type=source_path_type, validator=validate_deloy_path)
Expand All @@ -388,7 +395,7 @@ def prepare_logs_argument(c):
c.argument('skip_clone_settings', help='Create staging deployment will automatically copy settings from production deployment.',
action='store_true')
c.argument('cpu', arg_type=cpu_type)
c.argument('memory', arg_type=memort_type)
c.argument('memory', arg_type=memory_type)
c.argument('instance_count', type=int, help='Number of instance.', validator=validate_instance_count)

with self.argument_context('spring app deployment') as c:
Expand Down
2 changes: 1 addition & 1 deletion src/spring/azext_spring/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _pack_source_code(source_location, tar_file_path):

ignore_list, ignore_list_size = _load_gitignore_file(source_location)
common_vcs_ignore_list = {'.git', '.gitignore', 'bzrignore', '.hg',
'.hgignore', '.svn', '.circleci', 'target', 'docker'}
'.hgignore', '.svn', '.circleci', 'target', 'docker', 'mvnw', 'mvnw.cmd'}

def _ignore_check(tarinfo, parent_ignored, parent_matching_rule_index):
# ignore common vcs dir or file
Expand Down
4 changes: 4 additions & 0 deletions src/spring/azext_spring/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def app_deploy(cmd, client, resource_group, service, name,
container_args=None,
build_env=None,
builder=None,
build_cpu=None,
build_memory=None,
# deployment.settings
env=None,
disable_probe=None,
Expand Down Expand Up @@ -271,6 +273,8 @@ def app_deploy(cmd, client, resource_group, service, name,
'container_command': container_command,
'container_args': container_args,
'build_env': build_env,
'build_cpu': build_cpu,
'build_memory': build_memory,
'builder': builder,
'no_wait': no_wait
}
Expand Down
7 changes: 5 additions & 2 deletions src/spring/azext_spring/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def load_command_table(self, _):
exception_handler=handle_asc_exception) as g:
g.custom_command('create', 'app_create')
g.custom_command('update', 'app_update', supports_no_wait=True)
g.custom_command('deploy', 'app_deploy', supports_no_wait=True)

with self.command_group('spring app', client_factory=cf_spring_20220101preview,
exception_handler=handle_asc_exception) as g:
Expand Down Expand Up @@ -161,7 +160,11 @@ def load_command_table(self, _):
exception_handler=handle_asc_exception) as g:
g.custom_command('tail', 'app_tail_log')

with self.command_group('spring app deployment', custom_command_type=app_command,
with self.command_group('spring app', custom_command_type=app_command, client_factory=cf_spring_20220501preview,
exception_handler=handle_asc_exception) as g:
g.custom_command('deploy', 'app_deploy', supports_no_wait=True)

with self.command_group('spring app deployment', custom_command_type=app_command, client_factory=cf_spring_20220501preview,
exception_handler=handle_asc_exception) as g:
g.custom_command('create', 'deployment_create', supports_no_wait=True)

Expand Down
Loading

0 comments on commit 5bea677

Please sign in to comment.