Workflow file for this run
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: Push to ECR | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| architecture: | ||
| description: 'architecture' | ||
| type: string | ||
| required: true | ||
| environment: | ||
| description: 'environment' | ||
| type: string | ||
| required: true | ||
| secrets: | ||
| role: | ||
| description: 'AWS role to assume' | ||
| required: true | ||
| account_id: | ||
| description: 'AWS account id' | ||
| required: true | ||
| devRegion: | ||
| description: 'AWS region for DEV' | ||
| required: true | ||
| prodRegion: | ||
| description: 'AWS region for PROD' | ||
| required: true | ||
| jobs: | ||
| setup: | ||
| runs-on: ubuntu-24.04 | ||
| outputs: | ||
| runner: ${{ steps.select.outputs.runner }} | ||
| matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
| steps: | ||
| - name: Check branch | ||
| id: select | ||
| run: | | ||
| if [ ${{ inputs.architecture }} == 'x86_64' ]; then | ||
| echo "runner=ubuntu-24.04" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "runner=ubuntu-24.04-arm" >> $GITHUB_OUTPUT | ||
| fi | ||
| cat $GITHUB_OUTPUT | ||
| - uses: actions/checkout@v4 | ||
| - name: Build runtime matrix | ||
| id: set-matrix | ||
| run: | | ||
| jq -c '[.runtimes[] | select(.architectures | index("arm64")) | select(.image != null and .image.baseImage != null) | .path]' manifest.json | ||
| echo "matrix=$(jq -c '[.runtimes[] | select(.architectures | index("${{ inputs.architecture }}")) | select(.image != null and .image.baseImage != null) | .path]' manifest.json)" >> $GITHUB_OUTPUT | ||
| build-upload: | ||
| needs: setup | ||
| runs-on: ${{ needs.setup.outputs.runner }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| runtime_id: ${{fromJson(needs.setup.outputs.matrix)}} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: configure aws credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: ${{ secrets.role }} | ||
| role-session-name: GitHub_Action_LambdaPerf_Session | ||
| aws-region: ${{ inputs.environment == 'DEV' && secrets.devRegion || inputs.environment == 'PROD' && secrets.prodRegion }} | ||
| - name: Delete huge unnecessary folders | ||
| run: | | ||
| rm -rf /opt/hostedtoolcache | ||
| rm -rf /usr/share/dotnet | ||
| rm -rf /opt/ghc | ||
| rm -rf "$AGENT_TOOLSDIRECTORY" | ||
| - name: Set up Docker | ||
| uses: docker/setup-docker-action@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| - name: build and deploy | ||
| env: | ||
| ARCHITECTURE: ${{ inputs.architecture }} | ||
| AWS_REGION: ${{ inputs.environment == 'DEV' && secrets.devRegion || inputs.environment == 'PROD' && secrets.prodRegion }} | ||
| RUNTIME_ID: ${{ matrix.runtime_id }} | ||
| AWS_ACCOUNT_ID: ${{ secrets.account_id }} | ||
| run: | | ||
| cd container-uploader | ||
| yarn install | ||
| node app.mjs | ||
| clean-untagged-image: | ||
| needs: build-upload | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: configure aws credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: ${{ secrets.role }} | ||
| role-session-name: GitHub_Action_LambdaPerf_Session | ||
| aws-region: ${{ inputs.environment == 'DEV' && secrets.devRegion || inputs.environment == 'PROD' && secrets.prodRegion }} | ||
| - name: clean untagged images | ||
| env: | ||
| AWS_REGION: ${{ inputs.environment == 'DEV' && secrets.devRegion || inputs.environment == 'PROD' && secrets.prodRegion }} | ||
| run: | | ||
| echo "Fetching untagged images..." | ||
| IMAGES=$(aws ecr list-images \ | ||
| --region "${AWS_REGION}" \ | ||
| --repository-name lambda-perf \ | ||
| --filter "tagStatus=UNTAGGED" \ | ||
| --query 'imageIds' \ | ||
| --output json) | ||
| COUNT=$(echo "$IMAGES" | jq length) | ||
| if [ "$COUNT" -eq 0 ]; then | ||
| echo "No untagged images found. Skipping deletion." | ||
| exit 0 | ||
| fi | ||
| echo "Found $COUNT untagged images. Deleting in batches of 100..." | ||
| # Split into chunks of 100 | ||
| echo "$IMAGES" | jq -c '.[]' | split -l 100 -d batch_ | ||
| for batch in batch_*; do | ||
| IDS=$(jq -s '.' "$batch") | ||
| echo "Deleting batch: $batch" | ||
| aws ecr batch-delete-image \ | ||
| --region "${AWS_REGION}" \ | ||
| --repository-name lambda-perf \ | ||
| --image-ids "$IDS" | ||
| done | ||