Skip to content

feat(mono): Support automatically creating a CL and triggering the bu… #309

feat(mono): Support automatically creating a CL and triggering the bu…

feat(mono): Support automatically creating a CL and triggering the bu… #309

name: Mono Engine deploy
on:
push:
branches:
- main
paths-ignore:
- ".devcontainer/**"
- ".github/**"
- "config/**"
- "docker/**"
- "docs/**"
- "extensions/**"
- "moon/**"
- "orion/**"
- "orion-server/**"
- "scorpio/**"
- "scripts/**"
- "tests/**"
env:
AWS_ECS_CLUSTER_NAME: ${{ secrets.AWS_ECS_CLUSTER_NAME }}
AWS_ECS_MONO_SERVICE_NAME: ${{ secrets.AWS_ECS_MONO_SERVICE_NAME }}
REGISTRY_ALIAS: m8q5m4u3
REPOSITORY: mega
IMAGE_TAG_BASE: mono-0.1.0-pre-release
# Using AWS access key for authentication
permissions:
id-token: write
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-push-single-arch:
if: ${{ github.repository == 'web3infra-foundation/mega' }}
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64]
timeout-minutes: 30
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build & push image for ${{ matrix.platform }}
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
PLATFORM: ${{ matrix.platform }}
run: |
set -euo pipefail
IMAGE_BASE="$REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}"
ARCH_SUFFIX=$(echo "$PLATFORM" | awk -F'/' '{print $2}')
docker buildx build \
--platform "$PLATFORM" \
--provenance=false \
--sbom=false \
-t "$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-$ARCH_SUFFIX" \
-f ./mono/Dockerfile \
--push .
manifest:
needs: build-push-single-arch
runs-on: ubuntu-latest
if: ${{ github.repository == 'web3infra-foundation/mega' }}
permissions:
contents: read
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Create & push manifest
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
run: |
IMAGE_BASE="$REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}"
docker manifest create "$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}" \
"$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-amd64" \
"$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-arm64"
docker manifest push "$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}"
deploy:
needs: manifest
if: ${{ github.repository == 'web3infra-foundation/mega' }}
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
include:
- cluster: gitmega-com
service: mono-engine-dev-service-xnmoxhxb
- cluster: gitmono-com-mega-app
service: mono-engine
steps:
- name: Force ECS redeploy
run: |
aws ecs update-service \
--cluster ${{ matrix.cluster }} \
--service ${{ matrix.service }} \
--force-new-deployment
env:
AWS_REGION: ap-southeast-2
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}