update
Some checks failed
Backend EC - Modal Deployment / build-and-push (push) Failing after 1m38s
Backend EC - Modal Deployment / notify-deploy (push) Has been skipped

This commit is contained in:
DatTT127
2026-07-19 02:03:40 +07:00
parent 8bd81075f2
commit 2c6ff02b0c

View File

@@ -32,6 +32,7 @@ DEFAULT_IMAGE_NAME = "msk-lumina-backend"
DEFAULT_TAG = "latest"
APP_NAME = "msk-lumina-backend-builder"
# =============================================================================
# Modal Image Definition
# =============================================================================
@@ -78,6 +79,10 @@ def build_and_push(
platform: str = "linux/amd64",
) -> dict:
import boto3
import base64
import time
from botocore.exceptions import ClientError
full_image = f"{registry}/{image_name}:{tag}"
print(f"Building {full_image} for {platform}")
@@ -96,11 +101,45 @@ def build_and_push(
# ecr = boto3.client("ecr-public", region_name=region)
# else:
# ecr = boto3.client("ecr", region_name=region)
ecr = boto3.client("ecr-public", region_name=region)
auth = ecr.get_authorization_token()
token = auth["authorizationData"]["authorizationToken"]
username, password = base64.b64decode(token).decode().split(":")
# ecr = boto3.client("ecr-public", region_name=region)
# auth = ecr.get_authorization_token()
# token = auth["authorizationData"]["authorizationToken"]
def get_ecr_public_credentials(region="us-east-1", max_retries=3, initial_delay=2):
ecr = boto3.client("ecr-public", region_name=region)
delay = initial_delay
for attempt in range(max_retries):
try:
auth = ecr.get_authorization_token()
token = auth["authorizationData"]["authorizationToken"]
username, password = base64.b64decode(token).decode().split(":")
return username, password
except ClientError as e:
error_code = e.response['Error']['Code']
# If it's a permanent access issue, don't waste time retrying
if error_code in ["AccessDeniedException", "UnrecognizedClientException"]:
print(f"Permanent permission error: {e}. Fixing config needed.")
raise e
print(f"Attempt {attempt + 1} failed with transient error ({error_code}). Retrying in {delay}s...")
except Exception as e:
print(f"Attempt {attempt + 1} failed with unexpected error: {e}. Retrying in {delay}s...")
# Wait before trying again (doubles the wait time each loop)
time.sleep(delay)
delay *= 2
# If all retries fail, raise a final clean exception
raise RuntimeError(f"Failed to fetch ECR Public token after {max_retries} attempts.")
# username, password = base64.b64decode(token).decode().split(":")
username, password = get_ecr_public_credentials()
config = {
"auths": {
registry: {
@@ -138,7 +177,7 @@ def build_and_push(
"--context", str(workspace_root),
"--dockerfile", str(dockerfile_path),
"--destination", full_image,
"--custom-platform", platform,
"--custom-platform", platform,
"--verbosity", "info",
]