-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (93 loc) · 3.34 KB
/
Copy pathdeploy.yml
File metadata and controls
114 lines (93 loc) · 3.34 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Deploy to GCP Cloud Run
on:
push:
branches:
- main
permissions:
id-token: write
contents: read
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Setup Python
run: uv python install 3.13
- name: Sync dependencies
run: uv sync --extra dev
- name: Run tests
run: uv run pytest tests/test_models.py -v
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: test
environment: production
steps:
- name: Checkout code
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: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.6.0
- name: Terraform init
working-directory: ./terraform
run: terraform init
- name: Terraform plan
working-directory: ./terraform
env:
TF_VAR_supabase_url: ${{ secrets.SUPABASE_URL }}
TF_VAR_supabase_key: ${{ secrets.SUPABASE_KEY }}
TF_VAR_supabase_db_url: ${{ secrets.SUPABASE_DB_URL }}
TF_VAR_logfire_token: ${{ secrets.LOGFIRE_TOKEN }}
TF_VAR_logfire_environment: prod
run: terraform plan
- name: Terraform apply
working-directory: ./terraform
env:
TF_VAR_supabase_url: ${{ secrets.SUPABASE_URL }}
TF_VAR_supabase_key: ${{ secrets.SUPABASE_KEY }}
TF_VAR_supabase_db_url: ${{ secrets.SUPABASE_DB_URL }}
TF_VAR_logfire_token: ${{ secrets.LOGFIRE_TOKEN }}
TF_VAR_logfire_environment: prod
run: terraform apply -auto-approve
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{ vars.GCP_REGION }}-docker.pkg.dev
- name: Build and push Docker image
env:
IMAGE_URL: ${{ vars.GCP_REGION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${{ vars.PROJECT_NAME }}/${{ vars.PROJECT_NAME }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $IMAGE_URL:$IMAGE_TAG .
docker tag $IMAGE_URL:$IMAGE_TAG $IMAGE_URL:latest
docker push $IMAGE_URL:$IMAGE_TAG
docker push $IMAGE_URL:latest
- name: Deploy API to Cloud Run
run: |
gcloud run services update-traffic ${{ vars.API_SERVICE_NAME }} \
--region=${{ vars.GCP_REGION }} \
--to-latest
- name: Deploy Worker to Cloud Run
run: |
gcloud run services update-traffic ${{ vars.WORKER_SERVICE_NAME }} \
--region=${{ vars.GCP_REGION }} \
--to-latest
- name: Get API URL
run: |
echo "=== API Endpoint ==="
API_URL=$(gcloud run services describe ${{ vars.API_SERVICE_NAME }} \
--region=${{ vars.GCP_REGION }} \
--format='value(status.url)')
echo "API is available at: $API_URL"
echo "Health check: $API_URL/health"
echo "Documentation: $API_URL/docs"