CD AI Engine #1
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: CD AI Engine | |
| on: | |
| workflow_run: | |
| workflows: | |
| - CI AI Engine | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: cd-ai-engine-master | |
| cancel-in-progress: false | |
| jobs: | |
| ai-engine-cd: | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| github.event.workflow_run.head_branch == 'master' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| env: | |
| KUBE_NAMESPACE: trafiq | |
| IMAGE_NAME: mohamedkhalil26/trafiq-ai-engine | |
| RELEASE_SHA: ${{ github.event.workflow_run.head_sha }} | |
| steps: | |
| - name: Checkout repository at the promoted commit | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Authenticate to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: mohamedkhalil26 | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push AI engine image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: backend/ai-engine | |
| file: backend/ai-engine/Dockerfile | |
| push: true | |
| tags: | | |
| docker.io/${{ env.IMAGE_NAME }}:${{ env.RELEASE_SHA }} | |
| docker.io/${{ env.IMAGE_NAME }}:latest | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Install kubectl | |
| uses: azure/setup-kubectl@v4 | |
| with: | |
| version: v1.29.4 | |
| - name: Write kubeconfig from GitHub secret | |
| env: | |
| KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} | |
| run: | | |
| echo "$KUBE_CONFIG_DATA" | base64 --decode > "$RUNNER_TEMP/kubeconfig" | |
| chmod 600 "$RUNNER_TEMP/kubeconfig" | |
| - name: Deploy AI engine to Kubernetes | |
| env: | |
| KUBECONFIG: ${{ runner.temp }}/kubeconfig | |
| AI_IMAGE: docker.io/${{ env.IMAGE_NAME }}:${{ env.RELEASE_SHA }} | |
| AI_WS_TOKEN: ${{ secrets.AI_WS_TOKEN }} | |
| GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} | |
| run: | | |
| kubectl create namespace "$KUBE_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - | |
| kubectl apply -f k8s/configmap.yaml | |
| kubectl create secret generic trafiq-ai-secrets \ | |
| --namespace "$KUBE_NAMESPACE" \ | |
| --from-literal=AI_WS_TOKEN="$AI_WS_TOKEN" \ | |
| --from-literal=GROQ_API_KEY="$GROQ_API_KEY" \ | |
| --dry-run=client -o yaml | kubectl apply -f - | |
| kubectl apply -f k8s/ai-engine-deployment.yaml | |
| kubectl set image deployment/trafiq-ai-engine ai-engine="$AI_IMAGE" -n "$KUBE_NAMESPACE" | |
| kubectl rollout status deployment/trafiq-ai-engine -n "$KUBE_NAMESPACE" --timeout=180s |