Skip to content

[ACR] Add new command to check if specific blob is available to pull from registry#27676

Open
SakoPak wants to merge 10 commits intoAzure:devfrom
SakoPak:sako/check-health
Open

[ACR] Add new command to check if specific blob is available to pull from registry#27676
SakoPak wants to merge 10 commits intoAzure:devfrom
SakoPak:sako/check-health

Conversation

@SakoPak
Copy link
Copy Markdown
Contributor

@SakoPak SakoPak commented Oct 24, 2023

Description

  • Add new command to check if blobs within given image can be pulled from repository using command az acr check-health --name myRegistry --image hello-world@sha256@abc123

Testing Guide

  • Verify if blobs in image 'sha256:abc123' can be pulled from the repository: az acr check-health -n MyRegistry --image hello-world@sha256:abc123
  • Verify if blobs referenced by tag 'latest' can be pulled from the repository: az acr check-health -n MyRegistry -t hello-world:latest

History Notes
[ACR] az acr check-health --name --image: Add new command to check if blobs in given image can be pulled from registry


This checklist is used to make sure that common guidelines for a pull request are followed.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Oct 24, 2023

❌AzureCLI-FullTest
❌acr
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
❌latest
❌3.11
Type Test Case Error Message Line
Failed test_acr_check_health self = <azure.cli.command_modules.acr.tests.latest.test_acr_check_health_commands.AcrCheckHealthCommandsTests testMethod=test_acr_check_health>

    @ResourceGroupPreparer()
    def test_acr_check_health(self):
        repository = 'microsoft'
        tag = 'azure-cli'
    
        self.kwargs.update({
            'registry': self.create_random_name('clireg', 20),
            'sku': 'Premium',
            'resource-group': 'rg',
            'ignore_errors': False,
            'yes': False,
            'vnet': None,
            'repository': repository,
            'tag': tag,
            'image': '{}:{}'.format(repository, tag),
            'reason': 'OK',
            'source_reg_id': '/subscriptions/dfb63c8c-7c89-4ef8-af13-75c1d873c895/resourcegroups/resourcegroupdiffsub/providers/Microsoft.ContainerRegistry/registries/sourceregistrydiffsub',
        })
    
        # Create the registry
        result = self.cmd('acr create --name {registry} --sku {sku} --resource-group {rg}').get_output_in_json()
        self.kwargs['registry'] = result['name']
    
        # Import image to registry.
        self.cmd('acr import -n {registry} -r {source_reg_id} --source {image}')
    
        # Check the health of the registry
        self.cmd('acr check-health --name {registry} --yes --ignore-errors')
    
        # Test if imported image can be pulled from the registry
>       result = self.cmd('acr check-health --name {registry} --repository {repository} --image {tag} --yes --ignore-errors')

src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_check_health_commands.py:40: 
                                        
src/azure-cli-testsdk/azure/cli/testsdk/base.py:175: in cmd
    return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:250: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:301: in in_process_execute
    self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
env/lib/python3.11/site-packages/knack/cli.py:250: in invoke
    raise ex
env/lib/python3.11/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
src/azure-cli-core/azure/cli/core/commands/init.py:588: in execute
    parsed_args = self.parser.parse_args(args)
env/lib/python3.11/site-packages/knack/parser.py:261: in parse_args
    return super().parse_args(args)
/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/argparse.py:1872: in parse_args
    self.error(msg % ' '.join(argv))
src/azure-cli-core/azure/cli/core/parser.py:175: in error
    self.exit(2)
 
                                       

