Repository navigation
98 lines (84 loc) · 3.46 KB
/
Copy pathdeploy-api.yml
File metadata and controls
98 lines (84 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Deploy API → Cloud Run
on:
push:
branches: [main]
paths:
- "api/**"
- ".github/workflows/deploy-api.yml"
workflow_dispatch:
env:
GCP_PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
GCP_LOCATION: ${{ vars.GCP_LOCATION }}
GAR_LOCATION: ${{ vars.GCP_LOCATION }}
GAR_REPOSITORY: karma-images
SERVICE_NAME: karma-api
IMAGE_NAME: karma-api
permissions:
contents: read
id-token: write
jobs:
test:
name: Test API
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
working-directory: api
run: pip install -e ".[dev]"
- name: Run tests
working-directory: api
env:
GCP_PROJECT_ID: test-project
API_SECRET_KEY: ci-placeholder-not-real
run: pytest tests/ -v --tb=short
- name: Lint
working-directory: api
run: |
ruff check app/
mypy app/ --ignore-missing-imports
deploy:
name: Deploy to Cloud Run
needs: test
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev --quiet
- name: Build and push image
working-directory: api
run: |
IMAGE_TAG=${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
docker build -t "$IMAGE_TAG" .
docker push "$IMAGE_TAG"
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Deploy to Cloud Run
# Use gcloud directly so ALLOWED_ORIGINS (comma-separated URLs) is passed
# with the ^|^ custom delimiter — the deploy-cloudrun action splits env_vars
# on commas, which corrupts any value that itself contains a comma.
env:
ALLOWED_ORIGINS: ${{ vars.ALLOWED_ORIGINS }}
AGENT_ENGINE_RESOURCE_NAME: ${{ vars.AGENT_ENGINE_RESOURCE_NAME }}
SVC_PAYMENTS_V3_URL: ${{ vars.SVC_PAYMENTS_V3_URL }}
run: |
gcloud run deploy ${{ env.SERVICE_NAME }} \
--project=${{ env.GCP_PROJECT_ID }} \
--region=${{ env.GCP_LOCATION }} \
--image="$IMAGE_TAG" \
--allow-unauthenticated \
--service-account=karma-runner@skillbridge-76a4c.iam.gserviceaccount.com \
--min-instances=1 \
--max-instances=10 \
--memory=512Mi \
--cpu=1 \
--set-secrets=DT_API_TOKEN=dt-api-token:latest,DT_QUERY_TOKEN=dt-api-token:latest,API_SECRET_KEY=api-secret-key:latest,DT_OTEL_TOKEN=dt-otel-token:latest,GITHUB_TOKEN=gh-token:latest,GITHUB_WRITE_TOKEN=gh-write-token:latest,KARMA_CONTROL_TOKEN=karma-control-token:latest \
"--set-env-vars=^|^GCP_PROJECT_ID=${{ env.GCP_PROJECT_ID }}|GCP_LOCATION=${{ env.GCP_LOCATION }}|AGENT_ENGINE_RESOURCE_NAME=${AGENT_ENGINE_RESOURCE_NAME}|ALLOWED_ORIGINS=${ALLOWED_ORIGINS}|FIRESTORE_DATABASE=(default)|DT_ENV=${{ vars.DT_ENV }}|GITHUB_REPO=${{ vars.GH_REPO }}|SVC_PAYMENTS_V3_URL=${SVC_PAYMENTS_V3_URL}"