January Infrastructure updates trigger #97
This file contains 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: Update Backend | |
on: | |
push: | |
paths: | |
- api/** | |
- .github/workflow/update-backend.yml | |
branches: | |
- live | |
- stage | |
- dev | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
jobs: | |
push_to_env_matching_branch: | |
environment: ${{ github.ref_name }} | |
runs-on: ubuntu-latest | |
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_NUMBER }}:role/Role_Diagram_GitHub_OICD | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Login to ECR | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ secrets.AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com | |
- name: Build docker image and push to ECR | |
id: docker_build | |
uses: docker/build-push-action@v3 | |
with: | |
context: api/ | |
push: true | |
tags: ${{ secrets.AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPO_NAME }}:latest | |
- name: Update Lambda to use the latest image push | |
run: | | |
aws lambda update-function-code --function-name ${{ secrets.LAMBDA_NAME }} --image-uri ${{ secrets.AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPO_NAME }}@${{ steps.docker_build.outputs.digest }} | |
aws lambda wait function-updated --function-name ${{ secrets.LAMBDA_NAME }} |