Skip to content

Commit

Permalink
Support running an image without a context
Browse files Browse the repository at this point in the history
  • Loading branch information
NatalieYuGong committed Mar 14, 2019
1 parent f9569b4 commit 8af17b6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
Binary file added UpgradeLog.htm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def load_arguments(self, _): # pylint: disable=too-many-statements
c.argument('values', help="The task values file path relative to the source context.")
c.argument('set_value', options_list=['--set'], help="Value in 'name[=value]' format.", action='append', validator=validate_set)
c.argument('set_secret', help="Secret value in 'name[=value]' format.", action='append', validator=validate_set_secret)
c.argument('cmd', options_list=['--__cmd__'])
c.argument('cmd_value', help="Indicates whether the source location be interpreted as an image name to run or a context.", options_list=['--cmd'])

with self.argument_context('acr build') as c:
c.argument('registry_name', options_list=['--registry', '-r'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from ._archive_utils import upload_source_code, check_remote_source_code

RUN_NOT_SUPPORTED = 'Run is only available for managed registries.'
YAML_TEMPLATE = 'steps: \n - cmd: {{ .Values.run_image }}\n'
NULL_SOURCE_LOCATION = "/dev/null"

logger = get_logger(__name__)

Expand All @@ -28,6 +30,7 @@ def acr_run(cmd, # pylint: disable=too-many-locals
values=None,
set_value=None,
set_secret=None,
cmd_value=None,
no_format=False,
no_logs=False,
no_wait=False,
Expand All @@ -39,15 +42,20 @@ def acr_run(cmd, # pylint: disable=too-many-locals
_, resource_group_name = validate_managed_registry(
cmd, registry_name, resource_group_name, RUN_NOT_SUPPORTED)

platform_os, platform_arch, platform_variant = get_validate_platform(cmd, os_type, platform)

EncodedTaskRunRequest, FileTaskRunRequest, PlatformProperties = cmd.get_models('EncodedTaskRunRequest', 'FileTaskRunRequest', 'PlatformProperties')

client_registries = cf_acr_registries(cmd.cli_ctx)

if os.path.exists(source_location):
if source_location == NULL_SOURCE_LOCATION:
source_location = None
elif os.path.exists(source_location):
if not os.path.isdir(source_location):
raise CLIError(
"Source location should be a local directory path or remote URL.")

tar_file_path = os.path.join(tempfile.gettempdir(
), 'run_archive_{}.tar.gz'.format(uuid.uuid4().hex))
), 'run_archive_{}.tar.gz'.format(uuid.uuid4().hex))

try:
source_location = upload_source_code(
Expand All @@ -66,21 +74,40 @@ def acr_run(cmd, # pylint: disable=too-many-locals
source_location = check_remote_source_code(source_location)
logger.warning("Sending context to registry: %s...", registry_name)

platform_os, platform_arch, platform_variant = get_validate_platform(cmd, os_type, platform)

FileTaskRunRequest, PlatformProperties = cmd.get_models('FileTaskRunRequest', 'PlatformProperties')
request = FileTaskRunRequest(
task_file_path=file,
values_file_path=values,
values=(set_value if set_value else []) + (set_secret if set_secret else []),
source_location=source_location,
timeout=timeout,
platform=PlatformProperties(
os=platform_os,
architecture=platform_arch,
variant=platform_variant
if cmd_value:
values_content = "run_image: {0}\n".format(cmd_value)
import base64
request = EncodedTaskRunRequest(
encoded_task_content=base64.b64encode(YAML_TEMPLATE.encode()).decode(),
encoded_values_content=base64.b64encode(values_content.encode()).decode(),
values=(set_value if set_value else []) + (set_secret if set_secret else []),
source_location=source_location,
timeout=timeout,
platform=PlatformProperties(
os=platform_os,
architecture=platform_arch,
variant=platform_variant
)
)
else:
if file == "-":
f = open('acb.yaml', 'w+')
while f.write(input()) > 0:
f.write('\n')
f.close()
file = 'acb.yaml'
request = FileTaskRunRequest(
task_file_path=file,
values_file_path=values,
values=(set_value if set_value else []) + (set_secret if set_secret else []),
source_location=source_location,
timeout=timeout,
platform=PlatformProperties(
os=platform_os,
architecture=platform_arch,
variant=platform_variant
)
)
)

queued = LongRunningOperation(cmd.cli_ctx)(client_registries.schedule_run(
resource_group_name=resource_group_name,
Expand Down

0 comments on commit 8af17b6

Please sign in to comment.