update
This commit is contained in:
@@ -32,6 +32,7 @@ DEFAULT_IMAGE_NAME = "msk-lumina-backend"
|
|||||||
DEFAULT_TAG = "latest"
|
DEFAULT_TAG = "latest"
|
||||||
APP_NAME = "msk-lumina-backend-builder"
|
APP_NAME = "msk-lumina-backend-builder"
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Modal Image Definition
|
# Modal Image Definition
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@@ -78,6 +79,10 @@ def build_and_push(
|
|||||||
platform: str = "linux/amd64",
|
platform: str = "linux/amd64",
|
||||||
) -> dict:
|
) -> dict:
|
||||||
import boto3
|
import boto3
|
||||||
|
import base64
|
||||||
|
import time
|
||||||
|
from botocore.exceptions import ClientError
|
||||||
|
|
||||||
full_image = f"{registry}/{image_name}:{tag}"
|
full_image = f"{registry}/{image_name}:{tag}"
|
||||||
print(f"Building {full_image} for {platform}")
|
print(f"Building {full_image} for {platform}")
|
||||||
|
|
||||||
@@ -96,11 +101,45 @@ def build_and_push(
|
|||||||
# ecr = boto3.client("ecr-public", region_name=region)
|
# ecr = boto3.client("ecr-public", region_name=region)
|
||||||
# else:
|
# else:
|
||||||
# ecr = boto3.client("ecr", region_name=region)
|
# 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 = {
|
config = {
|
||||||
"auths": {
|
"auths": {
|
||||||
registry: {
|
registry: {
|
||||||
|
|||||||
Reference in New Issue
Block a user