Skip to content

Commit

Permalink
Update aha-uat-ci-cd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
rf-opssupport authored Sep 16, 2024
1 parent 24f5736 commit b3867e1
Showing 1 changed file with 44 additions and 81 deletions.
125 changes: 44 additions & 81 deletions .github/workflows/aha-uat-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,103 +1,47 @@
# This workflow will trigger pull requests and apply a label based on the
# paths that are modified in the pull request.
#
# To use this workflow, you will need to set up a .github/labeler.yml
# file with configuration. For more information, see:
# https://github.com/actions/labeler

name: AHA-UAT-CI-CD

# Controls when the workflow will run
on:
# Triggers the workflow on push events but only for the develop branch
workflow_dispatch:
inputs:
Tag_name:
description: Tag name of your release(please include "v")
required: true
# inputs:
# Tag_name:
# description: Tag name of your release(please include "v")
# required: true

jobs:

# CodeScan-ESLint:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Code
# uses: actions/checkout@v3
# with:
# fetch-depth: 0

# - name: Lint Code Base
# uses: github/super-linter@v4
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# LINTER_RULES_PATH: /
# TYPESCRIPT_ES_CONFIG_FILE: .eslintrc.json
# VALIDATE_TYPESCRIPT_ES: true


Github-ECR-Tag-Check:
Publish-Release:
runs-on: ubuntu-latest
steps:
- name: check tag
uses: mukunku/tag-exists-action@v1.2.0
id: checkTag
with:
tag: ${{ github.event.inputs.Tag_name }}

- name: Get release
if: ${{ steps.checkTag.outputs.exists == 'true' }}
id: result_release
uses: cardinalby/git-get-release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}
- name: New Release Publish
id: new_publish
uses: release-drafter/release-drafter@v5
with:
tag: ${{ github.event.inputs.Tag_name }}
repo: REAN-Foundation/rean-admin-portal

- name: Configure AWS credentials
if: ${{ steps.checkTag.outputs.exists == 'true' }}
uses: aws-actions/configure-aws-credentials@v1
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: Get ECR Image Tag
if: ${{ steps.checkTag.outputs.exists == 'true' }}
id: imageidvar
run: |
image_tag+=${{ steps.result_release.outputs.tag_name }} && image_tag+=_ && image_tag+=${{ steps.result_release.outputs.id }}
echo "imagetag_value=$(aws ecr-public describe-image-tags --repository-name rean-admin-portal --region us-east-1 --query "imageTagDetails[?imageTag=='$image_tag'].imageTag" --output text)" >> $GITHUB_OUTPUT
- name: ECR Image and Github Tag Check
run: |
if [[ ${{ steps.checkTag.outputs.exists }} == 'false' ]]; then exit 1; fi
if [[ -z "${{ steps.imageidvar.outputs.imagetag_value }}" ]]; then exit 1; fi
publish : true
env:
GITHUB_TOKEN: ${{ secrets.PAT_GITHUB }}

outputs:
release_name: ${{ steps.result_release.outputs.tag_name }}
release_id: ${{ steps.result_release.outputs.id }}
release_id: ${{ steps.new_publish.outputs.id }}
release_name: ${{ steps.new_publish.outputs.tag_name }}

Deploy-ECS:
needs: Github-ECR-Tag-Check
environment: aha-uat
needs: Publish-Release
environment: prod
runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: Copy env file
run: aws s3 cp s3://${{ secrets.ENV_FILE_BUCKET_PATH }}/.env ./.env

- name: Declare some variables
id: vars
shell: bash
Expand All @@ -106,34 +50,52 @@ jobs:
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "repo_name=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')" >> $GITHUB_OUTPUT
- name: Another step
run: |
echo "Branch: ${{ steps.vars.outputs.branch }}"
echo "Sha: ${{ steps.vars.outputs.sha_short }}"
echo "Repo: ${{ steps.vars.outputs.repo_name }}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Copy env file
run: aws s3 cp s3://${{ secrets.ENV_FILE_BUCKET_PATH }}/.env ./.env

- name: Copy constant file
run: aws s3 cp s3://${{ secrets.CONSTANT_FILE_BUCKET_PATH }}/constants.ts ./src/lib

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
build-args: ORIGIN=${{ env.ORIGIN }}
build-args: |
ORIGIN=${{ env.ORIGIN }}
ENVIRONMENT=aha-uat
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/rean-admin-portal:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
tags: ${{ steps.login-ecr.outputs.registry }}/rean-admin-portal-aha-uat:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} \
Expand All @@ -143,9 +105,9 @@ jobs:
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: default
image: ${{ steps.login-ecr.outputs.registry }}/rean-admin-portal:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}
task-definition: task-definition.json
container-name: default
image: ${{ steps.login-ecr.outputs.registry }}/rean-admin-portal-aha-uat:${{ steps.vars.outputs.branch }}_${{ steps.vars.outputs.sha_short }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
Expand All @@ -157,7 +119,8 @@ jobs:
id: taskdefintionvar
shell: bash
run: |
echo "task_definition_arn=$(aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} | jq '.[] | .taskDefinitionArn')" >> $GITHUB_OUTPUT
# echo "::set-output name=task_definition_arn::$(aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} | jq '.[] | .taskDefinitionArn')"
echo "task_definition_arn=$(aws ecs describe-task-definition --task-definition ${{ secrets.TASK_DEFINTION_NAME }} | jq '.[] | .taskDefinitionArn')" >> $GITHUB_OUTPUT
- name: Task Defintion ARN
run: |
Expand Down

0 comments on commit b3867e1

Please sign in to comment.