chore: add automation script to release images (#58)
This commit is contained in:
35
.github/workflows/release.yml
vendored
Normal file
35
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: release
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
reason:
|
||||||
|
description: 'the reason for triggering this workflow'
|
||||||
|
required: false
|
||||||
|
default: 'manually publish the pre-built ecr images'
|
||||||
|
jobs:
|
||||||
|
ecr_images:
|
||||||
|
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 scripts
|
||||||
|
bash push-to-ecr.sh
|
||||||
@@ -1,35 +1,62 @@
|
|||||||
# Make sure you have created the Repo in AWS ECR in every regions you want to push to before executing this script.
|
# 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:
|
# Usage:
|
||||||
# cd scripts
|
# cd scripts
|
||||||
# chmod +x push-to-ecr.sh
|
# bash ./push-to-ecr.sh
|
||||||
# ./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
|
# Define variables
|
||||||
IMAGE_NAME="bedrock-proxy-api"
|
|
||||||
TAG="latest"
|
TAG="latest"
|
||||||
AWS_REGIONS=("us-west-2") # List of AWS regions
|
ARCHS=("arm64" "amd64")
|
||||||
#AWS_REGIONS=("us-east-1" "us-west-2" "eu-central-1" "ap-southeast-1" "ap-northeast-1") # List of AWS regions
|
AWS_REGIONS=("us-east-1") # List of AWS region, use below liest if you don't enable ECR repository replication
|
||||||
|
# AWS_REGIONS=("us-east-1" "us-west-2" "eu-central-1" "ap-southeast-1" "ap-southeast-2" "ap-northeast-1" "eu-central-1" "eu-west-3") # List of supported AWS regions
|
||||||
|
|
||||||
# Build Docker image
|
build_and_push_images() {
|
||||||
docker build -t $IMAGE_NAME:$TAG ../src/
|
local IMAGE_NAME=$1
|
||||||
|
local TAG=$2
|
||||||
|
|
||||||
# Loop through each AWS region
|
# Build Docker image for each architecture
|
||||||
for REGION in "${AWS_REGIONS[@]}"
|
for ARCH in "${ARCHS[@]}"
|
||||||
do
|
do
|
||||||
# Get the account ID for the current region
|
docker buildx build --platform linux/$ARCH -t $IMAGE_NAME:$TAG-$ARCH -f ../src/Dockerfile_ecs --load ../src/
|
||||||
ACCOUNT_ID=$(aws sts get-caller-identity --region $REGION --query Account --output text)
|
done
|
||||||
|
|
||||||
# Create repository URI
|
# Push Docker image to ECR for each architecture in each AWS region
|
||||||
REPOSITORY_URI="${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${IMAGE_NAME}"
|
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)
|
||||||
|
|
||||||
# Log in to ECR
|
# Create repository URI
|
||||||
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $REPOSITORY_URI
|
REPOSITORY_URI="${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/${IMAGE_NAME}"
|
||||||
|
|
||||||
# Tag the image for the current region
|
# Create ECR repository if it doesn't exist
|
||||||
docker tag $IMAGE_NAME:$TAG $REPOSITORY_URI:$TAG
|
aws ecr create-repository --repository-name "${IMAGE_NAME}" --region $REGION || true
|
||||||
|
|
||||||
# Push the image to ECR
|
# Log in to ECR
|
||||||
docker push $REPOSITORY_URI:$TAG
|
aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $REPOSITORY_URI
|
||||||
echo "Pushed $IMAGE_NAME:$TAG to $REPOSITORY_URI"
|
|
||||||
done
|
# Push the image to ECR for each architecture
|
||||||
|
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
|
||||||
|
|
||||||
|
echo "Pushed $IMAGE_NAME:$TAG to $REPOSITORY_URI"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
build_and_push_images "bedrock-proxy-api" "$TAG"
|
||||||
|
build_and_push_images "bedrock-proxy-api-ecs" "$TAG"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.12-slim
|
FROM public.ecr.aws/docker/library/python:3.12-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user