self = AzCliCommandParser(prog='az', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
status = 2, message = None

    def exit(self, status=0, message=None):
        if message:
            self._print_message(message, _sys.stderr)
>       _sys.exit(status)
E       SystemExit: 2

/opt/hostedtoolcache/Python/3.11.6/x64/lib/python3.11/argparse.py:2617: SystemExit
azure/cli/command_modules/acr/tests/latest/test_acr_check_health_commands.py:9
❌3.9
Type Test Case Error Message Line
Failed test_acr_check_health self = <azure.cli.command_modules.acr.tests.latest.test_acr_check_health_commands.AcrCheckHealthCommandsTests testMethod=test_acr_check_health>

    @ResourceGroupPreparer()
    def test_acr_check_health(self):
        repository = 'microsoft'
        tag = 'azure-cli'
    
        self.kwargs.update({
            'registry': self.create_random_name('clireg', 20),
            'sku': 'Premium',
            'resource-group': 'rg',
            'ignore_errors': False,
            'yes': False,
            'vnet': None,
            'repository': repository,
            'tag': tag,
            'image': '{}:{}'.format(repository, tag),
            'reason': 'OK',
            'source_reg_id': '/subscriptions/dfb63c8c-7c89-4ef8-af13-75c1d873c895/resourcegroups/resourcegroupdiffsub/providers/Microsoft.ContainerRegistry/registries/sourceregistrydiffsub',
        })
    
        # Create the registry
        result = self.cmd('acr create --name {registry} --sku {sku} --resource-group {rg}').get_output_in_json()
        self.kwargs['registry'] = result['name']
    
        # Import image to registry.
        self.cmd('acr import -n {registry} -r {source_reg_id} --source {image}')
    
        # Check the health of the registry
        self.cmd('acr check-health --name {registry} --yes --ignore-errors')
    
        # Test if imported image can be pulled from the registry
>       result = self.cmd('acr check-health --name {registry} --repository {repository} --image {tag} --yes --ignore-errors')

src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_check_health_commands.py:40: 
                                        
src/azure-cli-testsdk/azure/cli/testsdk/base.py:175: in cmd
    return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:250: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:301: in in_process_execute
    self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
env/lib/python3.9/site-packages/knack/cli.py:250: in invoke
    raise ex
env/lib/python3.9/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
src/azure-cli-core/azure/cli/core/commands/init.py:588: in execute
    parsed_args = self.parser.parse_args(args)
env/lib/python3.9/site-packages/knack/parser.py:261: in parse_args
    return super().parse_args(args)
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/argparse.py:1828: in parse_args
    self.error(msg % ' '.join(argv))
src/azure-cli-core/azure/cli/core/parser.py:175: in error
    self.exit(2)
 
                                       

self = AzCliCommandParser(prog='az', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
status = 2, message = None

    def exit(self, status=0, message=None):
        if message:
            self._print_message(message, _sys.stderr)
>       _sys.exit(status)
E       SystemExit: 2

/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/argparse.py:2569: SystemExit
azure/cli/command_modules/acr/tests/latest/test_acr_check_health_commands.py:9
️✔️acs
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.11
️✔️3.9
️✔️ams
️✔️latest
️✔️3.11
️✔️3.9
️✔️apim
️✔️latest
️✔️3.11
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.11
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.11
️✔️3.9
️✔️aro
️✔️latest
️✔️3.11
️✔️3.9
️✔️backup
️✔️latest
️✔️3.11
️✔️3.9
️✔️batch
️✔️latest
️✔️3.11
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.11
️✔️3.9
️✔️billing
️✔️latest
️✔️3.11
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.11
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.11
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.11
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.11
️✔️3.9
️✔️config
️✔️latest
️✔️3.11
️✔️3.9
️✔️configure
️✔️latest
️✔️3.11
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.11
️✔️3.9
️✔️container
️✔️latest
️✔️3.11
️✔️3.9
️✔️containerapp
️✔️latest
️✔️3.11
️✔️3.9
️✔️core
️✔️2018-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.11
️✔️3.9
️✔️databoxedge
️✔️2019-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️dla
️✔️latest
️✔️3.11
️✔️3.9
️✔️dls
️✔️latest
️✔️3.11
️✔️3.9
️✔️dms
️✔️latest
️✔️3.11
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.11
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.11
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.11
️✔️3.9
️✔️find
️✔️latest
️✔️3.11
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.11
️✔️3.9
️✔️identity
️✔️latest
️✔️3.11
️✔️3.9
️✔️iot
️✔️2019-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️keyvault
️✔️2018-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️kusto
️✔️latest
️✔️3.11
️✔️3.9
️✔️lab
️✔️latest
️✔️3.11
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.11
️✔️3.9
️✔️maps
️✔️latest
️✔️3.11
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.11
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.11
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.11
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.11
️✔️3.9
️✔️network
️✔️2018-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.11
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.11
️✔️3.9
️✔️profile
️✔️latest
️✔️3.11
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.11
️✔️3.9
️✔️redis
️✔️latest
️✔️3.11
️✔️3.9
️✔️relay
️✔️latest
️✔️3.11
️✔️3.9
️✔️resource
️✔️2018-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️role
️✔️latest
️✔️3.11
️✔️3.9
️✔️search
️✔️latest
️✔️3.11
️✔️3.9
️✔️security
️✔️latest
️✔️3.11
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.11
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.11
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.11
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.11
️✔️3.9
️✔️sql
️✔️latest
️✔️3.11
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.11
️✔️3.9
️✔️storage
️✔️2018-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.11
️✔️3.9
️✔️telemetry
️✔️2018-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9
️✔️util
️✔️latest
️✔️3.11
️✔️3.9
️✔️vm
️✔️2018-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.11
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.11
️✔️3.9
️✔️latest
️✔️3.11
️✔️3.9

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Oct 24, 2023

⚠️AzureCLI-BreakingChangeTest
⚠️acr
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd acr check-health cmd acr check-health added parameter image
⚠️ 1006 - ParaAdd acr check-health cmd acr check-health added parameter password
⚠️ 1006 - ParaAdd acr check-health cmd acr check-health added parameter resource_group_name
⚠️ 1006 - ParaAdd acr check-health cmd acr check-health added parameter username

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Oct 24, 2023

ACR

Comment thread src/azure-cli/azure/cli/command_modules/acr/_help.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/_help.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/_help.py Outdated
@zhoxing-ms
Copy link
Copy Markdown
Contributor

Please address this CI issues

@zhoxing-ms
Copy link
Copy Markdown
Contributor

@SakoPak Please note that we are launching the release for this sprint this week. Please resolve all comments and conflicts by Tomorrow, otherwise the release of this PR will have to be postponed to the next sprint (on 12-05)

@SakoPak
Copy link
Copy Markdown
Contributor Author

SakoPak commented Nov 7, 2023

@SakoPak Please note that we are launching the release for this sprint this week. Please resolve all comments and conflicts by Tomorrow, otherwise the release of this PR will have to be postponed to the next sprint (on 12-05)

This PR can wait until next sprint as it's still in progress, thank you for the heads up.

Copy link
Copy Markdown
Contributor

@rosanch rosanch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, I left some comments, please do not resolve questions. I'll do after reading the response.
Thanks

Comment thread src/azure-cli/azure/cli/command_modules/acr/_help.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/_params.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py Outdated
Copy link
Copy Markdown

@estebanreyl estebanreyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comments, mostly on edge cases to consider, overall lgtm

Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
# If manifest is not a Docker Manifest List, find the smallest blob in the given single manifest
smallest_blob = min(manifest['layers'], key=lambda layer: layer['size'])

smallest_digest = smallest_blob['digest']
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One edge case to account for here is that smallest_blob could be empty, this is because manifests with no layers and Manifest lists with no sub-manifests are also technically allowed. In that situation you might be able to pull the manifest as if it is a regular blob (haven't tried it but it should work) or error and ask the user to use a different image.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that's a great point, I will factor in this edge case and have it pull the manifest like a regular blob, thanks!

Comment thread src/azure-cli/azure/cli/command_modules/acr/check_health.py
@zhoxing-ms
Copy link
Copy Markdown
Contributor

@SakoPak Could you please resolve these CI issues?

@toddysm
Copy link
Copy Markdown
Member

toddysm commented Jan 27, 2025

@SakoPak is this still needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants