test(cache): add comprehensive tests for cache invalidation (#711) #391
Workflow file for this run
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: Docker CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| release: | |
| types: [ created ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| cache: pip | |
| - 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 tests/ -v --cov=astroml --cov-report=xml | |
| - name: Upload coverage | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| build-docker-images: | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| strategy: | |
| matrix: | |
| stage: [base, development, feature-store, ingestion, training-cpu, production] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=sha,prefix= | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| target: ${{ matrix.stage }} | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.stage }}-${{ github.sha }} | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.stage }}-latest | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| security-scan: | |
| runs-on: ubuntu-latest | |
| needs: build-docker-images | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:production-latest | |
| format: 'sarif' | |
| output: 'trivy-results.sarif' | |
| - name: Upload Trivy results to GitHub Security tab | |
| uses: github/codeql-action/upload-sarif@v2 | |
| with: | |
| sarif_file: 'trivy-results.sarif' | |
| deploy-kubernetes: | |
| runs-on: ubuntu-latest | |
| needs: [build-docker-images, security-scan] | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up kubectl | |
| uses: azure/setup-kubectl@v3 | |
| with: | |
| version: 'v1.28.0' | |
| - name: Configure kubectl | |
| run: | | |
| echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > kubeconfig | |
| export KUBECONFIG=kubeconfig | |
| - name: Install kustomize | |
| run: | | |
| curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash | |
| sudo mv kustomize /usr/local/bin/ | |
| - name: Deploy to Kubernetes | |
| run: | | |
| kustomize build k8s/ | kubectl apply -f - | |
| - name: Verify deployment | |
| run: | | |
| kubectl rollout status deployment/feature-store -n astroml | |
| kubectl rollout status deployment/astroml-ingestion -n astroml | |
| kubectl rollout status deployment/postgres -n astroml | |
| kubectl rollout status deployment/redis -n astroml | |
| - name: Run smoke tests (issue #560) | |
| run: | | |
| # Wait for service to be ready | |
| sleep 30 | |
| # Get service endpoint | |
| SERVICE_IP=$(kubectl get service astroml-api -n astroml -o jsonpath='{.status.loadBalancer.ingress[0].ip}') | |
| # Run smoke tests with 5-minute timeout | |
| timeout 300 python tests/e2e/test_deployment_smoke.py http://${SERVICE_IP}:8000 | |
| continue-on-error: false | |
| - name: Rollback on smoke test failure | |
| if: failure() | |
| run: | | |
| kubectl rollout undo deployment/feature-store -n astroml | |
| kubectl rollout undo deployment/astroml-ingestion -n astroml | |
| echo "Deployment rolled back due to smoke test failure" | |
| deploy-staging: | |
| runs-on: ubuntu-latest | |
| needs: [build-docker-images, security-scan] | |
| if: github.ref == 'refs/heads/develop' && github.event_name == 'push' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up kubectl | |
| uses: azure/setup-kubectl@v3 | |
| with: | |
| version: 'v1.28.0' | |
| - name: Configure kubectl | |
| run: | | |
| echo "${{ secrets.KUBE_CONFIG_STAGING }}" | base64 -d > kubeconfig | |
| export KUBECONFIG=kubeconfig | |
| - name: Install kustomize | |
| run: | | |
| curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash | |
| sudo mv kustomize /usr/local/bin/ | |
| - name: Deploy to Staging | |
| run: | | |
| kustomize build k8s/overlays/staging | kubectl apply -f - | |
| - name: Verify deployment | |
| run: | | |
| kubectl rollout status deployment/feature-store -n astroml-staging | |
| kubectl rollout status deployment/astroml-ingestion -n astroml-staging | |
| notify: | |
| runs-on: ubuntu-latest | |
| needs: [deploy-kubernetes] | |
| if: always() | |
| steps: | |
| - name: Send notification | |
| uses: 8398a7/action-slack@v3 | |
| with: | |
| status: ${{ job.status }} | |
| text: | | |
| Deployment Status: ${{ job.status }} | |
| Branch: ${{ github.ref }} | |
| Commit: ${{ github.sha }} | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |