-
-
Notifications
You must be signed in to change notification settings - Fork 32
93 lines (75 loc) · 2.38 KB
/
deploy-api.yml
File metadata and controls
93 lines (75 loc) · 2.38 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
name: Deploy API
on:
push:
branches: [main]
paths:
- "apps/api/**"
- ".github/workflows/deploy-api.yml"
workflow_dispatch:
env:
PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
REGION: ${{ vars.GCP_REGION }}
SERVICE_NAME: fullstack-starter-api
WORKLOAD_IDENTITY_PROVIDER: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/api
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync --frozen
- name: Run linter
run: uv run ruff check .
- name: Run type checker
run: uv run mypy src
- name: Run tests
run: uv run pytest
build-and-deploy:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.SERVICE_ACCOUNT }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev
- name: Build and push image
run: |
IMAGE="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/fullstack-starter-images/api:${{ github.sha }}"
docker build -t $IMAGE apps/api
docker push $IMAGE
echo "IMAGE=$IMAGE" >> $GITHUB_ENV
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.SERVICE_NAME }}
region: ${{ env.REGION }}
image: ${{ env.IMAGE }}
flags: |
--min-instances=0
--max-instances=10
--cpu=1
--memory=512Mi
--allow-unauthenticated
- name: Show deployment URL
run: |
URL=$(gcloud run services describe ${{ env.SERVICE_NAME }} --region=${{ env.REGION }} --format='value(status.url)')
echo "### Deployed to: $URL" >> $GITHUB_STEP_SUMMARY