Skip to content

Commit

Permalink
Create prod-deployment.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhilashKD authored Oct 23, 2024
1 parent 40a62cc commit ca8435c
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/prod-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: PROD-WORKSPACE-TAG-BASE-DEPLOYMENT

on:
push:
tags:
- 'v*' # This will trigger on tags starting with 'v'

env:
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
EKS_CLUSTER_NAME: ${{ secrets.EKS_CLUSTER_NAME_PROD }}
AWS_REGION: ${{ secrets.AWS_REGION_NAME }}

jobs:
BACKEND-TAG-BASE-DEPLOYMENT-PROD:
name: Deployment
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set TAG environment variable
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Debug TAG value
run: echo "TAG value - ${{ env.TAG }}"

- 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: ${{ env.AWS_REGION }}

- name: Setup Node Env
uses: actions/setup-node@v3
with:
node-version: 21.1.0

- name: Copy .env file
env:
ENV_FILE_CONTENT: ${{ secrets.ENV_FILE_CONTENT_PROD }}
run: echo "$ENV_FILE_CONTENT" > manifest/configmap.yaml

- name: Show PWD and list content and Latest 3 commits
run: |
echo "Fetching all branches to ensure complete history"
git fetch --all
echo "Checking out the current branch"
git checkout ${{ github.ref_name }}
echo "Git Branch cloned"
git branch
echo "Current 3 merge commits are:"
git log --merges -n 3
pwd
ls -ltra
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ env.TAG }}
run: |
docker build -t ${{ secrets.ECR_REPOSITORY }}:${{ env.TAG }} .
docker push ${{ secrets.ECR_REPOSITORY }}:${{ env.TAG }}
- name: Update kube config
run: aws eks update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME_PROD }} --region ${{ secrets.AWS_REGION_NAME }}

- name: Deploy to EKS
env:
ECR_REGISTRY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ env.TAG }}
run: |
export ECR_REPOSITORY=${{ secrets.ECR_REPOSITORY }}
export IMAGE_TAG=${{ env.TAG }}
envsubst < manifest/backend.yaml > manifest/backend-updated.yaml
cat manifest/backend-updated.yaml
kubectl delete deployment backend
kubectl apply -f manifest/backend-updated.yaml
kubectl apply -f manifest/configmap.yaml
sleep 10
kubectl get pods
kubectl get services
kubectl get deployment

0 comments on commit ca8435c

Please sign in to comment.