From 6d5fae43fcb20c4ea89ee974603cc923814bf4b6 Mon Sep 17 00:00:00 2001 From: Vamil Gandhi <13998000+vamgan@users.noreply.github.com> Date: Mon, 11 May 2026 02:05:18 -0400 Subject: [PATCH] Package ECR build helper script --- package.json | 3 ++- scripts/build-and-push-ecr.sh | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index ea0423b..c1bcd9e 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "dist", "README.md", "LICENSE", - "Dockerfile" + "Dockerfile", + "scripts/build-and-push-ecr.sh" ], "scripts": { "build": "tsup src/index.ts src/server.ts --format esm --dts --clean", diff --git a/scripts/build-and-push-ecr.sh b/scripts/build-and-push-ecr.sh index 720fbc2..f264364 100755 --- a/scripts/build-and-push-ecr.sh +++ b/scripts/build-and-push-ecr.sh @@ -1,11 +1,16 @@ #!/usr/bin/env bash set -euo pipefail -AWS_REGION="${AWS_REGION:-${AGENTDISPATCH_AWS_REGION:-us-west-2}}" +AWS_REGION="${AWS_REGION:-${AWS_DEFAULT_REGION:-}}" ECR_REPOSITORY="${ECR_REPOSITORY:-agentdispatch-worker-agentcore}" IMAGE_TAG="${IMAGE_TAG:-latest}" PLATFORM="${PLATFORM:-linux/arm64}" +if [[ -z "$AWS_REGION" ]]; then + echo "AWS_REGION or AWS_DEFAULT_REGION is required." >&2 + exit 1 +fi + if ! command -v aws >/dev/null 2>&1; then echo "aws CLI is required." >&2 exit 1 @@ -16,8 +21,9 @@ if ! command -v docker >/dev/null 2>&1; then exit 1 fi -ACCOUNT_ID="$(aws sts get-caller-identity --query Account --output text)" -IMAGE_URI="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}" +AWS_ACCOUNT_ID="$(aws sts get-caller-identity --query Account --output text)" +ECR_REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" +IMAGE_URI="${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}" aws ecr describe-repositories \ --region "$AWS_REGION" \ @@ -26,12 +32,12 @@ aws ecr describe-repositories \ --region "$AWS_REGION" \ --repository-name "$ECR_REPOSITORY" >/dev/null -aws ecr get-login-password --region "$AWS_REGION" | \ - docker login --username AWS --password-stdin "${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" - npm ci npm run build +aws ecr get-login-password --region "$AWS_REGION" | \ + docker login --username AWS --password-stdin "$ECR_REGISTRY" + docker buildx build \ --platform "$PLATFORM" \ --tag "$IMAGE_URI" \