Skip to content

Commit

Permalink
Remove Cloud Run service deployment from Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki0920 committed Jan 14, 2025
1 parent 9c700ce commit e904375
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 132 deletions.
42 changes: 21 additions & 21 deletions go/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ steps:
- '--set-secrets=DATABASE_URL=DATABASE_URL:latest'
- '--cpu-boost'
- '--allow-unauthenticated'
# - id: 'Deploy container image to Cloud Run for test'
# name: 'gcr.io/cloud-builders/gcloud'
# args:
# - 'run'
# - 'deploy'
# - 'company-ranking-test-server'
# - '--image=gcr.io/$PROJECT_ID/company-ranking-server:latest'
# - '--region=asia-northeast1'
# - '--project=company-ranking-prod'
# - '--port=8080'
# - '--cpu=1000m'
# - '--memory=512Mi'
# - '--min-instances=0'
# - '--max-instances=1'
# - '--concurrency=80'
# - '--timeout=300s'
# - '--service-account=1026927710795-compute@developer.gserviceaccount.com'
# - '--set-env-vars=FRONT_URL=company-ranking-test.vercel.app'
# - '--set-secrets=DATABASE_URL=DATABASE_URL:latest'
# - '--cpu-boost'
# - '--allow-unauthenticated'
- id: 'Deploy container image to Cloud Run for test'
name: 'gcr.io/cloud-builders/gcloud'
args:
- 'run'
- 'deploy'
- 'company-ranking-test-server'
- '--image=gcr.io/$PROJECT_ID/company-ranking-server:latest'
- '--region=asia-northeast1'
- '--project=company-ranking-prod'
- '--port=8080'
- '--cpu=1000m'
- '--memory=512Mi'
- '--min-instances=0'
- '--max-instances=1'
- '--concurrency=80'
- '--timeout=300s'
- '--service-account=1026927710795-compute@developer.gserviceaccount.com'
- '--set-env-vars=FRONT_URL=company-ranking-test.vercel.app'
- '--set-secrets=DATABASE_URL=DATABASE_TEST_URL:latest'
- '--cpu-boost'
- '--allow-unauthenticated'
images:
- 'gcr.io/$PROJECT_ID/company-ranking-server:$COMMIT_SHA'
238 changes: 127 additions & 111 deletions terraform/prod/google_cloud_run_v2_service.tf
Original file line number Diff line number Diff line change
@@ -1,118 +1,134 @@
resource "google_cloud_run_v2_service" "company_ranking_server" {
ingress = "INGRESS_TRAFFIC_ALL"
location = "asia-northeast1"
name = "company-ranking-server"
project = "company-ranking-prod"
template {
max_instance_request_concurrency = 80
service_account = "[email protected]"
timeout = "300s"
containers {
image = "gcr.io/company-ranking-prod/company-ranking-server:latest"
name = "company-ranking-server-1"
env {
name = "FRONT_URL"
value = "company-ranking.net"
}
env {
name = "DATABASE_URL"
value_source {
secret_key_ref {
secret = "DATABASE_URL"
version = "latest"
}
}
}
ports {
container_port = 8080
name = "http1"
}
resources {
cpu_idle = true
limits = {
cpu = "1000m"
memory = "512Mi"
}
startup_cpu_boost = true
}
startup_probe {
failure_threshold = 1
period_seconds = 240
timeout_seconds = 240
tcp_socket {
port = 8080
}
}
}
scaling {
max_instance_count = 1
min_instance_count = 0
}
}

# Cloud Run service is deployed by gcloud command using cloudbuild
# So, we don't need to deploy Cloud Run service by Terraform to avoid conflict
removed {
from = google_cloud_run_v2_service.company_ranking_server
lifecycle {
ignore_changes = [
client,
client_version,
]
destroy = false
}
}

resource "google_cloud_run_v2_service" "company_ranking_test_server" {
ingress = "INGRESS_TRAFFIC_ALL"
location = "asia-northeast1"
name = "company-ranking-test-server"
project = "company-ranking-prod"
template {
max_instance_request_concurrency = 80
service_account = "[email protected]"
timeout = "300s"
containers {
image = "gcr.io/company-ranking-prod/company-ranking-server:latest"
name = "company-ranking-server-1"
env {
name = "FRONT_URL"
value = "company-ranking.net"
}
env {
name = "DATABASE_URL"
value_source {
secret_key_ref {
secret = "DATABASE_TEST_URL"
version = "latest"
}
}
}
ports {
container_port = 8080
name = "http1"
}
resources {
cpu_idle = true
limits = {
cpu = "1000m"
memory = "512Mi"
}
}
startup_probe {
failure_threshold = 1
period_seconds = 240
timeout_seconds = 240
tcp_socket {
port = 8080
}
}
}
scaling {
max_instance_count = 1
min_instance_count = 0
}
}

removed {
from = google_cloud_run_v2_service.company_ranking_test_server
lifecycle {
ignore_changes = [
client,
client_version,
]
destroy = false
}
}

# resource "google_cloud_run_v2_service" "company_ranking_server" {
# ingress = "INGRESS_TRAFFIC_ALL"
# location = "asia-northeast1"
# name = "company-ranking-server"
# project = "company-ranking-prod"
# template {
# max_instance_request_concurrency = 80
# service_account = "[email protected]"
# timeout = "300s"
# containers {
# image = "gcr.io/company-ranking-prod/company-ranking-server:latest"
# name = "company-ranking-server-1"
# env {
# name = "FRONT_URL"
# value = "company-ranking.net"
# }
# env {
# name = "DATABASE_URL"
# value_source {
# secret_key_ref {
# secret = "DATABASE_URL"
# version = "latest"
# }
# }
# }
# ports {
# container_port = 8080
# name = "http1"
# }
# resources {
# cpu_idle = true
# limits = {
# cpu = "1000m"
# memory = "512Mi"
# }
# startup_cpu_boost = true
# }
# startup_probe {
# failure_threshold = 1
# period_seconds = 240
# timeout_seconds = 240
# tcp_socket {
# port = 8080
# }
# }
# }
# scaling {
# max_instance_count = 1
# min_instance_count = 0
# }
# }

# lifecycle {
# ignore_changes = [
# client,
# client_version,
# ]
# }
# }

# resource "google_cloud_run_v2_service" "company_ranking_test_server" {
# ingress = "INGRESS_TRAFFIC_ALL"
# location = "asia-northeast1"
# name = "company-ranking-test-server"
# project = "company-ranking-prod"
# template {
# max_instance_request_concurrency = 80
# service_account = "[email protected]"
# timeout = "300s"
# containers {
# image = "gcr.io/company-ranking-prod/company-ranking-server:latest"
# name = "company-ranking-server-1"
# env {
# name = "FRONT_URL"
# value = "company-ranking.net"
# }
# env {
# name = "DATABASE_URL"
# value_source {
# secret_key_ref {
# secret = "DATABASE_TEST_URL"
# version = "latest"
# }
# }
# }
# ports {
# container_port = 8080
# name = "http1"
# }
# resources {
# cpu_idle = true
# limits = {
# cpu = "1000m"
# memory = "512Mi"
# }
# }
# startup_probe {
# failure_threshold = 1
# period_seconds = 240
# timeout_seconds = 240
# tcp_socket {
# port = 8080
# }
# }
# }
# scaling {
# max_instance_count = 1
# min_instance_count = 0
# }
# }

# lifecycle {
# ignore_changes = [
# client,
# client_version,
# ]
# }
# }

0 comments on commit e904375

Please sign in to comment.