feat: some api (#1984) #77
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Orion server deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - ".github/workflows/orion-server-deploy.yml" | |
| - "orion-server/**" | |
| env: | |
| REGISTRY_ALIAS: m8q5m4u3 | |
| REPOSITORY: mega | |
| IMAGE_TAG_BASE: orion-server-0.1.0-pre-release | |
| GCP_PROJECT_ID: infra-20250121-20260121-0235 | |
| GCP_REPOSITORY: mega | |
| permissions: | |
| id-token: write | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-push-single-arch: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # ----------------------------- | |
| # AWS auth | |
| # ----------------------------- | |
| - 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 | |
| # ----------------------------- | |
| # GCP auth | |
| # ----------------------------- | |
| - name: Auth to GCP | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Configure docker for GCP | |
| run: | | |
| gcloud auth configure-docker us-central1-docker.pkg.dev | |
| # ----------------------------- | |
| # Build once, push to AWS + GCP | |
| # ----------------------------- | |
| - name: Build & push amd64 image to AWS and GCP | |
| env: | |
| AWS_REGISTRY: ${{ steps.login-ecr-public.outputs.registry }} | |
| run: | | |
| set -euo pipefail | |
| PLATFORM="linux/amd64" | |
| ARCH_SUFFIX="amd64" | |
| AWS_IMAGE_BASE="$AWS_REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}" | |
| GCP_IMAGE_BASE="us-central1-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.REPOSITORY }}" | |
| TAG="${{ env.IMAGE_TAG_BASE }}-$ARCH_SUFFIX" | |
| docker buildx build \ | |
| --platform "$PLATFORM" \ | |
| --provenance=false \ | |
| --sbom=false \ | |
| -f orion-server/Dockerfile \ | |
| -t "$AWS_IMAGE_BASE:$TAG" \ | |
| -t "$GCP_IMAGE_BASE:$TAG" \ | |
| --push . | |
| manifest: | |
| needs: build-push-single-arch | |
| runs-on: ubuntu-latest | |
| 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-aws: | |
| needs: manifest | |
| if: ${{ github.repository == 'web3infra-foundation/mega' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| strategy: | |
| matrix: | |
| include: | |
| - cluster: gitmega-com | |
| service: orion-server-dev-service-om0caign | |
| - cluster: gitmono-com-mega-app | |
| service: orion-server-service | |
| 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 }} | |
| deploy-gcp: | |
| needs: manifest | |
| # if: ${{ github.repository == 'web3infra-foundation/mega' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Auth to GCP | |
| uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Deploy to Cloud Run (force new revision) | |
| env: | |
| REGION: asia-east1 | |
| SERVICE_NAME: buck2hub-orion | |
| run: | | |
| set -euo pipefail | |
| IMAGE=$(gcloud run services describe $SERVICE_NAME \ | |
| --project "$GCP_PROJECT_ID" \ | |
| --region "$REGION" \ | |
| --format="value(spec.template.spec.containers[0].image)") | |
| echo "Current image: $IMAGE" | |
| gcloud run deploy $SERVICE_NAME \ | |
| --image "$IMAGE" \ | |
| --region "$REGION" \ | |
| --project "$GCP_PROJECT_ID" \ | |
| --quiet |