Skip to content

Commit 8b97852

Browse files
Fix generate image size report
1 parent 5846583 commit 8b97852

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

.github/workflows/check-image-size.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ on:
66
image-version:
77
required: true
88
description: Image version=
9+
staging-repo-name:
10+
required: true
11+
description: Staging repository name
12+
staging-account:
13+
required: true
14+
description: Staging account ID
915
# Call from other workflow
1016
workflow_call:
1117
inputs:
1218
image-version:
1319
type: string
1420
required: true
21+
staging-repo-name:
22+
type: string
23+
required: true
24+
staging-account:
25+
type: string
26+
required: true
1527

1628
defaults:
1729
run:
@@ -37,4 +49,4 @@ jobs:
3749
- name: Activate sagemaker-distribution
3850
run: micromamba activate sagemaker-distribution
3951
- name: Run size validation
40-
run: python ./src/main.py generate-size-report --target-patch-version ${{ inputs.image-version }} --validate
52+
run: python ./src/main.py generate-size-report --target-patch-version ${{ inputs.image-version }} --staging-repo-name ${{ inputs.staging-repo-name }} --staging-account ${{ inputs.staging-account }} --validate

src/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@ def get_arg_parser():
428428
required=True,
429429
help="Specify the target patch version for which the package size report needs to be " "generated.",
430430
)
431+
package_size_parser.add_argument(
432+
"--staging-repo-name",
433+
required=True,
434+
help="Specify the staging repository",
435+
)
436+
package_size_parser.add_argument(
437+
"--staging-account",
438+
required=True,
439+
help="Specify the staging account",
440+
)
431441
package_size_parser.add_argument(
432442
"--validate",
433443
action="store_true",

src/package_report.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def generate_package_size_report(args):
271271
base_version_dir = get_dir_for_version(base_version) if base_version else None
272272

273273
#Generate the report for Total Image Size changed from Base Version
274-
_generate_image_size_report(target_version, base_version)
274+
_generate_image_size_report(target_version, base_version, args.staging_repo_name, args.staging_account)
275275

276276
validate_results = []
277277
for image_config in _image_generator_configs[target_version.major]:
@@ -312,13 +312,13 @@ def generate_package_dependency_report(args):
312312
print("## Image Type: " + "(" + image_config["image_type"].upper() + ")")
313313
_generate_python_package_dependency_report(image_config, base_version_dir, target_version_dir)
314314

315-
def get_image_size(image_tag):
315+
def get_image_size(image_tag, staging_repo_name, staging_account):
316316
try:
317317
ecr_client = boto3.client('ecr', region_name="us-east-1")
318318

319319
response = ecr_client.describe_images(
320-
registryId=STAGING_ACCOUNT,
321-
repositoryName=STAGING_REPO_NAME,
320+
registryId=staging_account,
321+
repositoryName=staging_repo_name,
322322
imageIds=[{'imageTag': image_tag}]
323323
)
324324
image_details = response.get('imageDetails', [])
@@ -328,27 +328,27 @@ def get_image_size(image_tag):
328328
image_size_gb = image_size_bytes / (1024 ** 3)
329329
return image_size_gb
330330
else:
331-
print(f"Image size not found for {STAGING_REPO_NAME}:{image_tag}")
331+
print(f"Image size not found for {staging_repo_name}:{image_tag}")
332332
else:
333-
print(f"No image details found for {STAGING_REPO_NAME}:{image_tag}")
333+
print(f"No image details found for {staging_repo_name}:{image_tag}")
334334

335335
except Exception as e:
336336
print(f"Error retrieving image size: {str(e)}")
337337

338338
return None
339339

340-
def _generate_image_size_report(target_version, base_version):
340+
def _generate_image_size_report(target_version, base_version, staging_repo_name, staging_account):
341341
target_tag_gpu = f"{target_version.major}.{target_version.minor}.{target_version.patch}-gpu"
342342
base_tag_gpu = f"{base_version.major}.{base_version.minor}.{base_version.patch}-gpu" if base_version else None
343343

344344
target_tag_cpu = f"{target_version.major}.{target_version.minor}.{target_version.patch}-cpu"
345345
base_tag_cpu = f"{base_version.major}.{base_version.minor}.{base_version.patch}-cpu" if base_version else None
346346

347-
target_size_gpu = get_image_size(target_tag_gpu)
348-
base_size_gpu = get_image_size(base_tag_gpu) if base_tag_gpu else None
347+
target_size_gpu = get_image_size(target_tag_gpu, staging_repo_name, staging_account)
348+
base_size_gpu = get_image_size(base_tag_gpu, staging_repo_name, staging_account) if base_tag_gpu else None
349349

350-
target_size_cpu = get_image_size(target_tag_cpu)
351-
base_size_cpu = get_image_size(base_tag_cpu) if base_tag_cpu else None
350+
target_size_cpu = get_image_size(target_tag_cpu, staging_repo_name, staging_account)
351+
base_size_cpu = get_image_size(base_tag_cpu, staging_repo_name, staging_account) if base_tag_cpu else None
352352

353353
headers = ["Target Image Size", "Base Image Size", "Size Difference", "Size Change (%)"]
354354

0 commit comments

Comments
 (0)