From 065b2282f9a4cfa327dbe29c32852f7552ef3332 Mon Sep 17 00:00:00 2001 From: James Kwon <96548424+hongil0316@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:46:35 -0500 Subject: [PATCH] Modify input variable correctly --- .../environment/prod/.terraform.lock.hcl | 22 ------ infrastructure/environment/prod/README.md | 23 ------- infrastructure/environment/prod/main.tf | 24 ------- infrastructure/environment/prod/variable.tf | 10 --- infrastructure/environment/staging/README.md | 23 ------- infrastructure/environment/staging/main.tf | 24 ------- .../environment/staging/variable.tf | 10 --- .../simple-node-pack-extract/main.tf | 1 + .../node-pack-extract-trigger/README.md | 10 --- .../module/node-pack-extract-trigger/main.tf | 67 ------------------- .../node-pack-extract-trigger/variable.tf | 49 -------------- .../node-pack-extract-trigger/version.tf | 8 --- .../.terraform.lock.hcl | 22 ------ .../node-pack-extract-trigger/README.md | 5 +- .../modules/node-pack-extract-trigger/main.tf | 8 +-- .../node-pack-extract-trigger/output.tf | 0 .../node-pack-extract-trigger/variable.tf | 30 +++++---- infrastructure/prod/main.tf | 1 + infrastructure/staging/main.tf | 1 + node-pack-extract/test/testdata/main.tf | 56 ---------------- node-pack-extract/trigger/README.md | 10 --- node-pack-extract/trigger/main.tf | 67 ------------------- node-pack-extract/trigger/output.tf | 11 --- node-pack-extract/trigger/variable.tf | 49 -------------- node-pack-extract/trigger/version.tf | 8 --- 25 files changed, 28 insertions(+), 511 deletions(-) delete mode 100644 infrastructure/environment/prod/.terraform.lock.hcl delete mode 100644 infrastructure/environment/prod/README.md delete mode 100644 infrastructure/environment/prod/main.tf delete mode 100644 infrastructure/environment/prod/variable.tf delete mode 100644 infrastructure/environment/staging/README.md delete mode 100644 infrastructure/environment/staging/main.tf delete mode 100644 infrastructure/environment/staging/variable.tf rename infrastructure/{example => examples}/simple-node-pack-extract/main.tf (95%) delete mode 100644 infrastructure/module/node-pack-extract-trigger/README.md delete mode 100644 infrastructure/module/node-pack-extract-trigger/main.tf delete mode 100644 infrastructure/module/node-pack-extract-trigger/variable.tf delete mode 100644 infrastructure/module/node-pack-extract-trigger/version.tf delete mode 100644 infrastructure/modules/node-pack-extract-trigger/.terraform.lock.hcl rename infrastructure/{module => modules}/node-pack-extract-trigger/output.tf (100%) delete mode 100644 node-pack-extract/test/testdata/main.tf delete mode 100644 node-pack-extract/trigger/README.md delete mode 100644 node-pack-extract/trigger/main.tf delete mode 100644 node-pack-extract/trigger/output.tf delete mode 100644 node-pack-extract/trigger/variable.tf delete mode 100644 node-pack-extract/trigger/version.tf diff --git a/infrastructure/environment/prod/.terraform.lock.hcl b/infrastructure/environment/prod/.terraform.lock.hcl deleted file mode 100644 index 8a45359..0000000 --- a/infrastructure/environment/prod/.terraform.lock.hcl +++ /dev/null @@ -1,22 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/google" { - version = "6.14.1" - constraints = "6.14.1" - hashes = [ - "h1:zhyWKVVqORklT7c28f6FzZ0z/g6pGa6FFtv/wp1MKDc=", - "zh:0a0cab3291bdac20fe31511b7aa9f3258b14add16d13110d4ebac18761277361", - "zh:178594db6fbff9974a7c65c65195a64c93d16f652a1a4136015b192faaa1ce2d", - "zh:379bbd6bd5b8add55ffd46c99a8081664e9004188f6df91f8f044e4268b86e42", - "zh:4899b6174a4492dbff3d94f56a901692a3f8d86a6db9de6a92b83d43b7ad4507", - "zh:6240820c3aeeaa8b9830fb4514d3ecb6e3fed8724340dfedaf89b4bb2265102f", - "zh:9a214e052c5c7b4e7bc409086832d4bd8e404b652b66344c26c314747c49744f", - "zh:a6cb9da102d371a52b750de5628a2b6b7cc7c20481d7fa3fb25a957b58b05777", - "zh:ab69d69f9c16461105a585f8a9c780eb06238827db269c5ad3f7c114922e7f20", - "zh:b716e219779295e9af2b632b2c0d534c90cca5c87352fc0c6dc8ebae671dd4d2", - "zh:d96e8d6c3109882d5527956acad12015a024fc24a6110e244007209b4f3069a0", - "zh:f49274564725189932a65cf1a4e8f40f46fca2537da7a673da9fea6ff7e3f195", - "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", - ] -} diff --git a/infrastructure/environment/prod/README.md b/infrastructure/environment/prod/README.md deleted file mode 100644 index 10d50c4..0000000 --- a/infrastructure/environment/prod/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Trigger for node-pack-extract production - -Terraform modules to setup trigger for cloud build that will run [node-pack-extract](../../../node-pack-extract/) - -## Requirements - -- Google Cloud Account - -## Configuration - -This use the following configuration value: - -- bucket_name: "comfy-registry " -- service account: "" -- topic_name: "comfy-registry-event" - -## Apply - -```bash -terraform apply - -var project_id=dreamboothy-dev - -var region=us-central1 -``` diff --git a/infrastructure/environment/prod/main.tf b/infrastructure/environment/prod/main.tf deleted file mode 100644 index 6086d7e..0000000 --- a/infrastructure/environment/prod/main.tf +++ /dev/null @@ -1,24 +0,0 @@ -terraform { - required_providers { - google = { - source = "hashicorp/google" - version = "6.14.1" - } - } -} - -provider "google" { - project = var.project_id - region = var.region -} - -module "node_pack_extract_trigger" { - source = "../../modules/node-pack-extract-trigger" - providers = { - google = google - } - region = var.region - bucket_name = "comfy-registry " - cloud_build_service_account = "cloud-scheduler@dreamboothy.iam.gserviceaccount.com" - topic_name = "comfy-registry-event" -} diff --git a/infrastructure/environment/prod/variable.tf b/infrastructure/environment/prod/variable.tf deleted file mode 100644 index 7694c45..0000000 --- a/infrastructure/environment/prod/variable.tf +++ /dev/null @@ -1,10 +0,0 @@ -variable "project_id" { - type = string - description = "google cloud project id" -} - -variable "region" { - type = string - default = "us-central1" - description = "google cloud region" -} diff --git a/infrastructure/environment/staging/README.md b/infrastructure/environment/staging/README.md deleted file mode 100644 index 3279ab1..0000000 --- a/infrastructure/environment/staging/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Trigger for node-pack-extract production - -Terraform modules to setup trigger for cloud build that will run [node-pack-extract](../../../node-pack-extract/) - -## Requirements - -- Google Cloud Account - -## Configuration - -This use the following configuration value: - -- bucket_name: "comfy-registry " -- service account: "" -- topic_name: "comfy-registry-event-staging" - -## Apply - -```bash -terraform apply - -var project_id=dreamboothy-dev - -var region=us-central1 -``` diff --git a/infrastructure/environment/staging/main.tf b/infrastructure/environment/staging/main.tf deleted file mode 100644 index f0420f9..0000000 --- a/infrastructure/environment/staging/main.tf +++ /dev/null @@ -1,24 +0,0 @@ -terraform { - required_providers { - google = { - source = "hashicorp/google" - version = "6.14.1" - } - } -} - -provider "google" { - project = var.project_id - region = var.region -} - -module "node_pack_extract_trigger" { - source = "../../modules/node-pack-extract-trigger" - providers = { - google = google - } - region = var.region - bucket_name = "comfy-registry " - cloud_build_service_account = "cloud-scheduler@dreamboothy.iam.gserviceaccount.com" - topic_name = "comfy-registry-event-stage" -} diff --git a/infrastructure/environment/staging/variable.tf b/infrastructure/environment/staging/variable.tf deleted file mode 100644 index 7694c45..0000000 --- a/infrastructure/environment/staging/variable.tf +++ /dev/null @@ -1,10 +0,0 @@ -variable "project_id" { - type = string - description = "google cloud project id" -} - -variable "region" { - type = string - default = "us-central1" - description = "google cloud region" -} diff --git a/infrastructure/example/simple-node-pack-extract/main.tf b/infrastructure/examples/simple-node-pack-extract/main.tf similarity index 95% rename from infrastructure/example/simple-node-pack-extract/main.tf rename to infrastructure/examples/simple-node-pack-extract/main.tf index 783d0a8..a421827 100644 --- a/infrastructure/example/simple-node-pack-extract/main.tf +++ b/infrastructure/examples/simple-node-pack-extract/main.tf @@ -40,6 +40,7 @@ module "node_pack_extract_trigger" { cloud_build_service_account = google_service_account.service_account.email topic_name = "${var.prefix}-comfy-registry-event" trigger_name = "${var.prefix}-comfy-registry-event" + registry_backend_url = "https://stagingapi.comfy.org" } output "trigger_id" { diff --git a/infrastructure/module/node-pack-extract-trigger/README.md b/infrastructure/module/node-pack-extract-trigger/README.md deleted file mode 100644 index bac6dee..0000000 --- a/infrastructure/module/node-pack-extract-trigger/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Trigger for node-pack-extract - -Terraform modules to setup trigger for cloud build that will run [node-pack-extract](../../../node-pack-extract/) - -## Requirements - -- Google Cloud Account -- Existing Google Cloud Storage public bucket where the Registry backend store the comfy node packs. -- Existing Service Account that is whitelisted in [service_account_auth](../../../server/middleware/authentication/service_account_auth.go#65) middleware and with `Service Account Token Creator` Role. -- [Connected repositories](https://cloud.google.com/build/docs/repositories) contains the [node-pack-extract](../../../node-pack-extract/) folder diff --git a/infrastructure/module/node-pack-extract-trigger/main.tf b/infrastructure/module/node-pack-extract-trigger/main.tf deleted file mode 100644 index d19f07a..0000000 --- a/infrastructure/module/node-pack-extract-trigger/main.tf +++ /dev/null @@ -1,67 +0,0 @@ -# get the existing GCS bucket -data "google_storage_bucket" "bucket" { - name = var.bucket_name -} - -# create a Pub/Sub topic -resource "google_pubsub_topic" "topic" { - name = var.topic_name -} - -# get the default GCS service account -data "google_storage_project_service_account" "gcs_account" { -} - -# Grant the GCS service account permission to publish to the Pub/Sub topic -resource "google_pubsub_topic_iam_binding" "gcs_publisher" { - topic = google_pubsub_topic.topic.name - role = "roles/pubsub.publisher" - members = ["serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}"] -} - -# enable GCS Bucket Notification to Pub/Sub -resource "google_storage_notification" "notification" { - bucket = data.google_storage_bucket.bucket.name - topic = google_pubsub_topic.topic.id - payload_format = "JSON_API_V1" - depends_on = [google_pubsub_topic_iam_binding.gcs_publisher] - event_types = [ - "OBJECT_FINALIZE", # Triggered when an object is successfully created or overwritten - ] -} - - -# Get the existing cloudbuild service account -data "google_service_account" "cloudbuild_service_account" { - account_id = var.cloud_build_service_account -} - -# Create the cloud build trigger -resource "google_cloudbuild_trigger" "trigger" { - name = var.trigger_name - location = var.region - service_account = data.google_service_account.cloudbuild_service_account.id - - pubsub_config { - topic = google_pubsub_topic.topic.id - } - - source_to_build { - uri = var.git_repo_uri - ref = "refs/heads/${var.git_repo_branch}" - repo_type = "GITHUB" - } - - git_file_source { - uri = var.git_repo_uri - revision = "refs/heads/${var.git_repo_branch}" - repo_type = "GITHUB" - path = "node-pack-extract/cloudbuild.yaml" - } - - substitutions = { - _CUSTOM_NODE_NAME = "custom-node" - _CUSTOM_NODE_URL = "https://storage.googleapis.com/$(body.message.data.bucket)/$(body.message.data.name)" - _REGISTRY_BACKEND_URL = var.registry_backend_url - } -} diff --git a/infrastructure/module/node-pack-extract-trigger/variable.tf b/infrastructure/module/node-pack-extract-trigger/variable.tf deleted file mode 100644 index 7cb5f13..0000000 --- a/infrastructure/module/node-pack-extract-trigger/variable.tf +++ /dev/null @@ -1,49 +0,0 @@ -# REQUIRED VARIABLE -variable "bucket_name" { - type = string - description = "Existing public bucket that store the comfy node-packs." -} - -variable "cloud_build_service_account" { - type = string - description = "Existing service account used to run the cloud build and used to access registry backend, e.g. cloud-build@my-project.iam.gserviceaccount.com. Note that this service account needs to have 'Service Account Token Creator' role." -} - -# OPTIONAL VARIABLE -variable "region" { - type = string - description = "Google Cloud region" - default = "us-central1" -} - -variable "topic_name" { - type = string - description = "Google Cloudpub/sub topic to be created" - default = "comfy-registry-event" -} - -variable "trigger_name" { - type = string - description = "Cloud build trigger name" - default = "comfy-registry-nodepack" - -} - -variable "git_repo_uri" { - type = string - description = "Connected git repo containing the cloud build pipeline. See https://cloud.google.com/build/docs/repositories" - default = "https://github.com/Comfy-Org/registry-backend" -} - -variable "git_repo_branch" { - type = string - description = "Git repo branch." - default = "master" -} - -variable "registry_backend_url" { - type = string - description = "The base url where registry backend can be reached" - default = "https://api.comfy.org" -} - diff --git a/infrastructure/module/node-pack-extract-trigger/version.tf b/infrastructure/module/node-pack-extract-trigger/version.tf deleted file mode 100644 index 7818333..0000000 --- a/infrastructure/module/node-pack-extract-trigger/version.tf +++ /dev/null @@ -1,8 +0,0 @@ -terraform { - required_providers { - google = { - source = "hashicorp/google" - version = "6.14.1" - } - } -} diff --git a/infrastructure/modules/node-pack-extract-trigger/.terraform.lock.hcl b/infrastructure/modules/node-pack-extract-trigger/.terraform.lock.hcl deleted file mode 100644 index 8a45359..0000000 --- a/infrastructure/modules/node-pack-extract-trigger/.terraform.lock.hcl +++ /dev/null @@ -1,22 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/google" { - version = "6.14.1" - constraints = "6.14.1" - hashes = [ - "h1:zhyWKVVqORklT7c28f6FzZ0z/g6pGa6FFtv/wp1MKDc=", - "zh:0a0cab3291bdac20fe31511b7aa9f3258b14add16d13110d4ebac18761277361", - "zh:178594db6fbff9974a7c65c65195a64c93d16f652a1a4136015b192faaa1ce2d", - "zh:379bbd6bd5b8add55ffd46c99a8081664e9004188f6df91f8f044e4268b86e42", - "zh:4899b6174a4492dbff3d94f56a901692a3f8d86a6db9de6a92b83d43b7ad4507", - "zh:6240820c3aeeaa8b9830fb4514d3ecb6e3fed8724340dfedaf89b4bb2265102f", - "zh:9a214e052c5c7b4e7bc409086832d4bd8e404b652b66344c26c314747c49744f", - "zh:a6cb9da102d371a52b750de5628a2b6b7cc7c20481d7fa3fb25a957b58b05777", - "zh:ab69d69f9c16461105a585f8a9c780eb06238827db269c5ad3f7c114922e7f20", - "zh:b716e219779295e9af2b632b2c0d534c90cca5c87352fc0c6dc8ebae671dd4d2", - "zh:d96e8d6c3109882d5527956acad12015a024fc24a6110e244007209b4f3069a0", - "zh:f49274564725189932a65cf1a4e8f40f46fca2537da7a673da9fea6ff7e3f195", - "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", - ] -} diff --git a/infrastructure/modules/node-pack-extract-trigger/README.md b/infrastructure/modules/node-pack-extract-trigger/README.md index c4c9016..bac6dee 100644 --- a/infrastructure/modules/node-pack-extract-trigger/README.md +++ b/infrastructure/modules/node-pack-extract-trigger/README.md @@ -5,5 +5,6 @@ Terraform modules to setup trigger for cloud build that will run [node-pack-extr ## Requirements - Google Cloud Account -- Existing Google Cloud Storage bucket where the Registry backend store the comfy node packs. -- Existing Service Account with `Service Account Token Creator` Role plus the one that is whitelisted in [service_account_auth](../../../server/middleware/authentication/service_account_auth.go#65) middleware. +- Existing Google Cloud Storage public bucket where the Registry backend store the comfy node packs. +- Existing Service Account that is whitelisted in [service_account_auth](../../../server/middleware/authentication/service_account_auth.go#65) middleware and with `Service Account Token Creator` Role. +- [Connected repositories](https://cloud.google.com/build/docs/repositories) contains the [node-pack-extract](../../../node-pack-extract/) folder diff --git a/infrastructure/modules/node-pack-extract-trigger/main.tf b/infrastructure/modules/node-pack-extract-trigger/main.tf index 2dbffc4..d19f07a 100644 --- a/infrastructure/modules/node-pack-extract-trigger/main.tf +++ b/infrastructure/modules/node-pack-extract-trigger/main.tf @@ -38,7 +38,7 @@ data "google_service_account" "cloudbuild_service_account" { # Create the cloud build trigger resource "google_cloudbuild_trigger" "trigger" { - name = "comfy-registry-nodepack" + name = var.trigger_name location = var.region service_account = data.google_service_account.cloudbuild_service_account.id @@ -60,8 +60,8 @@ resource "google_cloudbuild_trigger" "trigger" { } substitutions = { - _CUSTOM_NODE_NAME = "custom-node" - _CUSTOM_NODE_URL = "https://storage.googleapis.com/$(body.message.data.bucket)/$(body.message.data.name)" - _NODEPACK_HANDLER = var.registry_backend_url + _CUSTOM_NODE_NAME = "custom-node" + _CUSTOM_NODE_URL = "https://storage.googleapis.com/$(body.message.data.bucket)/$(body.message.data.name)" + _REGISTRY_BACKEND_URL = var.registry_backend_url } } diff --git a/infrastructure/module/node-pack-extract-trigger/output.tf b/infrastructure/modules/node-pack-extract-trigger/output.tf similarity index 100% rename from infrastructure/module/node-pack-extract-trigger/output.tf rename to infrastructure/modules/node-pack-extract-trigger/output.tf diff --git a/infrastructure/modules/node-pack-extract-trigger/variable.tf b/infrastructure/modules/node-pack-extract-trigger/variable.tf index ceb77b0..bfcb127 100644 --- a/infrastructure/modules/node-pack-extract-trigger/variable.tf +++ b/infrastructure/modules/node-pack-extract-trigger/variable.tf @@ -1,7 +1,7 @@ # REQUIRED VARIABLE variable "bucket_name" { type = string - description = "existing bucket name" + description = "Existing public bucket that store the comfy node-packs." } variable "cloud_build_service_account" { @@ -9,34 +9,40 @@ variable "cloud_build_service_account" { description = "Existing service account used to run the cloud build and used to access registry backend, e.g. cloud-build@my-project.iam.gserviceaccount.com. Note that this service account needs to have 'Service Account Token Creator' role." } +variable "registry_backend_url" { + type = string + description = "The base url where registry backend can be reached" +} + # OPTIONAL VARIABLE variable "region" { type = string + description = "Google Cloud region" default = "us-central1" - description = "google cloud region" } variable "topic_name" { type = string - description = "pub/sub topic to be created" + description = "Google Cloudpub/sub topic to be created" default = "comfy-registry-event" } -variable "git_repo_uri" { +variable "trigger_name" { type = string - description = "git repo containing the cloud build pipeline" - default = "https://github.com/Comfy-Org/registry-backend" + description = "Cloud build trigger name" + default = "comfy-registry-nodepack" + } -variable "git_repo_branch" { +variable "git_repo_uri" { type = string - description = "git repo branch" - default = "master" + description = "Connected git repo containing the cloud build pipeline. See https://cloud.google.com/build/docs/repositories" + default = "https://github.com/Comfy-Org/registry-backend" } -variable "registry_backend_url" { +variable "git_repo_branch" { type = string - description = "the url where registry backend can be reached" - default = "https://api.comfy.org" + description = "Git repo branch." + default = "main" } diff --git a/infrastructure/prod/main.tf b/infrastructure/prod/main.tf index 8a7136f..06c5d43 100644 --- a/infrastructure/prod/main.tf +++ b/infrastructure/prod/main.tf @@ -21,4 +21,5 @@ module "node_pack_extract_trigger" { bucket_name = "comfy-registry" cloud_build_service_account = "cloud-scheduler@dreamboothy.iam.gserviceaccount.com" topic_name = "comfy-registry-event" + registry_backend_url = "https://api.comfy.org" } diff --git a/infrastructure/staging/main.tf b/infrastructure/staging/main.tf index ca71d9e..ff2055e 100644 --- a/infrastructure/staging/main.tf +++ b/infrastructure/staging/main.tf @@ -21,4 +21,5 @@ module "node_pack_extract_trigger" { bucket_name = "comfy-registry" cloud_build_service_account = "cloud-scheduler@dreamboothy.iam.gserviceaccount.com" topic_name = "comfy-registry-event-staging" + registry_backend_url = "https://stagingapi.comfy.org" } diff --git a/node-pack-extract/test/testdata/main.tf b/node-pack-extract/test/testdata/main.tf deleted file mode 100644 index ab19d05..0000000 --- a/node-pack-extract/test/testdata/main.tf +++ /dev/null @@ -1,56 +0,0 @@ -terraform { - required_providers { - google = { - source = "hashicorp/google" - version = "6.14.1" - } - } -} - -variable "prefix" { - type = string -} - -variable "region" { - type = string - default = "us-central1" -} - -provider "google" { - region = var.region -} - -resource "google_storage_bucket" "bucket" { - name = "${var.prefix}-comfy-registry-bucket" - location = var.region -} - -resource "google_service_account" "service_account" { - account_id = "${var.prefix}-comfy-registry-sa" -} - -module "node_pack_extract_trigger" { - depends_on = [google_service_account.service_account, google_storage_bucket.bucket] - source = "../../../node-pack-extract/trigger" - providers = { - google = google - } - region = var.region - bucket_name = google_storage_bucket.bucket.name - cloud_build_service_account = google_service_account.service_account.email - topic_name = "${var.prefix}-comfy-registry-event" - trigger_name = "${var.prefix}-comfy-registry-event" -} - -output "trigger_id" { - value = module.node_pack_extract_trigger.trigger_id -} -output "topic_id" { - value = module.node_pack_extract_trigger.topic_id -} -output "bucket_notification_id" { - value = module.node_pack_extract_trigger.bucket_notification_id -} -output "bucket_name" { - value = google_storage_bucket.bucket.name -} diff --git a/node-pack-extract/trigger/README.md b/node-pack-extract/trigger/README.md deleted file mode 100644 index d354272..0000000 --- a/node-pack-extract/trigger/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Trigger for node-pack-extract - -Terraform modules to setup trigger for cloud build that will run [node-pack-extract](../../../node-pack-extract/) - -## Requirements - -- Google Cloud Account -- Existing Google Cloud Storage public bucket where the Registry backend store the comfy node packs. -- Existing Service Account that is whitelisted in [service_account_auth](../../../server/middleware/authentication/service_account_auth.go#65) middleware and with `Service Account Token Creator` Role. -- [Connected repositories](https://cloud.google.com/build/docs/repositories) diff --git a/node-pack-extract/trigger/main.tf b/node-pack-extract/trigger/main.tf deleted file mode 100644 index d19f07a..0000000 --- a/node-pack-extract/trigger/main.tf +++ /dev/null @@ -1,67 +0,0 @@ -# get the existing GCS bucket -data "google_storage_bucket" "bucket" { - name = var.bucket_name -} - -# create a Pub/Sub topic -resource "google_pubsub_topic" "topic" { - name = var.topic_name -} - -# get the default GCS service account -data "google_storage_project_service_account" "gcs_account" { -} - -# Grant the GCS service account permission to publish to the Pub/Sub topic -resource "google_pubsub_topic_iam_binding" "gcs_publisher" { - topic = google_pubsub_topic.topic.name - role = "roles/pubsub.publisher" - members = ["serviceAccount:${data.google_storage_project_service_account.gcs_account.email_address}"] -} - -# enable GCS Bucket Notification to Pub/Sub -resource "google_storage_notification" "notification" { - bucket = data.google_storage_bucket.bucket.name - topic = google_pubsub_topic.topic.id - payload_format = "JSON_API_V1" - depends_on = [google_pubsub_topic_iam_binding.gcs_publisher] - event_types = [ - "OBJECT_FINALIZE", # Triggered when an object is successfully created or overwritten - ] -} - - -# Get the existing cloudbuild service account -data "google_service_account" "cloudbuild_service_account" { - account_id = var.cloud_build_service_account -} - -# Create the cloud build trigger -resource "google_cloudbuild_trigger" "trigger" { - name = var.trigger_name - location = var.region - service_account = data.google_service_account.cloudbuild_service_account.id - - pubsub_config { - topic = google_pubsub_topic.topic.id - } - - source_to_build { - uri = var.git_repo_uri - ref = "refs/heads/${var.git_repo_branch}" - repo_type = "GITHUB" - } - - git_file_source { - uri = var.git_repo_uri - revision = "refs/heads/${var.git_repo_branch}" - repo_type = "GITHUB" - path = "node-pack-extract/cloudbuild.yaml" - } - - substitutions = { - _CUSTOM_NODE_NAME = "custom-node" - _CUSTOM_NODE_URL = "https://storage.googleapis.com/$(body.message.data.bucket)/$(body.message.data.name)" - _REGISTRY_BACKEND_URL = var.registry_backend_url - } -} diff --git a/node-pack-extract/trigger/output.tf b/node-pack-extract/trigger/output.tf deleted file mode 100644 index 32cbceb..0000000 --- a/node-pack-extract/trigger/output.tf +++ /dev/null @@ -1,11 +0,0 @@ -output "topic_id" { - value = google_pubsub_topic.topic.id -} - -output "bucket_notification_id" { - value = google_storage_notification.notification.id -} - -output "trigger_id" { - value = google_cloudbuild_trigger.trigger.id -} diff --git a/node-pack-extract/trigger/variable.tf b/node-pack-extract/trigger/variable.tf deleted file mode 100644 index 7cb5f13..0000000 --- a/node-pack-extract/trigger/variable.tf +++ /dev/null @@ -1,49 +0,0 @@ -# REQUIRED VARIABLE -variable "bucket_name" { - type = string - description = "Existing public bucket that store the comfy node-packs." -} - -variable "cloud_build_service_account" { - type = string - description = "Existing service account used to run the cloud build and used to access registry backend, e.g. cloud-build@my-project.iam.gserviceaccount.com. Note that this service account needs to have 'Service Account Token Creator' role." -} - -# OPTIONAL VARIABLE -variable "region" { - type = string - description = "Google Cloud region" - default = "us-central1" -} - -variable "topic_name" { - type = string - description = "Google Cloudpub/sub topic to be created" - default = "comfy-registry-event" -} - -variable "trigger_name" { - type = string - description = "Cloud build trigger name" - default = "comfy-registry-nodepack" - -} - -variable "git_repo_uri" { - type = string - description = "Connected git repo containing the cloud build pipeline. See https://cloud.google.com/build/docs/repositories" - default = "https://github.com/Comfy-Org/registry-backend" -} - -variable "git_repo_branch" { - type = string - description = "Git repo branch." - default = "master" -} - -variable "registry_backend_url" { - type = string - description = "The base url where registry backend can be reached" - default = "https://api.comfy.org" -} - diff --git a/node-pack-extract/trigger/version.tf b/node-pack-extract/trigger/version.tf deleted file mode 100644 index 7818333..0000000 --- a/node-pack-extract/trigger/version.tf +++ /dev/null @@ -1,8 +0,0 @@ -terraform { - required_providers { - google = { - source = "hashicorp/google" - version = "6.14.1" - } - } -}