Skip to content

SURVEY-TAG-BASED-IMAGE-BUILD #7

SURVEY-TAG-BASED-IMAGE-BUILD

SURVEY-TAG-BASED-IMAGE-BUILD #7

Workflow file for this run

name: SURVEY-TAG-BASED-IMAGE-BUILD
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
environment:
description: "Target environment (qa or prod)"
required: true
default: "qa"
tag:
description: "Image tag to build"
required: true
jobs:
build:
name: Build and Push Docker Image to AWS ECR
runs-on: ubuntu-latest
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 \
$(echo ${{ secrets.ECR_REPOSITORY }} | cut -d'/' -f1)
- name: Build, Tag, and Push Docker Image
run: |
IMAGE_URI="${{ secrets.ECR_REPOSITORY }}:${{ env.TAG }}"
echo "Building image: $IMAGE_URI"
docker build -t $IMAGE_URI .
docker push $IMAGE_URI
docker rmi $IMAGE_URI