From c4200f13820e9738eac1c936ff24670fa593b7c9 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Sun, 12 Oct 2025 20:58:38 +0800 Subject: [PATCH 1/6] feat: update push to ecr script --- README.md | 52 +++-- server/scripts/push-to-ecr.sh | 220 ++++++++++++++------ server/template/SwiftChatAppRunner.template | 68 ++++-- server/template/SwiftChatLambda.template | 19 +- 4 files changed, 253 insertions(+), 106 deletions(-) diff --git a/README.md b/README.md index b103d182..5a0023da 100644 --- a/README.md +++ b/README.md @@ -82,37 +82,59 @@ this [example](https://github.com/awslabs/aws-lambda-web-adapter/tree/main/examp 2. Check whether you are in the [supported region](#supported-region), then click on the **Create parameter** button. 3. Fill in the parameters below, leaving other options as default: - - **Name**: Enter a parameter name (e.g., "SwiftChatAPIKey", will be used as `ApiKeyParam` in Step 2). + - **Name**: Enter a parameter name (e.g., "SwiftChatAPIKey", will be used as `ApiKeyParam` in Step 3). - **Type**: Select `SecureString` - - **Value**: Enter any string without spaces.(this will be your `API Key` in Step 3) + - **Value**: Enter any string without spaces.(this will be your `API Key` in Step 4) 4. Click **Create parameter**. -### Step 2: Deploy stack and get your API URL +### Step 2: Build and push container images to ECR -1. Go to [CloudFormation Console](https://console.aws.amazon.com/cloudformation/home#/stacks/create/template?stackName=SwiftChat) and select **Upload a template file** under **Specify template**, then use one of the following templates to deploy. (Make sure you are in the same region where your API Key was created.) +1. Clone this repository: + ```bash + git clone https://github.com/aws-samples/swift-chat.git + cd swift-chat + ``` - - **App Runner** +2. Run the build and push script: + ```bash + cd server/scripts + bash ./push-to-ecr.sh + ``` - Open [SwiftChatAppRunner.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatAppRunner.template), then download and upload the file. +3. Follow the prompts to configure: + - ECR repository name (or use default: `swift-chat-api`) + - Image tag (or use default: `latest`) + - AWS region (or use default: `us-east-1`) - - **Lambda** (Note: For AWS customer use only) +4. The script will build and push the Docker image to your ECR repository. - Open [SwiftChatLambda.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatLambda.template) then download and upload the file. +5. **Important**: Copy the image URI displayed at the end of the script output. You'll need this in the next step. -2. Click **Next**, On the "Specify stack details" page, provide the following information: - - Fill the `ApiKeyParam` with the parameter name you used for storing the API key (e.g., "SwiftChatAPIKey"). - - For App Runner, choose an `InstanceTypeParam` based on your needs. -3. Click **Next**, Keep the "Configure stack options" page as default, Read the Capabilities and Check the "I +### Step 3: Deploy stack and get your API URL + +1. Download the CloudFormation template you want to use: + - For App Runner: [SwiftChatAppRunner.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatAppRunner.template) + - For Lambda: [SwiftChatLambda.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatLambda.template) + +2. Go to [CloudFormation Console](https://console.aws.amazon.com/cloudformation/home#/stacks/create/template?stackName=SwiftChatAPI) and select **Upload a template file** under **Specify template**, then upload the template file you downloaded. (Make sure you are in the same region where your API Key was created.) + +3. Click **Next**, On the "Specify stack details" page, provide the following information: + - **Stack name**: Keep the default "SwiftChatAPI" or change if needed + - **ApiKeyParam**: Enter the parameter name you used for storing the API key (e.g., "SwiftChatAPIKey") + - **ContainerImageUri**: Enter the ECR image URI from Step 2 output + - For App Runner, choose an **InstanceTypeParam** based on your needs + +4. Click **Next**, Keep the "Configure stack options" page as default, Read the Capabilities and Check the "I acknowledge that AWS CloudFormation might create IAM resources" checkbox at the bottom. -4. Click **Next**, In the "Review and create" Review your configuration and click **Submit**. +5. Click **Next**, In the "Review and create" Review your configuration and click **Submit**. -Wait about 3-5 minutes for the deployment to finish, then click the CloudFormation stack and go to **Outputs** tab, you +Wait about 10-15 minutes for the deployment to finish, then click the CloudFormation stack and go to **Outputs** tab, you can find the **API URL** which looks like: `https://xxx.xxx.awsapprunner.com` or `https://xxx.lambda-url.xxx.on.aws` -### Step 3: Open the App and setup with API URL and API Key +### Step 4: Open the App and setup with API URL and API Key 1. Launch the App, open the drawer menu, and tap **Settings**. 2. Paste the `API URL` and `API Key`(The **Value** you typed in Parameter Store) Under Amazon Bedrock -> SwiftChat diff --git a/server/scripts/push-to-ecr.sh b/server/scripts/push-to-ecr.sh index 0581f46a..88c782d6 100644 --- a/server/scripts/push-to-ecr.sh +++ b/server/scripts/push-to-ecr.sh @@ -1,77 +1,173 @@ # NOTE: The script will try to create the ECR repository if it doesn't exist. Please grant the necessary permissions to the IAM user or role. # Usage: -# cd scripts +# cd server/scripts # bash ./push-to-ecr.sh set -o errexit # exit on first error set -o nounset # exit on using unset variables set -o pipefail # exit on any error in a pipeline -# Define variables -TAG="latest" -ARCHS=("amd64" "arm64") -AWS_REGIONS=("us-east-1") # List of AWS region, use below list if you don't enable ECR repository replication -# AWS_REGIONS=("us-west-2" "us-east-1" "ap-south-1" "ap-southeast-1" "ap-southeast-2" "ap-northeast-1" "ca-central-1" -# "eu-central-1" "eu-west-2" "eu-west-3" "sa-east-1") # List of supported AWS regions +# Check prerequisites +echo "================================================" +echo "SwiftChat - Build and Push to ECR" +echo "================================================" +echo "" -build_and_push_images() { +echo "Checking prerequisites..." + +# Check if Docker is available +if ! command -v docker &> /dev/null; then + echo "❌ ERROR: Docker is not installed or not in PATH." + echo "Please install Docker Desktop or Docker Engine before running this script." + exit 1 +fi + +# Check if Docker daemon is running +if ! docker info >/dev/null 2>&1; then + echo "❌ ERROR: Docker daemon is not running." + echo "Please start Docker Desktop or Docker daemon before running this script." + exit 1 +fi + +# Check if AWS CLI is available +if ! command -v aws &> /dev/null; then + echo "❌ ERROR: AWS CLI is not installed or not in PATH." + echo "Please install AWS CLI before running this script." + exit 1 +fi + +# Check if AWS credentials are configured +if ! aws sts get-caller-identity >/dev/null 2>&1; then + echo "❌ ERROR: AWS credentials are not configured." + echo "Please run 'aws configure' or set up your AWS credentials before running this script." + exit 1 +fi + +echo "✅ All prerequisites are met." +echo "" + +# Prompt user for inputs + +# Get repository name +read -p "Enter ECR repository name (default: swift-chat-api): " REPO_NAME +REPO_NAME=${REPO_NAME:-swift-chat-api} + +# Get image tag +read -p "Enter image tag (default: latest): " TAG +TAG=${TAG:-latest} + +# Get AWS region +read -p "Enter AWS region (default: us-east-1): " AWS_REGION +AWS_REGION=${AWS_REGION:-us-east-1} + +echo "" +echo "Configuration:" +echo " Repository: $REPO_NAME" +echo " Image Tag: $TAG" +echo " AWS Region: $AWS_REGION" +echo "" +read -p "Continue with these settings? (y/n): " CONFIRM +if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then + echo "Aborted." + exit 1 +fi +echo "" + +# Acknowledgment about ECR repository creation +echo "ℹ️ NOTICE: This script will automatically create ECR repository if it doesn't exist." +echo " The repository will be created with the following default settings:" +echo " - Image tag mutability: MUTABLE (allows overwriting tags)" +echo " - Image scanning: Disabled" +echo " - Encryption: AES256 (AWS managed encryption)" +echo "" +echo " You can modify these settings later in the AWS ECR Console if needed." +echo " Required IAM permissions: ecr:CreateRepository, ecr:GetAuthorizationToken," +echo " ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart," +echo " ecr:CompleteLayerUpload, ecr:PutImage, ecr-public:GetAuthorizationToken" +echo "" +read -p "Do you acknowledge and want to proceed? (y/n): " ACK_CONFIRM +if [[ ! "$ACK_CONFIRM" =~ ^[Yy]$ ]]; then + echo "Aborted." + exit 1 +fi +echo "" + +build_and_push_image() { local IMAGE_NAME=$1 local TAG=$2 - local ENABLE_MULTI_ARCH=${3:-true} # Parameter for enabling multi-arch build, default is true - local DOCKERFILE_PATH=${4:-"../src/Dockerfile"} # Parameter for Dockerfile path, default is "../src/Dockerfile_ecs" - - # Build Docker image for each architecture - if [ "$ENABLE_MULTI_ARCH" == "true" ]; then - for ARCH in "${ARCHS[@]}" - do - # Build multi-architecture Docker image - docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG-$ARCH -f $DOCKERFILE_PATH --load ../src/ - done - else - # Build single architecture Docker image - docker buildx build --platform linux/${ARCHS[0]} -t $IMAGE_NAME:$TAG -f $DOCKERFILE_PATH --load ../src/ + local DOCKERFILE_PATH=$3 + local REGION=$AWS_REGION + local ARCH="amd64" # Single architecture for simplicity + + echo "Logging in to AWS Public ECR..." + # Log in to AWS Public ECR for pulling base images + if ! aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws; then + echo "❌ ERROR: Failed to login to AWS Public ECR. Please check your AWS credentials." + exit 1 + fi + + echo "Building $IMAGE_NAME:$TAG..." + + # Build Docker image + if ! docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG -f $DOCKERFILE_PATH --load ../src/; then + echo "❌ ERROR: Failed to build Docker image." + exit 1 + fi + + echo "Getting AWS account ID..." + # Get the account ID + if ! ACCOUNT_ID=$(aws sts get-caller-identity --region $REGION --query Account --output text 2>/dev/null); then + echo "❌ ERROR: Failed to get AWS account ID. Please check your AWS credentials and region." + exit 1 + fi + + # Create repository URI + REPOSITORY_URI="${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${IMAGE_NAME}" + + echo "Creating ECR repository if it doesn't exist..." + # Create ECR repository if it doesn't exist + aws ecr create-repository --repository-name "${IMAGE_NAME}" --region $REGION >/dev/null 2>&1 || true + + echo "Logging in to ECR..." + # Log in to ECR + if ! aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $REPOSITORY_URI; then + echo "❌ ERROR: Failed to login to ECR. Please check your AWS credentials and permissions." + exit 1 + fi + + echo "Tagging image for ECR..." + # Tag the image for ECR + if ! docker tag $IMAGE_NAME:$TAG $REPOSITORY_URI:$TAG; then + echo "❌ ERROR: Failed to tag Docker image." + exit 1 fi - # Push Docker image to ECR for each architecture in each AWS region - for REGION in "${AWS_REGIONS[@]}" - do - # Get the account ID for the current region - ACCOUNT_ID=$(aws sts get-caller-identity --region $REGION --query Account --output text) - - # Create repository URI - REPOSITORY_URI="${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${IMAGE_NAME}" - - # Create ECR repository if it doesn't exist - aws ecr create-repository --repository-name "${IMAGE_NAME}" --region $REGION || true - - # Log in to ECR - aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $REPOSITORY_URI - - # Push the image to ECR for each architecture - if [ "$ENABLE_MULTI_ARCH" == "true" ]; then - for ARCH in "${ARCHS[@]}" - do - # Tag the image for the current region - docker tag $IMAGE_NAME:$TAG-$ARCH $REPOSITORY_URI:$TAG-$ARCH - # Push the image to ECR - docker push $REPOSITORY_URI:$TAG-$ARCH - # Create a manifest for the image - docker manifest create $REPOSITORY_URI:$TAG $REPOSITORY_URI:$TAG-$ARCH --amend - # Annotate the manifest with architecture information - docker manifest annotate $REPOSITORY_URI:$TAG "$REPOSITORY_URI:$TAG-$ARCH" --os linux --arch $ARCH - done - - # Push the manifest to ECR - docker manifest push $REPOSITORY_URI:$TAG - else - # Tag the image for the current region - docker tag $IMAGE_NAME:$TAG $REPOSITORY_URI:$TAG - # Push the image to ECR - docker push $REPOSITORY_URI:$TAG - fi - - echo "Pushed $IMAGE_NAME:$TAG to $REPOSITORY_URI" - done + echo "Pushing image to ECR..." + # Push the image to ECR + if ! docker push $REPOSITORY_URI:$TAG; then + echo "❌ ERROR: Failed to push image to ECR." + exit 1 + fi + + echo "✅ Successfully pushed $IMAGE_NAME:$TAG to $REPOSITORY_URI" + echo "" + + # Return the image URI for later use + echo "$REPOSITORY_URI:$TAG" } -build_and_push_images "swift-chat-api" "$TAG" "true" "../src/Dockerfile" +echo "Building and pushing SwiftChat image..." +IMAGE_URI=$(build_and_push_image "$REPO_NAME" "$TAG" "../src/Dockerfile") + +echo "================================================" +echo "✅ Image successfully pushed!" +echo "================================================" +echo "" +echo "Your container image URI:" +echo " $IMAGE_URI" +echo "" +echo "Next steps:" +echo " 1. Download the CloudFormation templates from server/template/ folder" +echo " 2. Update the ContainerImageUri parameter with your image URI above" +echo " 3. Deploy the stack via AWS CloudFormation Console" +echo "" diff --git a/server/template/SwiftChatAppRunner.template b/server/template/SwiftChatAppRunner.template index 8d510f45..0394df42 100644 --- a/server/template/SwiftChatAppRunner.template +++ b/server/template/SwiftChatAppRunner.template @@ -18,6 +18,10 @@ "2 vCPU 4 GB" ], "Description": "Select CPU and Memory configuration" + }, + "ContainerImageUri": { + "Type": "String", + "Description": "The ECR image URI for the App Runner service (e.g., 123456789012.dkr.ecr.us-east-1.amazonaws.com/swift-chat-api:latest)" } }, "Resources": { @@ -190,7 +194,54 @@ { "Ref": "AWS::Region" }, - ":366590864501:repository/swift-chat-api" + ":", + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + ".", + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "/", + { + "Ref": "ContainerImageUri" + } + ] + } + ] + } + ] + } + ] + }, + ":repository/", + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + ":", + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "/", + { + "Ref": "ContainerImageUri" + } + ] + } + ] + } + ] + } + ] + } ] ] } @@ -321,20 +372,7 @@ ] }, "ImageIdentifier": { - "Fn::Join": [ - "", - [ - "366590864501.dkr.ecr.", - { - "Ref": "AWS::Region" - }, - ".", - { - "Ref": "AWS::URLSuffix" - }, - "/swift-chat-api:latest-amd64" - ] - ] + "Ref": "ContainerImageUri" }, "ImageRepositoryType": "ECR" } diff --git a/server/template/SwiftChatLambda.template b/server/template/SwiftChatLambda.template index b76fb66d..bbe3db22 100644 --- a/server/template/SwiftChatLambda.template +++ b/server/template/SwiftChatLambda.template @@ -7,6 +7,10 @@ "Description": "API Key Parameter name for authentication", "MinLength": 1, "NoEcho": false + }, + "ContainerImageUri": { + "Type": "String", + "Description": "The ECR image URI for the Lambda function (e.g., 123456789012.dkr.ecr.us-east-1.amazonaws.com/swift-chat-api:latest)" } }, "Resources": { @@ -161,20 +165,7 @@ ], "Code": { "ImageUri": { - "Fn::Join": [ - "", - [ - "366590864501.dkr.ecr.", - { - "Ref": "AWS::Region" - }, - ".", - { - "Ref": "AWS::URLSuffix" - }, - "/swift-chat-api:latest-arm64" - ] - ] + "Ref": "ContainerImageUri" } }, "Environment": { From 8fa06208e3674d6f31f0a955a52e242c3d053191 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Sun, 12 Oct 2025 21:21:09 +0800 Subject: [PATCH 2/6] docs: update README_CN.md --- README.md | 2 +- README_CN.md | 53 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5a0023da..2aaa599a 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ this [example](https://github.com/awslabs/aws-lambda-web-adapter/tree/main/examp acknowledge that AWS CloudFormation might create IAM resources" checkbox at the bottom. 5. Click **Next**, In the "Review and create" Review your configuration and click **Submit**. -Wait about 10-15 minutes for the deployment to finish, then click the CloudFormation stack and go to **Outputs** tab, you +Wait about 3–5 minutes for the deployment to finish, then click the CloudFormation stack and go to **Outputs** tab, you can find the **API URL** which looks like: `https://xxx.xxx.awsapprunner.com` or `https://xxx.lambda-url.xxx.on.aws` ### Step 4: Open the App and setup with API URL and API Key diff --git a/README_CN.md b/README_CN.md index 8cb44d81..ad43c9c4 100644 --- a/README_CN.md +++ b/README_CN.md @@ -74,36 +74,57 @@ SwiftChat 是一款快速响应的 AI 聊天应用,采用 [React Native](https 2. 检查您是否在 [支持的区域](#支持的区域),然后点击 **创建参数** 按钮。 3. 填入以下参数,其他选项保持默认: - - **名称**:输入参数名称(例如 "SwiftChatAPIKey",将在步骤 2 中用作 `ApiKeyParam`)。 + - **名称**:输入参数名称(例如 "SwiftChatAPIKey",将在步骤 3 中用作 `ApiKeyParam`)。 - **类型**:选择 `SecureString` - - **值**:输入任何不含空格的字符串(这将是步骤 3 中您的 `API Key`) + - **值**:输入任何不含空格的字符串(这将是步骤 4 中您的 `API Key`) 4. 点击 **创建参数**。 -### 步骤 2:部署堆栈并获取 API URL +### 步骤 2:构建并推送容器镜像到 ECR -1. 前往 [CloudFormation 控制台](https://console.aws.amazon.com/cloudformation/home#/stacks/create/template?stackName=SwiftChat),在**指定模板**下选择**上传模板文件**,然后使用以下模板之一进行部署。(确保您所在的区域与创建 API Key 的区域相同。) +1. 克隆此仓库: + ```bash + git clone https://github.com/aws-samples/swift-chat.git + cd swift-chat + ``` - - **App Runner** +2. 运行构建和推送脚本: + ```bash + cd server/scripts + bash ./push-to-ecr.sh + ``` - 打开 [SwiftChatAppRunner.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatAppRunner.template),然后下载并上传文件。 +3. 按照提示进行配置: + - ECR 仓库名称(或使用默认值:`swift-chat-api`) + - 镜像标签(或使用默认值:`latest`) + - AWS 区域(或使用默认值:`us-east-1`) - - **Lambda**(注意:仅供 AWS 客户使用) +4. 脚本将构建并推送 Docker 镜像到您的 ECR 仓库。 - 打开 [SwiftChatLambda.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatLambda.template),然后下载并上传文件。 +5. **重要**:复制脚本输出末尾显示的镜像 URI。您将在下一步中需要它。 -2. 点击 **下一步**,在"指定堆栈详细信息"页面,提供以下信息: - - 用您存储 API 密钥的参数名称填写 `ApiKeyParam`(例如 "SwiftChatAPIKey")。 - - 对于 App Runner,根据您的需求选择 `InstanceTypeParam`。 -3. 点击 **下一步**,保持"配置堆栈选项"页面为默认,阅读功能并勾选底部的"我确认 AWS CloudFormation 可能会创建 IAM 资源"复选框。 -4. 点击 **下一步**,在"审核并创建"中检查您的配置并点击 **提交**。 +### 步骤 3:部署堆栈并获取 API URL -等待约 3-5 分钟完成部署,然后点击 CloudFormation 堆栈并转到 **输出** 选项卡,您可以找到类似 -`https://xxx.xxx.awsapprunner.com` 或 `https://xxx.lambda-url.xxx.on.aws` 的 **API URL**。 +1. 下载您想使用的 CloudFormation 模板: + - App Runner:[SwiftChatAppRunner.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatAppRunner.template) + - Lambda:[SwiftChatLambda.template](https://github.com/aws-samples/swift-chat/blob/main/server/template/SwiftChatLambda.template) -### 步骤 3:打开应用并使用 API URL 和 API Key 进行设置 +2. 前往 [CloudFormation 控制台](https://console.aws.amazon.com/cloudformation/home#/stacks/create/template?stackName=SwiftChatAPI),在**指定模板**下选择**上传模板文件**,然后上传您下载的模板文件。(确保您所在的区域与创建 API Key 的区域相同。) + +3. 点击 **下一步**,在"指定堆栈详细信息"页面,提供以下信息: + - **Stack name**:保持默认的 "SwiftChatAPI" 或根据需要更改 + - **ApiKeyParam**:输入您用于存储 API 密钥的参数名称(例如 "SwiftChatAPIKey") + - **ContainerImageUri**:输入步骤 2 输出的 ECR 镜像 URI + - 对于 App Runner,根据您的需求选择 **InstanceTypeParam** + +4. 点击 **下一步**,保持"配置堆栈选项"页面为默认,阅读功能并勾选底部的"我确认 AWS CloudFormation 可能会创建 IAM 资源"复选框。 +5. 点击 **下一步**,在"审核并创建"中检查您的配置并点击 **提交**。 + +等待约 3-5 分钟完成部署,然后点击 CloudFormation 堆栈并转到 **输出** 选项卡,您可以找到 **API URL**,类似于:`https://xxx.xxx.awsapprunner.com` 或 `https://xxx.lambda-url.xxx.on.aws` + +### 步骤 4:打开应用并使用 API URL 和 API Key 进行设置 1. 启动应用,打开抽屉菜单,点击 **设置**。 2. 粘贴 `API URL` 和 `API Key`(您在 Parameter Store 中输入的 **值**)到 Amazon Bedrock -> SwiftChat Server 下,然后选择您的区域。 From 296f99935afb9d6f871886075901c2e482cd0001 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Sun, 12 Oct 2025 21:30:53 +0800 Subject: [PATCH 3/6] feat: remove release-template.yml, add permission for action --- .github/workflows/build-android.yml | 4 ++- .github/workflows/build-ios.yml | 4 ++- .github/workflows/code-lint.yml | 4 ++- .github/workflows/release-template.yml | 41 -------------------------- .github/workflows/release.yml | 3 ++ 5 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 .github/workflows/release-template.yml diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.yml index 4a9e2f67..79cdffde 100644 --- a/.github/workflows/build-android.yml +++ b/.github/workflows/build-android.yml @@ -5,7 +5,9 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] - +permissions: + contents: read + pull-requests: write jobs: build-android: runs-on: ubuntu-latest diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index 35dcfe56..8dee7cae 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -5,7 +5,9 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] - +permissions: + contents: read + pull-requests: write jobs: build-ios: runs-on: macos-latest diff --git a/.github/workflows/code-lint.yml b/.github/workflows/code-lint.yml index fc4a74e4..5aeada0d 100644 --- a/.github/workflows/code-lint.yml +++ b/.github/workflows/code-lint.yml @@ -5,7 +5,9 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] - +permissions: + contents: read + pull-requests: write jobs: code-lint: runs-on: ubuntu-latest diff --git a/.github/workflows/release-template.yml b/.github/workflows/release-template.yml deleted file mode 100644 index 07fdf900..00000000 --- a/.github/workflows/release-template.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Release Template - -on: - workflow_dispatch: - inputs: - reason: - description: 'the reason for triggering this workflow' - required: false - default: 'manually publish the ecr images and templates' -jobs: - release_template: - runs-on: ubuntu-latest - permissions: - id-token: write - contents: read - env: - iam_role_to_assume: ${{ secrets.ROLE_ARN }} - steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Configure AWS Credentials - if: ${{ env.iam_role_to_assume != '' }} - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: ${{ env.iam_role_to_assume }} - aws-region: us-east-1 - - name: Build and Publish - run: |- - cd server/scripts - bash push-to-ecr.sh - - name: Copy Deployment Templates to S3 - env: - S3_BUCKET: ${{ secrets.ASSET_BUCKET }} - S3_PREFIX: swift-chat/latest/ - run: aws s3 sync server/template/ s3://$S3_BUCKET/$S3_PREFIX --acl public-read diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08be5063..fbf4167c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,9 @@ on: description: 'Release Version Code' required: true type: string +permissions: + contents: read + pull-requests: write env: NEW_VERSION: ${{ github.event.inputs.release_tag }} NEW_VERSION_CODE: ${{ github.event.inputs.release_code }} From 37e35840b7bc120f9b6061231d77a6ed2cc55196 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Sun, 12 Oct 2025 22:16:46 +0800 Subject: [PATCH 4/6] feat: support input build arch --- server/scripts/push-to-ecr.sh | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/server/scripts/push-to-ecr.sh b/server/scripts/push-to-ecr.sh index 88c782d6..a98be595 100644 --- a/server/scripts/push-to-ecr.sh +++ b/server/scripts/push-to-ecr.sh @@ -60,11 +60,37 @@ TAG=${TAG:-latest} read -p "Enter AWS region (default: us-east-1): " AWS_REGION AWS_REGION=${AWS_REGION:-us-east-1} +# Get deployment type +echo "" +echo "Select deployment type:" +echo " 1) AppRunner (default) - uses amd64 architecture" +echo " 2) Lambda - uses arm64 architecture" +read -p "Enter deployment type (1 or 2, default: 1): " DEPLOY_TYPE +DEPLOY_TYPE=${DEPLOY_TYPE:-1} + +# Determine architecture based on deployment type +case $DEPLOY_TYPE in + 1) + DEPLOY_TYPE_NAME="AppRunner" + ARCH="amd64" + ;; + 2) + DEPLOY_TYPE_NAME="Lambda" + ARCH="arm64" + ;; + *) + echo "❌ ERROR: Invalid deployment type. Please enter 1 or 2." + exit 1 + ;; +esac + echo "" echo "Configuration:" echo " Repository: $REPO_NAME" echo " Image Tag: $TAG" echo " AWS Region: $AWS_REGION" +echo " Deployment Type: $DEPLOY_TYPE_NAME" +echo " Architecture: $ARCH" echo "" read -p "Continue with these settings? (y/n): " CONFIRM if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then @@ -96,8 +122,8 @@ build_and_push_image() { local IMAGE_NAME=$1 local TAG=$2 local DOCKERFILE_PATH=$3 + local BUILD_ARCH=$4 local REGION=$AWS_REGION - local ARCH="amd64" # Single architecture for simplicity echo "Logging in to AWS Public ECR..." # Log in to AWS Public ECR for pulling base images @@ -106,10 +132,10 @@ build_and_push_image() { exit 1 fi - echo "Building $IMAGE_NAME:$TAG..." + echo "Building $IMAGE_NAME:$TAG for linux/$BUILD_ARCH..." # Build Docker image - if ! docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG -f $DOCKERFILE_PATH --load ../src/; then + if ! docker buildx build --platform linux/$BUILD_ARCH -t $IMAGE_NAME:$TAG -f $DOCKERFILE_PATH --load ../src/; then echo "❌ ERROR: Failed to build Docker image." exit 1 fi @@ -157,7 +183,7 @@ build_and_push_image() { } echo "Building and pushing SwiftChat image..." -IMAGE_URI=$(build_and_push_image "$REPO_NAME" "$TAG" "../src/Dockerfile") +IMAGE_URI=$(build_and_push_image "$REPO_NAME" "$TAG" "../src/Dockerfile" "$ARCH") echo "================================================" echo "✅ Image successfully pushed!" From 28f2b3b746604b2ca503f7ac126d7bc3ebdce073 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Sun, 12 Oct 2025 22:35:02 +0800 Subject: [PATCH 5/6] docs: update doc for arch selection --- README.md | 3 +++ README_CN.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 2aaa599a..8a256358 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,9 @@ this [example](https://github.com/awslabs/aws-lambda-web-adapter/tree/main/examp - ECR repository name (or use default: `swift-chat-api`) - Image tag (or use default: `latest`) - AWS region (or use default: `us-east-1`) + - Deployment type: + - Option 1 (default): **AppRunner** - uses amd64 architecture + - Option 2: **Lambda** - uses arm64 architecture 4. The script will build and push the Docker image to your ECR repository. diff --git a/README_CN.md b/README_CN.md index ad43c9c4..1b9ebb65 100644 --- a/README_CN.md +++ b/README_CN.md @@ -100,6 +100,9 @@ SwiftChat 是一款快速响应的 AI 聊天应用,采用 [React Native](https - ECR 仓库名称(或使用默认值:`swift-chat-api`) - 镜像标签(或使用默认值:`latest`) - AWS 区域(或使用默认值:`us-east-1`) + - 部署类型: + - 选项 1(默认):**AppRunner** - 使用 amd64 架构 + - 选项 2:**Lambda** - 使用 arm64 架构 4. 脚本将构建并推送 Docker 镜像到您的 ECR 仓库。 From 26b083fd9e4e2ff826686b617a5ae1df611cedc1 Mon Sep 17 00:00:00 2001 From: xiaoweii Date: Mon, 13 Oct 2025 08:35:33 +0800 Subject: [PATCH 6/6] docs: update region selection --- README.md | 4 ++-- README_CN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a256358..d2f5e78a 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,8 @@ this [example](https://github.com/awslabs/aws-lambda-web-adapter/tree/main/examp 3. Follow the prompts to configure: - ECR repository name (or use default: `swift-chat-api`) - - Image tag (or use default: `latest`) - - AWS region (or use default: `us-east-1`) + - Image tag (please use default: `latest`) + - AWS region (the region you want to deploy, e.g.,: `us-east-1`) - Deployment type: - Option 1 (default): **AppRunner** - uses amd64 architecture - Option 2: **Lambda** - uses arm64 architecture diff --git a/README_CN.md b/README_CN.md index 1b9ebb65..2c10e2bd 100644 --- a/README_CN.md +++ b/README_CN.md @@ -98,8 +98,8 @@ SwiftChat 是一款快速响应的 AI 聊天应用,采用 [React Native](https 3. 按照提示进行配置: - ECR 仓库名称(或使用默认值:`swift-chat-api`) - - 镜像标签(或使用默认值:`latest`) - - AWS 区域(或使用默认值:`us-east-1`) + - 镜像标签(请使用默认值:`latest`) + - AWS 区域(填写你希望部署的区域,例如:`us-east-1`) - 部署类型: - 选项 1(默认):**AppRunner** - 使用 amd64 架构 - 选项 2:**Lambda** - 使用 arm64 架构