Skip to content

feat: testing

feat: testing #45

name: Docker Push
on:
push:
paths:
- 'todo-app/lambda_function/**'
branches:
- main
jobs:
push-app-ecr:
name: Deploy to ECR
runs-on: ubuntu-latest
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
sha_short: $(git rev-parse --short HEAD)
TARGET_ENVIRONMENT: dev
REGISTRIES: ${{ secrets.REGISTRIES }}
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
permissions:
id-token: write
contents: read
pull-requests: write
repository-projects: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set ENV variables to get the repo name
run: echo "REPO_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
- name: Use the custom ENV variable
run: echo $REPO_NAME
env:
REPO_NAME: $REPO_NAME
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: GithubActionsSession
- name: Install AWS CLI
run: |
sudo apt-get update
sudo apt-get install -y awscli
- name: Check if ECR repository exists
id: check_ecr_repo
run: |
aws ecr describe-repositories --repository-names ${{ env.REPO_NAME }} --region ${{ env.AWS_REGION }} > /dev/null || echo "::set-output name=exists::false"
- name: Create ECR repository if it doesn't exist
if: steps.check_ecr_repo.outputs.exists == 'false'
run: |
aws ecr create-repository --repository-name ${{ env.REPO_NAME }} --region ${{ env.AWS_REGION }}
- name: Show ECR repository details
run: |
aws ecr describe-repositories --repository-names ${{ env.REPO_NAME }} --region ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registries: "${{ env.REGISTRIES }}"
- name: Set short sha
id: sha_short
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v5
id: build-push-to-ecr
with:
context: todo-app/lambda_function
file: todo-app/lambda_function/Dockerfile
push: true
tags: ${{ env.ECR_REGISTRY }}/${{ env.REPO_NAME }}:${{ steps.sha_short.outputs.sha_short }}
platforms: linux/amd64
provenance: false
continue-on-error: false