Skip to content

Merge pull request #46 from Shubham4026/aws_sms #2

Merge pull request #46 from Shubham4026/aws_sms

Merge pull request #46 from Shubham4026/aws_sms #2

Workflow file for this run

name: Tag-based Build Image
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
environment:
description: "Target environment (qa or prod)"
required: true
default: "qa"
tag:
description: "Image tag to deploy"
required: true
jobs:
build:
name: Build and Push Docker Image to AWS ECR
runs-on: ubuntu-latest
# Use qa for tag pushes, or the chosen input for workflow_dispatch
environment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'qa' }}
env:
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'qa' }}
TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag || github.ref_name }}
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Extract ECR Registry from Repository
run: |
FULL_REPO="${{ secrets.ECR_REPOSITORY }}"
REGISTRY="$(echo $FULL_REPO | cut -d'/' -f1)"
echo "ECR_REGISTRY=$REGISTRY" >> $GITHUB_ENV
echo "ECR_REPOSITORY=$FULL_REPO" >> $GITHUB_ENV
- name: Log in to Amazon ECR
run: |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} \
| docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }}
- name: Build, Tag, and Push Docker Image
run: |
IMAGE_URI="${{ env.ECR_REPOSITORY }}:${{ env.TAG }}"
echo "Building image: $IMAGE_URI"
docker build -t $IMAGE_URI .
docker push $IMAGE_URI
docker rmi $IMAGE_URI