PROD-WORKSPACE-TAG-BASE-DEPLOYMENT #16
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Copy .env file in the code | |
env: | |
PROD_ENV: ${{ secrets.PROD_ENV }} | |
run: rm -f .env && echo '${{ secrets.PROD_ENV }}' > .env | |
#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/workspace.yaml > manifest/workspace-updated.yaml | |
cat manifest/workspace-updated.yaml | |
rm -rf manifest/workspace-service.yaml | |
kubectl delete deployment shiksha-workspace | |
kubectl delete service shiksha-workspace | |
kubectl delete cm workspace-service-config | |
kubectl apply -f manifest/workspace-updated.yaml | |
kubectl apply -f manifest/configmap.yaml | |
sleep 10 | |
kubectl get pods | |
kubectl get services | |
kubectl get deployment |