Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide artifact endpoint definitions #1448

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions terraform/modules.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ module "api-gateway" {
}

module "cloud-run-build" {
docker_image = "${var.project_region}-docker.pkg.dev/${var.project_id}/cloud-run-source-deploy/api.ashdavies.dev"
source = "./modules/google/cloud-run-build"
service_name = "playground-service"
location = var.project_region
project = var.project_id
image_name = "api.ashdavies.dev"
location = var.project_region
project = var.project_id
repository_id = "cloud-run-source-deploy"
service_name = "playground-service"
source = "./modules/google/cloud-run-build"
}

# module.cloud-run-endpoint is deprecated
module "cloud-run-endpoint" {
source = "./modules/google/cloud-run-endpoint"
config_id = module.cloud-run-endpoint.config_id
container_image = "${var.project_region}-docker.pkg.dev/${var.project_id}/endpoints-release/endpoints-runtime-serverless:latest"
image_name = "endpoints-runtime-serverless"
repository_id = "endpoints-release"
endpoint_name = "api.ashdavies.dev"
image_repository = "${var.project_region}-docker.pkg.dev/${var.project_id}/endpoints-release"
location = var.project_region
Expand Down
13 changes: 9 additions & 4 deletions terraform/modules/google/cloud-run-build/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
resource "google_cloud_run_service" "main" {
name = var.service_name
location = var.location
autogenerate_revision_name = true
name = var.service_name
location = var.location

template {
spec {
containers {
image = "${var.docker_image}:latest"
image = data.google_artifact_registry_docker_image.main.self_link
}
}
}
Expand All @@ -16,3 +15,9 @@ resource "google_cloud_run_service" "main" {
percent = var.percent
}
}

data "google_artifact_registry_docker_image" "main" {
location = var.location
repository_id = var.repository_id
image_name = var.image_name
}
10 changes: 6 additions & 4 deletions terraform/modules/google/cloud-run-build/variables.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
variable "docker_image" {
variable "image_name" {
description = <<EOT
Docker image name. This is most often a reference to a container located in the container
registry, such as europe-west1-docker.pkg.dev/project/cloud-run-source-deploy/artifact.
More info: https://kubernetes.io/docs/concepts/containers/images
"The image name to fetch. If no digest or tag is provided, then the latest modified image will be used."
EOT
}

Expand All @@ -28,6 +26,10 @@ variable "project" {
description = "The project for the resource."
}

variable "repository_id" {
description = "The last part of the repository name to fetch from."
}

variable "service_name" {
description = <<EOT
Name must be unique within a namespace, within a Cloud Run region. Is required when creating
Expand Down
57 changes: 31 additions & 26 deletions terraform/modules/google/cloud-run-endpoint/main.tf
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@

data "external" "esp_version" {
program = ["bash", "${path.module}/scripts/esp_full_version", "${var.esp_version}"]
}

resource "null_resource" "main" {
provisioner "local-exec" {
command = <<EOS
bash ${path.module}/scripts/gcloud_build_image \
-g ${var.image_repository} \
-s ${var.endpoint_name} \
-c ${var.config_id} \
-p ${var.project} \
-v ${var.esp_version}
EOS
}

triggers = {
config_id = google_endpoints_service.main.config_id
esp_version = data.external.esp_version.result.esp_full_version
}
}

resource "google_cloud_run_service" "main" {
depends_on = [null_resource.main]
name = var.service_name
location = var.location
project = var.project

template {
spec {
containers {
image = var.container_image
image = data.google_artifact_registry_docker_image.main.self_link
}
}
}
Expand All @@ -39,15 +17,42 @@ resource "google_cloud_run_service" "main" {
latest_revision = true
}

autogenerate_revision_name = true

lifecycle {
prevent_destroy = true
}
}

data "google_artifact_registry_docker_image" "main" {
depends_on = [null_resource.main]
location = var.location
repository_id = var.repository_id
image_name = var.image_name
}

resource "null_resource" "main" {
provisioner "local-exec" {
command = <<EOS
bash ${path.module}/scripts/gcloud_build_image \
-g ${var.image_repository} \
-s ${var.endpoint_name} \
-c ${var.config_id} \
-p ${var.project} \
-v ${var.esp_version}
EOS
}

triggers = {
config_id = google_endpoints_service.main.config_id
esp_version = data.external.esp_version.result.esp_full_version
}
}

resource "google_endpoints_service" "main" {
openapi_config = var.openapi_config
service_name = var.endpoint_name
project = var.project
}

data "external" "esp_version" {
program = ["bash", "${path.module}/scripts/esp_full_version", var.esp_version]
}
Empty file.
18 changes: 10 additions & 8 deletions terraform/modules/google/cloud-run-endpoint/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ variable "config_id" {
description = "The id of the service configuration resource."
}

variable "container_image" {
description = <<EOT
Docker image name. This is most often a reference to a container located in the container
registry, such as europe-west1-docker.pkg.dev/project/cloud-run-source-deploy/artifact.
More info: https://kubernetes.io/docs/concepts/containers/images
EOT
}

variable "endpoint_name" {
description = ""
}
Expand All @@ -20,6 +12,12 @@ variable "esp_version" {
default = "2.40.0"
}

variable "image_name" {
description = <<EOT
"The image name to fetch. If no digest or tag is provided, then the latest modified image will be used."
EOT
}

variable "image_repository" {
description = ""
}
Expand All @@ -43,3 +41,7 @@ variable "service_name" {
variable "project" {
description = "The project for the resource."
}

variable "repository_id" {
description = "The last part of the repository name to fetch from."
}
Loading