feat: add Kubernetes secrets template #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: Deploy | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| KUBERNETES_VERSION: 'latest' | |
| PYTHON_VERSION: '3.10' | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov | |
| - name: Run tests | |
| run: | | |
| pytest --cov=app --cov-report=xml | |
| env: | |
| GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} | |
| GROQ_MODEL: ${{ secrets.GROQ_MODEL }} | |
| - name: Upload coverage report | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| fail_ci_if_error: true | |
| build-and-push: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to the Container registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v4 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=semver,pattern={{version}} | |
| type=sha,format=long | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| - name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| build-args: | | |
| GROQ_API_KEY=${{ secrets.GROQ_API_KEY }} | |
| GROQ_MODEL=${{ secrets.GROQ_MODEL }} | |
| deploy: | |
| needs: build-and-push | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| environment: production | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up kubectl | |
| uses: azure/setup-kubectl@v3 | |
| with: | |
| version: ${{ env.KUBERNETES_VERSION }} | |
| - name: Configure kubectl | |
| run: | | |
| echo "${{ secrets.KUBE_CONFIG }}" > kubeconfig.yaml | |
| chmod 600 kubeconfig.yaml | |
| export KUBECONFIG=kubeconfig.yaml | |
| - name: Deploy to Kubernetes | |
| run: | | |
| # Update image tag in deployment | |
| kubectl set image deployment/rag-api rag-api=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
| # Apply other configurations | |
| kubectl apply -f k8s/monitoring/ | |
| kubectl apply -f k8s/keda-scaler.yaml | |
| kubectl apply -f k8s/network-policy.yaml | |
| - name: Verify deployment | |
| run: | | |
| kubectl rollout status deployment/rag-api --timeout=300s | |
| kubectl get pods -l app=rag-api | |
| kubectl get services -l app=rag-api | |
| kubectl get ingress -l app=rag-api | |
| - name: Check monitoring stack | |
| run: | | |
| kubectl get pods -n monitoring | |
| kubectl get services -n monitoring | |
| kubectl get configmaps -n monitoring | |
| - name: Check logs | |
| if: failure() | |
| run: | | |
| kubectl logs -l app=rag-api --tail=100 | |
| kubectl describe pods -l app=rag-api |