Skip to content

Commit 19c409f

Browse files
committed
feat: update Cloud Run services and add outputs for new services
1 parent 765b97a commit 19c409f

File tree

7 files changed

+340
-59
lines changed

7 files changed

+340
-59
lines changed

.github/workflows/cd-dev.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,17 @@ jobs:
116116
- name: Terraform Plan
117117
working-directory: infra/terraform/environments/dev
118118
run: |
119+
BILLING_ARGS=""
120+
if [ -n "${{ secrets.BILLING_ACCOUNT_DEV }}" ]; then
121+
BILLING_ARGS="-var=billing_account=${{ secrets.BILLING_ACCOUNT_DEV }}"
122+
fi
123+
119124
terraform plan \
120125
-var="project_id=${{ env.PROJECT_ID }}" \
121126
-var="environment=dev" \
122127
-var="firestore_location=${{ env.FIRESTORE_LOCATION }}" \
123128
-var="budget_amount=${{ env.BUDGET_AMOUNT }}" \
129+
$BILLING_ARGS \
124130
-out=tfplan
125131
126132
- name: Terraform Apply
@@ -129,8 +135,8 @@ jobs:
129135

130136
# deploy ingestion API (Cloud Run Service)
131137
deploy-ingestion:
132-
needs: changes
133-
if: needs.changes.outputs.ingestion == 'true'
138+
needs: [changes, terraform]
139+
if: ${{ !failure() && !cancelled() && needs.changes.outputs.ingestion == 'true' }}
134140
runs-on: ubuntu-latest
135141
permissions:
136142
contents: read
@@ -191,8 +197,8 @@ jobs:
191197
echo "Deployed to: $URL" >> "$GITHUB_STEP_SUMMARY"
192198
193199
deploy-state-manager:
194-
needs: changes
195-
if: needs.changes.outputs.state-manager == 'true'
200+
needs: [changes, terraform]
201+
if: ${{ !failure() && !cancelled() && needs.changes.outputs.state-manager == 'true' }}
196202
runs-on: ubuntu-latest
197203
permissions:
198204
contents: read
@@ -253,8 +259,8 @@ jobs:
253259
echo "Deployed to: $URL" >> "$GITHUB_STEP_SUMMARY"
254260
255261
deploy-optimizer:
256-
needs: changes
257-
if: needs.changes.outputs.optimizer == 'true'
262+
needs: [changes, terraform]
263+
if: ${{ !failure() && !cancelled() && needs.changes.outputs.optimizer == 'true' }}
258264
runs-on: ubuntu-latest
259265
permissions:
260266
contents: read
@@ -322,8 +328,8 @@ jobs:
322328
echo "State Manager URL: \`${{ steps.state-manager.outputs.url }}\`" >> "$GITHUB_STEP_SUMMARY"
323329
324330
deploy-visualizer:
325-
needs: changes
326-
if: needs.changes.outputs.visualizer == 'true'
331+
needs: [changes, terraform]
332+
if: ${{ !failure() && !cancelled() && needs.changes.outputs.visualizer == 'true' }}
327333
runs-on: ubuntu-latest
328334
permissions:
329335
contents: read
@@ -365,6 +371,7 @@ jobs:
365371
--image "${{ env.IMAGE_BASE }}/visualizer:$SHORT_SHA" \
366372
--region ${{ env.REGION }} \
367373
--platform managed \
374+
--service-account "visualizer@${{ env.PROJECT_ID }}.iam.gserviceaccount.com" \
368375
--set-env-vars "PROJECT_ID=${{ env.PROJECT_ID }},NODE_ENV=production,PUBSUB_SUBSCRIPTION=telemetry-sub" \
369376
--min-instances 0 \
370377
--max-instances 2 \
@@ -382,8 +389,8 @@ jobs:
382389
echo "Deployed to: $URL" >> "$GITHUB_STEP_SUMMARY"
383390
384391
deploy-simulator:
385-
needs: changes
386-
if: needs.changes.outputs.simulator == 'true'
392+
needs: [changes, terraform]
393+
if: ${{ !failure() && !cancelled() && needs.changes.outputs.simulator == 'true' }}
387394
runs-on: ubuntu-latest
388395
permissions:
389396
contents: read
@@ -450,8 +457,8 @@ jobs:
450457
echo "Ingestion URL: \`${{ steps.ingestion.outputs.url }}\`" >> "$GITHUB_STEP_SUMMARY"
451458
452459
deploy-seed-firestore:
453-
needs: changes
454-
if: needs.changes.outputs.seed-firestore == 'true'
460+
needs: [changes, terraform]
461+
if: ${{ !failure() && !cancelled() && needs.changes.outputs.seed-firestore == 'true' }}
455462
runs-on: ubuntu-latest
456463
permissions:
457464
contents: read

infra/terraform/environments/dev/main.tf

Lines changed: 213 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ resource "google_service_account" "optimizer" {
141141
project = var.project_id
142142
}
143143

144+
resource "google_service_account" "visualizer" {
145+
account_id = "visualizer"
146+
display_name = "Visualizer Service Account"
147+
project = var.project_id
148+
}
149+
144150
# IAM for pubsub
145151

146152
# to pub orders/telemetry topics
@@ -185,6 +191,16 @@ resource "google_pubsub_topic_iam_member" "optimizer_publisher" {
185191
depends_on = [module.decisions_topic]
186192
}
187193

194+
# visualizer needs to subscribe to telemetry-sub
195+
resource "google_pubsub_subscription_iam_member" "visualizer_subscriber" {
196+
project = var.project_id
197+
subscription = "telemetry-sub"
198+
role = "roles/pubsub.subscriber"
199+
member = "serviceAccount:${google_service_account.visualizer.email}"
200+
201+
depends_on = [module.telemetry_topic]
202+
}
203+
188204
# pubsub SA need to be set as pub on DLQ to pub failed ones
189205
resource "google_pubsub_topic_iam_member" "pubsub_dlq_publisher" {
190206
project = var.project_id
@@ -289,7 +305,202 @@ resource "google_project_iam_member" "seed_firestore_datastore" {
289305
member = "serviceAccount:${google_service_account.seed_firestore.email}"
290306
}
291307

292-
# cloud Run Job: simulator
308+
# Cloud Run Service: ingestion API
309+
resource "google_cloud_run_v2_service" "ingestion" {
310+
name = "ingestion"
311+
location = var.region
312+
project = var.project_id
313+
labels = local.common_labels
314+
315+
template {
316+
service_account = google_service_account.ingestion_api.email
317+
318+
scaling {
319+
min_instance_count = 0
320+
max_instance_count = 2
321+
}
322+
323+
containers {
324+
image = "${local.image_base}/ingestion:latest"
325+
326+
env {
327+
name = "ENVIRONMENT"
328+
value = var.environment
329+
}
330+
env {
331+
name = "PROJECT_ID"
332+
value = var.project_id
333+
}
334+
335+
resources {
336+
limits = {
337+
cpu = "1"
338+
memory = "512Mi"
339+
}
340+
}
341+
}
342+
}
343+
344+
depends_on = [google_project_service.cloud_run]
345+
346+
lifecycle {
347+
ignore_changes = [
348+
template[0].containers[0].image,
349+
template[0].containers[0].env,
350+
]
351+
}
352+
}
353+
354+
# Cloud Run Service: state-manager
355+
resource "google_cloud_run_v2_service" "state_manager" {
356+
name = "state-manager"
357+
location = var.region
358+
project = var.project_id
359+
labels = local.common_labels
360+
361+
template {
362+
service_account = google_service_account.state_manager.email
363+
364+
scaling {
365+
min_instance_count = 1
366+
max_instance_count = 3
367+
}
368+
369+
containers {
370+
image = "${local.image_base}/state-manager:latest"
371+
372+
env {
373+
name = "ENVIRONMENT"
374+
value = var.environment
375+
}
376+
env {
377+
name = "PROJECT_ID"
378+
value = var.project_id
379+
}
380+
env {
381+
name = "SPRING_PROFILES_ACTIVE"
382+
value = var.environment
383+
}
384+
385+
resources {
386+
limits = {
387+
cpu = "2"
388+
memory = "1Gi"
389+
}
390+
}
391+
}
392+
}
393+
394+
depends_on = [google_project_service.cloud_run]
395+
396+
lifecycle {
397+
ignore_changes = [
398+
template[0].containers[0].image,
399+
template[0].containers[0].env,
400+
]
401+
}
402+
}
403+
404+
# Cloud Run Service: visualizer
405+
resource "google_cloud_run_v2_service" "visualizer" {
406+
name = "visualizer"
407+
location = var.region
408+
project = var.project_id
409+
labels = local.common_labels
410+
411+
template {
412+
service_account = google_service_account.visualizer.email
413+
414+
scaling {
415+
min_instance_count = 0
416+
max_instance_count = 2
417+
}
418+
419+
containers {
420+
image = "${local.image_base}/visualizer:latest"
421+
422+
env {
423+
name = "PROJECT_ID"
424+
value = var.project_id
425+
}
426+
env {
427+
name = "NODE_ENV"
428+
value = "production"
429+
}
430+
env {
431+
name = "PUBSUB_SUBSCRIPTION"
432+
value = "telemetry-sub"
433+
}
434+
435+
resources {
436+
limits = {
437+
cpu = "1"
438+
memory = "512Mi"
439+
}
440+
}
441+
}
442+
}
443+
444+
depends_on = [google_project_service.cloud_run]
445+
446+
lifecycle {
447+
ignore_changes = [
448+
template[0].containers[0].image,
449+
template[0].containers[0].env,
450+
]
451+
}
452+
}
453+
454+
# Cloud Run Job: path-optimizer
455+
resource "google_cloud_run_v2_job" "path_optimizer" {
456+
name = "path-optimizer"
457+
location = var.region
458+
project = var.project_id
459+
labels = local.common_labels
460+
461+
template {
462+
template {
463+
service_account = google_service_account.optimizer.email
464+
timeout = "300s"
465+
max_retries = 1
466+
467+
containers {
468+
image = "${local.image_base}/path-optimizer:latest"
469+
470+
env {
471+
name = "ENVIRONMENT"
472+
value = var.environment
473+
}
474+
env {
475+
name = "PROJECT_ID"
476+
value = var.project_id
477+
}
478+
env {
479+
name = "STATE_MANAGER_URL"
480+
value = google_cloud_run_v2_service.state_manager.uri
481+
}
482+
483+
resources {
484+
limits = {
485+
cpu = "2"
486+
memory = "2Gi"
487+
}
488+
}
489+
}
490+
}
491+
}
492+
493+
depends_on = [google_project_service.cloud_run]
494+
495+
lifecycle {
496+
ignore_changes = [
497+
template[0].template[0].containers[0].image,
498+
template[0].template[0].containers[0].env,
499+
]
500+
}
501+
}
502+
503+
# Cloud Run Job: simulator
293504
resource "google_cloud_run_v2_job" "simulator" {
294505
name = "simulator"
295506
location = var.region
@@ -315,7 +526,7 @@ resource "google_cloud_run_v2_job" "simulator" {
315526
}
316527
env {
317528
name = "INGESTION_API_URL"
318-
value = "https://ingestion-placeholder.run.app"
529+
value = google_cloud_run_v2_service.ingestion.uri
319530
}
320531

321532
resources {

0 commit comments

Comments
 (0)