Skip to content

Build and Push Lambda Report Generator #2

Build and Push Lambda Report Generator

Build and Push Lambda Report Generator #2

name: Build and Push Lambda Report Generator
on:
workflow_dispatch:
workflow_call:
inputs:
TAG:
required: false
type: string
default: latest
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
AWS_REGION: ca-central-1
COMPONENT_NAME: report-generator
IMAGE_NAME: ${{ github.repository_owner }}/report-generator
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
uses: docker/login-action@v2
with:
registry: ${{ vars.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=raw,value=${{ github.sha }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./lambda/${{ inputs.COMPONENT_NAME }}
file: ./lambda/${{ inputs.COMPONENT_NAME }}/src/main/docker/Dockerfile.lambda
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Tag and push latest image
run: |
IMAGE=${{ vars.REGISTRY }}/${{ github.repository_owner }}/nr-bcws-wfprev-${{ inputs.COMPONENT_NAME }}
docker pull $IMAGE:${{ github.sha }}
docker tag $IMAGE:${{ github.sha }} $IMAGE:${{ inputs.TAG }}
docker push $IMAGE:${{ inputs.TAG }}
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.LZA_ECR_AWS_ACCOUNT_ID }}:role/Terraform-deploy
aws-region: ${{ env.AWS_REGION }}
role-session-name: GitHubActions-ReportGenerator
- name: Create ECR Repository for Report Generator (if not exists)
run: |
aws ecr describe-repositories --repository-names nr-bcws-wfprev-${{ inputs.COMPONENT_NAME }} --region ${{ env.AWS_REGION }} || \
aws ecr create-repository --repository-name nr-bcws-wfprev-${{ inputs.COMPONENT_NAME }} --region ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
run: |
aws ecr get-login-password --region ${{ env.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.LZA_ECR_AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
- name: Pull, Tag, and Push GDB Extractor Docker image to ECR
id: pushGdbExtractorImage
run: |
docker pull ${{vars.REPOSITORY_HOST}}/${{ github.repository_owner }}/nr-bcws-wfprev-${{ inputs.COMPONENT_NAME }}:${{ inputs.TAG }}
docker tag ${{vars.REPOSITORY_HOST}}/${{ github.repository_owner }}/nr-bcws-wfprev-${{ inputs.COMPONENT_NAME }}:${{ inputs.TAG }} ${{ secrets.LZA_ECR_AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/nr-bcws-wfprev-${{ inputs.COMPONENT_NAME }}:${{ inputs.TAG }}
docker push ${{ secrets.LZA_ECR_AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/nr-bcws-wfprev-${{ inputs.COMPONENT_NAME }}:${{ inputs.TAG }}