Build and Push Astron RPA Backend Services #30
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: Build and Push Astron RPA Backend Services | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| push_images: | |
| description: 'Push images to registry' | |
| required: false | |
| default: true | |
| type: boolean | |
| services: | |
| description: 'Services to build (comma-separated: ai-service,openapi-service,resource-service,robot-service,rpa-auth)' | |
| required: false | |
| default: 'ai-service,openapi-service,resource-service,robot-service,rpa-auth' | |
| type: string | |
| concurrency: | |
| group: build-push-backend-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| packages: write | |
| attestations: write | |
| id-token: write | |
| env: | |
| REGISTRY_GHCR: ghcr.io | |
| jobs: | |
| # ============================================================================ | |
| # Stage 1: Project Detection and Metadata | |
| # ============================================================================ | |
| detect-and-prepare: | |
| name: π Detection & Metadata | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.meta.outputs.version }} | |
| should-push: ${{ steps.meta.outputs.should-push }} | |
| platforms: ${{ steps.meta.outputs.platforms }} | |
| services: ${{ steps.meta.outputs.services }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract metadata | |
| id: meta | |
| run: | | |
| # Determine version based on trigger | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| else | |
| VERSION="latest" | |
| fi | |
| # Determine if should push (always true for releases, configurable for manual dispatch) | |
| SHOULD_PUSH="false" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| SHOULD_PUSH="true" | |
| elif [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.push_images }}" == "true" ]]; then | |
| SHOULD_PUSH="true" | |
| fi | |
| # Set platforms (multi-arch builds for better compatibility) | |
| PLATFORMS="linux/amd64,linux/arm64" | |
| # Determine services to build | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ github.event.inputs.services }}" ]]; then | |
| SERVICES="${{ github.event.inputs.services }}" | |
| else | |
| SERVICES="ai-service,openapi-service,resource-service,robot-service,rpa-auth" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "should-push=$SHOULD_PUSH" >> $GITHUB_OUTPUT | |
| echo "platforms=$PLATFORMS" >> $GITHUB_OUTPUT | |
| echo "services=$SERVICES" >> $GITHUB_OUTPUT | |
| echo "π·οΈ Version: $VERSION" | |
| echo "π€ Should push: $SHOULD_PUSH" | |
| echo "ποΈ Platforms: $PLATFORMS" | |
| echo "π§ Services: $SERVICES" | |
| # ============================================================================ | |
| # Stage 2: Build Backend Services (Parallel Jobs) | |
| # ============================================================================ | |
| build-ai-service: | |
| name: π€ Build AI Service | |
| runs-on: ubuntu-latest | |
| needs: detect-and-prepare | |
| if: contains(needs.detect-and-prepare.outputs.services, 'ai-service') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| if: needs.detect-and-prepare.outputs.should-push == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY_GHCR }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/ai-service | |
| tags: | | |
| type=raw,value=${{ needs.detect-and-prepare.outputs.version }} | |
| ${{ github.event_name == 'release' && 'type=raw,value=latest' || '' }} | |
| - name: Build and push AI Service image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./backend/ai-service/Dockerfile | |
| platforms: ${{ needs.detect-and-prepare.outputs.platforms }} | |
| push: ${{ needs.detect-and-prepare.outputs.should-push }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ needs.detect-and-prepare.outputs.version }} | |
| GIT_COMMIT=${{ github.sha }} | |
| BUILD_TIME=${{ github.run_id }} | |
| cache-from: type=gha,scope=ai-service | |
| cache-to: type=gha,scope=ai-service,mode=max | |
| build-openapi-service: | |
| name: π Build OpenAPI Service | |
| runs-on: ubuntu-latest | |
| needs: detect-and-prepare | |
| if: contains(needs.detect-and-prepare.outputs.services, 'openapi-service') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| if: needs.detect-and-prepare.outputs.should-push == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY_GHCR }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/openapi-service | |
| tags: | | |
| type=raw,value=${{ needs.detect-and-prepare.outputs.version }} | |
| ${{ github.event_name == 'release' && 'type=raw,value=latest' || '' }} | |
| - name: Build and push OpenAPI Service image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./backend/openapi-service/Dockerfile | |
| platforms: ${{ needs.detect-and-prepare.outputs.platforms }} | |
| push: ${{ needs.detect-and-prepare.outputs.should-push }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ needs.detect-and-prepare.outputs.version }} | |
| GIT_COMMIT=${{ github.sha }} | |
| BUILD_TIME=${{ github.run_id }} | |
| cache-from: type=gha,scope=openapi-service | |
| cache-to: type=gha,scope=openapi-service,mode=max | |
| build-resource-service: | |
| name: π¦ Build Resource Service | |
| runs-on: ubuntu-latest | |
| needs: detect-and-prepare | |
| if: contains(needs.detect-and-prepare.outputs.services, 'resource-service') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| if: needs.detect-and-prepare.outputs.should-push == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY_GHCR }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/resource-service | |
| tags: | | |
| type=raw,value=${{ needs.detect-and-prepare.outputs.version }} | |
| ${{ github.event_name == 'release' && 'type=raw,value=latest' || '' }} | |
| - name: Build and push Resource Service image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./backend/resource-service/Dockerfile | |
| platforms: ${{ needs.detect-and-prepare.outputs.platforms }} | |
| push: ${{ needs.detect-and-prepare.outputs.should-push }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ needs.detect-and-prepare.outputs.version }} | |
| GIT_COMMIT=${{ github.sha }} | |
| BUILD_TIME=${{ github.run_id }} | |
| cache-from: type=gha,scope=resource-service | |
| cache-to: type=gha,scope=resource-service,mode=max | |
| build-robot-service: | |
| name: π€ Build Robot Service | |
| runs-on: ubuntu-latest | |
| needs: detect-and-prepare | |
| if: contains(needs.detect-and-prepare.outputs.services, 'robot-service') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| if: needs.detect-and-prepare.outputs.should-push == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY_GHCR }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/robot-service | |
| tags: | | |
| type=raw,value=${{ needs.detect-and-prepare.outputs.version }} | |
| ${{ github.event_name == 'release' && 'type=raw,value=latest' || '' }} | |
| - name: Build and push Robot Service image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./backend/robot-service/Dockerfile | |
| platforms: ${{ needs.detect-and-prepare.outputs.platforms }} | |
| push: ${{ needs.detect-and-prepare.outputs.should-push }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ needs.detect-and-prepare.outputs.version }} | |
| GIT_COMMIT=${{ github.sha }} | |
| BUILD_TIME=${{ github.run_id }} | |
| cache-from: type=gha,scope=robot-service | |
| cache-to: type=gha,scope=robot-service,mode=max | |
| build-rpa-auth: | |
| name: π Build RPA Auth | |
| runs-on: ubuntu-latest | |
| needs: detect-and-prepare | |
| if: contains(needs.detect-and-prepare.outputs.services, 'rpa-auth') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| if: needs.detect-and-prepare.outputs.should-push == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY_GHCR }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/rpa-auth | |
| tags: | | |
| type=raw,value=${{ needs.detect-and-prepare.outputs.version }} | |
| ${{ github.event_name == 'release' && 'type=raw,value=latest' || '' }} | |
| - name: Build and push RPA Auth image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./backend/rpa-auth/Dockerfile | |
| platforms: ${{ needs.detect-and-prepare.outputs.platforms }} | |
| push: ${{ needs.detect-and-prepare.outputs.should-push }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| VERSION=${{ needs.detect-and-prepare.outputs.version }} | |
| GIT_COMMIT=${{ github.sha }} | |
| BUILD_TIME=${{ github.run_id }} | |
| cache-from: type=gha,scope=rpa-auth | |
| cache-to: type=gha,scope=rpa-auth,mode=max | |
| # ============================================================================ | |
| # Stage 3: Summary and Notifications | |
| # ============================================================================ | |
| build-summary: | |
| name: π Build Summary | |
| runs-on: ubuntu-latest | |
| needs: | |
| - detect-and-prepare | |
| - build-ai-service | |
| - build-openapi-service | |
| - build-resource-service | |
| - build-robot-service | |
| - build-rpa-auth | |
| if: always() | |
| steps: | |
| - name: Generate build summary | |
| run: | | |
| echo "=== π³ astron RPA Backend Services Docker Build Summary ===" | |
| echo "" | |
| echo "π Project Detection: ${{ needs.detect-and-prepare.result }}" | |
| echo "π Version: ${{ needs.detect-and-prepare.outputs.version }}" | |
| echo "π€ Push to Registry: ${{ needs.detect-and-prepare.outputs.should-push }}" | |
| echo "ποΈ Target Platforms: ${{ needs.detect-and-prepare.outputs.platforms }}" | |
| echo "π§ Services: ${{ needs.detect-and-prepare.outputs.services }}" | |
| echo "" | |
| echo "π³ Docker Build Results:" | |
| echo " π€ AI Service: ${{ needs.build-ai-service.result }}" | |
| echo " π OpenAPI Service: ${{ needs.build-openapi-service.result }}" | |
| echo " π¦ Resource Service: ${{ needs.build-resource-service.result }}" | |
| echo " π€ Robot Service: ${{ needs.build-robot-service.result }}" | |
| echo " π RPA Auth: ${{ needs.build-rpa-auth.result }}" | |
| echo "" | |
| # Count successful builds | |
| SUCCESS_COUNT=0 | |
| TOTAL_COUNT=0 | |
| # Check each service based on what was requested | |
| if [[ "${{ needs.detect-and-prepare.outputs.services }}" == *"ai-service"* ]]; then | |
| TOTAL_COUNT=$((TOTAL_COUNT + 1)) | |
| [[ "${{ needs.build-ai-service.result }}" == "success" ]] && SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.detect-and-prepare.outputs.services }}" == *"openapi-service"* ]]; then | |
| TOTAL_COUNT=$((TOTAL_COUNT + 1)) | |
| [[ "${{ needs.build-openapi-service.result }}" == "success" ]] && SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.detect-and-prepare.outputs.services }}" == *"resource-service"* ]]; then | |
| TOTAL_COUNT=$((TOTAL_COUNT + 1)) | |
| [[ "${{ needs.build-resource-service.result }}" == "success" ]] && SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.detect-and-prepare.outputs.services }}" == *"robot-service"* ]]; then | |
| TOTAL_COUNT=$((TOTAL_COUNT + 1)) | |
| [[ "${{ needs.build-robot-service.result }}" == "success" ]] && SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| if [[ "${{ needs.detect-and-prepare.outputs.services }}" == *"rpa-auth"* ]]; then | |
| TOTAL_COUNT=$((TOTAL_COUNT + 1)) | |
| [[ "${{ needs.build-rpa-auth.result }}" == "success" ]] && SUCCESS_COUNT=$((SUCCESS_COUNT + 1)) | |
| fi | |
| echo "π Build Success Rate: $SUCCESS_COUNT/$TOTAL_COUNT services built successfully" | |
| if [[ "${{ needs.detect-and-prepare.outputs.should-push }}" == "true" ]]; then | |
| echo "" | |
| echo "π― Published Images:" | |
| if [[ "${{ needs.build-ai-service.result }}" == "success" ]]; then | |
| echo " π€ ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/ai-service:${{ needs.detect-and-prepare.outputs.version }}" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| echo " π€ ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/ai-service:latest" | |
| fi | |
| fi | |
| if [[ "${{ needs.build-openapi-service.result }}" == "success" ]]; then | |
| echo " π ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/openapi-service:${{ needs.detect-and-prepare.outputs.version }}" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| echo " π ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/openapi-service:latest" | |
| fi | |
| fi | |
| if [[ "${{ needs.build-resource-service.result }}" == "success" ]]; then | |
| echo " π¦ ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/resource-service:${{ needs.detect-and-prepare.outputs.version }}" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| echo " π¦ ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/resource-service:latest" | |
| fi | |
| fi | |
| if [[ "${{ needs.build-robot-service.result }}" == "success" ]]; then | |
| echo " π€ ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/robot-service:${{ needs.detect-and-prepare.outputs.version }}" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| echo " π€ ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/robot-service:latest" | |
| fi | |
| fi | |
| if [[ "${{ needs.build-rpa-auth.result }}" == "success" ]]; then | |
| echo " π ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/rpa-auth:${{ needs.detect-and-prepare.outputs.version }}" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| echo " π ${{ env.REGISTRY_GHCR }}/${{ github.repository }}/rpa-auth:latest" | |
| fi | |
| fi | |
| fi | |
| if [[ "$SUCCESS_COUNT" == "$TOTAL_COUNT" && "$TOTAL_COUNT" -gt 0 ]]; then | |
| echo "" | |
| echo "β π All requested backend services built successfully!" | |
| if [[ "${{ needs.detect-and-prepare.outputs.should-push }}" == "true" ]]; then | |
| echo "π Images are now available in GitHub Container Registry" | |
| else | |
| echo "π¦ Images built locally (not pushed to registry)" | |
| fi | |
| elif [[ "$TOTAL_COUNT" -eq 0 ]]; then | |
| echo "" | |
| echo "β οΈ No services were requested to be built" | |
| else | |
| echo "" | |
| echo "β π¨ Some Docker builds failed - check individual job results" | |
| exit 1 | |
| fi | |
| # Additional info for manual workflow dispatch | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "" | |
| echo "π§ Manual Workflow Dispatch Summary:" | |
| echo " Trigger: ${{ github.actor }}" | |
| echo " Ref: ${{ github.ref }}" | |
| echo " Build Type: latest (based on current code)" | |
| echo " Push Images: ${{ github.event.inputs.push_images }}" | |
| echo " Services: ${{ github.event.inputs.services }}" | |
| fi |