Skip to content

Merge pull request #20 from onaio/round-cleanup #2

Merge pull request #20 from onaio/round-cleanup

Merge pull request #20 from onaio/round-cleanup #2

---
# ABOUTME: Builds and pushes truecover-backend Docker image to AWS ECR.
# ABOUTME: Triggers on push to main/master branches and version tags.
name: Build and Push Backend to ECR
"on":
push:
branches:
- main
- master
tags:
- 'v*'
paths:
- 'truecover-backend/**'
- '.github/workflows/build-and-push-backend.yml'
env:
AWS_REGION: ${{ vars.AWS_REGION || 'eu-central-1' }}
ECR_REPOSITORY: onaio/truecover-backend
permissions:
id-token: write
contents: read
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}
tags: |
type=sha,prefix=,format=short
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{
startsWith(github.ref, 'refs/tags/v') }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./truecover-backend
file: ./truecover-backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true
- name: Output image details
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
TAGS: ${{ steps.meta.outputs.tags }}
run: |
echo "## Backend image pushed to ECR" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** $REGISTRY" >> $GITHUB_STEP_SUMMARY
echo "**Repository:** $ECR_REPOSITORY" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "$TAGS" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY