-
-
Notifications
You must be signed in to change notification settings - Fork 33
114 lines (92 loc) · 3.21 KB
/
Copy pathdeploy-worker.yml
File metadata and controls
114 lines (92 loc) · 3.21 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 Worker
# Template cost controls (Actions minutes) — copy into product repos:
# - path filters so unrelated monorepo edits do not rebuild
# - concurrency cancel-in-progress: only the latest SHA deploys on main
# - docker/build-push-action GHA layer cache (scope per image)
# - PR CI lives in review.yml; this workflow is main/deploy only
on:
push:
branches: [main]
paths:
- "apps/worker/**"
- ".github/workflows/deploy-worker.yml"
workflow_dispatch:
concurrency:
group: deploy-worker
cancel-in-progress: true
permissions:
contents: read
id-token: write
actions: write # docker GHA cache (cache-to: type=gha)
env:
PROJECT_ID: ${{ vars.GCP_PROJECT_ID }}
REGION: ${{ vars.GCP_REGION }}
SERVICE_NAME: fullstack-starter-worker
WORKLOAD_IDENTITY_PROVIDER: ${{ vars.WORKLOAD_IDENTITY_PROVIDER }}
SERVICE_ACCOUNT: ${{ vars.GCP_SERVICE_ACCOUNT }}
IMAGE: ${{ vars.GCP_REGION }}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/fullstack-starter-images/worker
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/worker
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
version: "latest"
enable-cache: true
cache-dependency-glob: "apps/worker/uv.lock"
- 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
steps:
- uses: actions/checkout@v6
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.SERVICE_ACCOUNT }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v3
- name: Configure Docker
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: apps/worker
push: true
tags: ${{ env.IMAGE }}:${{ github.sha }}
cache-from: type=gha,scope=fullstack-starter-worker
cache-to: type=gha,mode=max,scope=fullstack-starter-worker
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v3
with:
service: ${{ env.SERVICE_NAME }}
region: ${{ env.REGION }}
image: ${{ env.IMAGE }}:${{ github.sha }}
flags: |
--min-instances=0
--max-instances=5
--cpu=1
--memory=512Mi
--ingress=internal
--no-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 (internal only)" >> $GITHUB_STEP_SUMMARY