Notification-TAG-BASED-DEPLOYMENT #4
This file contains hidden or 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: Notification-TAG-BASED-DEPLOYMENT | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: "Target environment (qa or prod)" | |
| required: true | |
| default: "qa" | |
| tag: | |
| description: "Image tag to deploy" | |
| required: true | |
| jobs: | |
| deploy: | |
| name: Deploy notification Service | |
| runs-on: ubuntu-latest | |
| environment: ${{ github.event.inputs.environment }} | |
| steps: | |
| # Step 1: Checkout code | |
| - name: Check out repository | |
| uses: actions/checkout@v2 | |
| # Step 2: Set TAG environment variable | |
| - name: Set TAG environment variable | |
| run: | | |
| TAG="${{ github.event.inputs.tag }}" | |
| echo "TAG=$TAG" >> $GITHUB_ENV | |
| # Step 3: Debug TAG value | |
| - name: Debug TAG value | |
| run: echo "TAG value:${{ env.TAG }}" | |
| # Step 4: Configure AWS credentials | |
| - 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 }} | |
| # Step 5: Decode ConfigMap YAML from secret | |
| - name: Write ConfigMap manifest | |
| run: | | |
| mkdir -p manifest | |
| echo "${{ secrets.ENV_FILE_CONTENT }}" | base64 -d > manifest/configmap.yaml | |
| echo "Generated ConfigMap:" | |
| cat manifest/configmap.yaml | |
| # Step 6: Update Deployment Manifest | |
| - name: Update Deployment Manifest | |
| env: | |
| IMAGE_TAG: ${{ env.TAG }} | |
| ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | |
| run: | | |
| mkdir -p manifest | |
| envsubst < manifest/notification-service.yaml > manifest/notification-service-updated.yaml | |
| echo "Updated deployment manifest:" | |
| cat manifest/notification-service-updated.yaml | |
| # Step 7: Deploy to AWS EKS | |
| - name: Deploy to AWS EKS | |
| env: | |
| EKS_CLUSTER_NAME: ${{ secrets.EKS_CLUSTER_NAME }} | |
| AWS_REGION: ${{ secrets.AWS_REGION }} | |
| NAMESPACE: ${{ github.event.inputs.environment == 'prod' && 'default' || 'microservices-qa' }} | |
| run: | | |
| aws eks update-kubeconfig --name $EKS_CLUSTER_NAME --region $AWS_REGION | |
| # Apply ConfigMap first so Deployment has it | |
| kubectl apply -f manifest/configmap.yaml -n $NAMESPACE | |
| kubectl apply -f manifest/notification-service-updated.yaml -n $NAMESPACE | |
| # Restart pods so they pick up config | |
| kubectl rollout restart deployment notification -n $NAMESPACE | |
| sleep 10 | |
| echo "Pods status:" | |
| kubectl get pods -n $NAMESPACE | grep notification |