# ============================================================================== # Google Cloud Build Pipeline for CropAI Backend # Automatically builds, tests, and deploys to Google Cloud Run # ============================================================================== steps: # 1. Run Unit & Integration Tests - name: 'python:3.11-slim' entrypoint: 'bash' args: - '-c' - | pip install --no-cache-dir -r backend/requirements.txt python -m unittest backend/tests/test_api.py -v # 2. Build Container Image with BuildKit - name: 'gcr.io/cloud-builders/docker' args: - 'build' - '-t' - 'gcr.io/$PROJECT_ID/cropai-backend:$COMMIT_SHA' - '-t' - 'gcr.io/$PROJECT_ID/cropai-backend:latest' - '-f' - 'backend/Dockerfile' - 'backend' # 3. Push Container Image to Google Container Registry / Artifact Registry - name: 'gcr.io/cloud-builders/docker' args: - 'push' - 'gcr.io/$PROJECT_ID/cropai-backend:$COMMIT_SHA' # 4. Deploy to Google Cloud Run (Fully Managed Serverless) - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' entrypoint: gcloud args: - 'run' - 'deploy' - 'cropai-backend' - '--image' - 'gcr.io/$PROJECT_ID/cropai-backend:$COMMIT_SHA' - '--region' - 'us-central1' - '--platform' - 'managed' - '--allow-unauthenticated' - '--memory' - '2Gi' - '--cpu' - '2' - '--min-instances' - '1' - '--max-instances' - '20' - '--concurrency' - '80' - '--timeout' - '60s' - '--port' - '8080' images: - 'gcr.io/$PROJECT_ID/cropai-backend:$COMMIT_SHA' - 'gcr.io/$PROJECT_ID/cropai-backend:latest' timeout: '900s'