Skip to content

Commit

Permalink
Integrated with Harry
Browse files Browse the repository at this point in the history
  • Loading branch information
snehapar9 committed May 4, 2023
1 parent 04f21ed commit 1821286
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 50 deletions.
12 changes: 12 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,3 +1271,15 @@
--environment MyContainerappEnv \\
--compose-file-path "path/to/docker-compose.yml"
"""

helps['containerapp patch list'] = """
type: command
short-summary: List patchable and unpatchable container apps.
examples:
- name: List patchable container apps.
text: |
az containerapp list -g MyResourceGroup --environment MyContainerappEnv
- name: List patchable and non-patchable container apps.
text: |
az containerapp list -g MyResourceGroup --environment MyContainerappEnv --showAll
"""
4 changes: 2 additions & 2 deletions src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,6 @@ def load_arguments(self, _):
c.argument('max_nodes', help="The maximum node count for the workload profile")

with self.argument_context('containerapp patch list') as c:
c.argument('resource_group_name', options_list=['--rg'], configured_default='resource_group_name', id_part=None)
c.argument('env_name', options_list=['--env','--e'], help='Name or resource id of the Container App environment.')
c.argument('resource_group_name', options_list=['--rg','-g'], configured_default='resource_group_name', id_part=None)
c.argument('environment', options_list=['--environment'], help='Name or resource id of the Container App environment.')
c.argument('show_all', options_list=['--show-all'],help='Show all patchable and non-patchable containerapps')
80 changes: 32 additions & 48 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
ScaleRule as ScaleRuleModel,
Volume as VolumeModel,
VolumeMount as VolumeMountModel,)
from ._models import DotnetTagProperty, ImagePatchableCheck, ImageProperties
from ._models import OryxMarinerRunImgTagProperty, ImagePatchableCheck, ImageProperties

from ._utils import (_validate_subscription_registered, _ensure_location_allowed,
parse_secret_flags, store_as_secret_and_return_secret_ref, parse_env_var_flags,
Expand Down Expand Up @@ -4132,31 +4132,6 @@ def show_auth_config(cmd, resource_group_name, name):
pass
return auth_settings


def list_dummy_values(cmd, resource_group_name, env_name, show_all=False):
print(show_all)
dummy_json = {
"children":[
{
"targetContainerAppName": "test-rg-1",
"oldRunImage": "mcr.microsoft.com/dotnet/sdk:6.0.100-cbl-mariner1.0",
"newRunImage": "mcr.microsoft.com/dotnet/sdk6.0.400-cbl-mariner1.0",
"id": "014eef45-350d-4f94-9e31-7a088d932354",
"reason": "The image is based on Mariner and the minor version is within safe update range."
},
{
"targetContainerAppName": "test-rg-1",
"oldRunImage": "mcr.microsoft.com/dotnet/sdk:7.0.101-cbl-mariner2.0",
"newRunImage": None,
"id": None,
"reason": "You're already up to date!"

}

]
}
return json.dumps(dummy_json)

# Compose

def create_containerapps_from_compose(cmd, # pylint: disable=R0914
Expand Down Expand Up @@ -4326,8 +4301,8 @@ def delete_workload_profile(cmd, resource_group_name, env_name, workload_profile
except Exception as e:
handle_raw_exception(e)

def patch_list(cmd, resource_group_name=None, managed_env=None):
caList = list_containerapp(cmd, resource_group_name, managed_env)
def patch_list(cmd, resource_group_name, managed_env, show_all=False):
caList = list_containerapp(cmd, resource_group_name, managed_env)
imgs = []
if caList:
for ca in caList:
Expand All @@ -4343,10 +4318,11 @@ def patch_list(cmd, resource_group_name=None, managed_env=None):
## For production
#
for img in imgs:
subprocess.run("pack inspect-image " + img["imageName"] + " --output json > /tmp/bom.json 2>&1", shell=True)
with open("/tmp/bom.json", "rb") as f:
bom = json.load(f)
bom.update('{ "targetContainerAppName": img["targetContainerAppName"] }')
subprocess.run("pack inspect-image " + img["imageName"] + " --output json > ./bom.json 2>&1", shell=True)
with open("./bom.json", "rb") as f:
lines = f.read()
bom = json.loads(lines)
bom.update({ "targetContainerAppName": img["targetContainerAppName"] })
boms.append(bom)

## For testing
Expand All @@ -4373,23 +4349,31 @@ def patch_list(cmd, resource_group_name=None, managed_env=None):
else:
# devide run-images into different parts by "/"
runImagesProps = bom["remote_info"]["run_images"]
for runImagesProp in runImagesProps:
if (runImagesProp["name"].find("mcr.microsoft.com/oryx/builder") != -1):
runImagesProp = runImagesProp["name"].split(":")
runImagesTag = runImagesProp[1]
# Based on Mariners
if runImagesTag.find('mariner') != -1:
result = patchableCheck(runImagesTag, oryxRunImgTags, bom=bom)
else:
if runImagesProps is None:
result = ImagePatchableCheck
result["targetContainerAppName"] = bom["targetContainerAppName"]
result["reason"] = "Image not based on Mariners"
results.append(result)
else:
for runImagesProp in runImagesProps:
if (runImagesProp["name"].find("mcr.microsoft.com/oryx/builder") != -1):
runImagesProp = runImagesProp["name"].split(":")
runImagesTag = runImagesProp[1]
# Based on Mariners
if runImagesTag.find('mariner') != -1:
result = patchableCheck(runImagesTag, oryxRunImgTags, bom=bom)
else:
result = ImagePatchableCheck
result["targetContainerAppName"] = bom["targetContainerAppName"]
result["oldRunImage"] = bom["remote_info"]["run_images"]
result["reason"] = "Image not based on Mariners"
else:
# Not based on image from mcr.microsoft.com/dotnet
result = ImagePatchableCheck
result["targetContainerAppName"] = bom["targetContainerAppName"]
result["oldRunImage"] = bom["remote_info"]["run_images"]
result["reason"] = "Image not based on Mariners"
else:
# Not based on image from mcr.microsoft.com/dotnet
result = ImagePatchableCheck
result["targetContainerAppName"] = bom["targetContainerAppName"]
result["oldRunImage"] = bom["remote_info"]["run_images"]
result["reason"] = "Image not from mcr.microsoft.com/oryx/builder"
results.append(result)
result["reason"] = "Image not from mcr.microsoft.com/oryx/builder"
results.append(result)
if show_all == False :
results = [x for x in results if x["newRunImage"] != None]
return results

0 comments on commit 1821286

Please sign in to comment.