From ca8435c4a792a87e7cf8870862cf82ac8e51c80f Mon Sep 17 00:00:00 2001 From: Abhilash Dubey <124042593+AbhilashKD@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:25:37 +0530 Subject: [PATCH] Create prod-deployment.yaml --- .github/workflows/prod-deployment.yaml | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/workflows/prod-deployment.yaml diff --git a/.github/workflows/prod-deployment.yaml b/.github/workflows/prod-deployment.yaml new file mode 100644 index 0000000..f9d5020 --- /dev/null +++ b/.github/workflows/prod-deployment.yaml @@ -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