|
| 1 | +name: Build & Push Container |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'main' |
| 7 | + tags: |
| 8 | + - '*' |
| 9 | + merge_group: |
| 10 | + pull_request_target: |
| 11 | + types: [labeled, synchronize, reopened, ready_for_review, opened] |
| 12 | + |
| 13 | +env: |
| 14 | + PUSH_FROM_PR: >- |
| 15 | + ${{ github.event_name == 'pull_request_target' && |
| 16 | + ( |
| 17 | + contains(github.event.pull_request.labels.*.name, 'push-container') || |
| 18 | + contains(github.event.pull_request.labels.*.name, 'deploy-pr-temp-env') |
| 19 | + ) |
| 20 | + }} |
| 21 | +
|
| 22 | +jobs: |
| 23 | + terraform: |
| 24 | + name: "ECR" |
| 25 | + runs-on: ubuntu-latest |
| 26 | + if: github.repository == 'coderamp-labs/gitingest' |
| 27 | + |
| 28 | + permissions: |
| 29 | + id-token: write |
| 30 | + contents: read |
| 31 | + pull-requests: write |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: configure aws credentials |
| 38 | + uses: aws-actions/configure-aws-credentials@v4 |
| 39 | + with: |
| 40 | + role-to-assume: ${{ secrets.CODERAMP_AWS_ECR_REGISTRY_PUSH_ROLE_ARN }} |
| 41 | + role-session-name: GitHub_to_AWS_via_FederatedOIDC |
| 42 | + aws-region: eu-west-1 |
| 43 | + |
| 44 | + - name: Set current timestamp |
| 45 | + id: vars |
| 46 | + run: | |
| 47 | + echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT |
| 48 | + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + - name: Login to Amazon ECR |
| 51 | + id: login-ecr |
| 52 | + uses: aws-actions/amazon-ecr-login@v2 |
| 53 | + |
| 54 | + - name: Docker Meta |
| 55 | + id: meta |
| 56 | + uses: docker/metadata-action@v5 |
| 57 | + with: |
| 58 | + images: | |
| 59 | + ${{ secrets.ECR_REGISTRY_URL }} |
| 60 | + flavor: | |
| 61 | + latest=false |
| 62 | + tags: | |
| 63 | + type=ref,event=branch,branch=main,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }} |
| 64 | + type=ref,event=pr,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }} |
| 65 | + type=pep440,pattern={{raw}} |
| 66 | +
|
| 67 | + - name: Set up QEMU |
| 68 | + uses: docker/setup-qemu-action@v3 |
| 69 | + |
| 70 | + - name: Set up Docker Buildx |
| 71 | + uses: docker/setup-buildx-action@v3 |
| 72 | + |
| 73 | + - name: Build and push |
| 74 | + uses: docker/build-push-action@v6 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + platforms: linux/amd64, linux/arm64 |
| 78 | + push: ${{ github.event_name != 'pull_request_target' || env.PUSH_FROM_PR == 'true' }} |
| 79 | + tags: ${{ steps.meta.outputs.tags }} |
| 80 | + labels: ${{ steps.meta.outputs.labels }} |
| 81 | + cache-from: type=gha |
| 82 | + cache-to: type=gha,mode=max |
0 commit comments