Skip to content

Commit 63be8b3

Browse files
authored
Merge pull request #14 from DeNA/feature/add-gcs-for-plugin-daemon-storage-volume
2 parents 10189c4 + ff034a4 commit 63be8b3

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

terraform/environments/dev/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module "cloudrun" {
5555
plugin_daemon_key = var.plugin_daemon_key
5656
plugin_dify_inner_api_key = var.plugin_dify_inner_api_key
5757
dify_plugin_daemon_version = var.dify_plugin_daemon_version
58+
plugin_daemon_storage_name = module.storage.plugin_daemon_storage_bucket_name
5859
shared_env_vars = local.shared_env_vars
5960
}
6061

terraform/environments/dev/provider.tf

-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11
terraform {
2-
required_version = ">=1.5.0"
3-
required_providers {
4-
google = {
5-
source = "hashicorp/google"
6-
version = "5.10.0"
7-
}
8-
google-beta = {
9-
source = "hashicorp/google-beta"
10-
version = "5.10.0"
11-
}
12-
archive = {
13-
source = "hashicorp/archive"
14-
version = "2.4.0"
15-
}
16-
}
17-
182
backend "gcs" {
193
bucket = "your-tfstate-bucket" # replace with your bucket name
204
prefix = "dify"

terraform/modules/cloudrun/main.tf

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ resource "google_service_account" "dify_service_account" {
66
resource "google_project_iam_member" "dify_service_account_role" {
77
for_each = toset([
88
"roles/run.admin",
9+
"roles/storage.admin",
910
])
1011
project = var.project_id
1112
member = "serviceAccount:${google_service_account.dify_service_account.email}"
@@ -35,7 +36,8 @@ resource "google_cloud_run_v2_service" "dify_service" {
3536
location = var.region
3637
ingress = var.cloud_run_ingress
3738
template {
38-
service_account = google_service_account.dify_service_account.email
39+
service_account = google_service_account.dify_service_account.email
40+
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
3941
containers {
4042
name = "nginx"
4143
image = "${var.region}-docker.pkg.dev/${var.project_id}/${var.nginx_repository_id}/dify-nginx:latest"
@@ -185,6 +187,11 @@ resource "google_cloud_run_v2_service" "dify_service" {
185187
name = "PM2_INSTANCES"
186188
value = 2
187189
}
190+
# NOTE: Changing PM2_HOME is required for pm2 to work properly on Cloud Run Gen2 environment because of permission issues
191+
env {
192+
name = "PM2_HOME"
193+
value = "/app/web/.pm2"
194+
}
188195
env {
189196
name = "LOOP_NODE_MAX_COUNT"
190197
value = 100
@@ -286,6 +293,10 @@ resource "google_cloud_run_v2_service" "dify_service" {
286293
port = 5003
287294
}
288295
}
296+
volume_mounts {
297+
name = "plugin-daemon"
298+
mount_path = "/app/storage"
299+
}
289300
}
290301
vpc_access {
291302
network_interfaces {
@@ -298,6 +309,13 @@ resource "google_cloud_run_v2_service" "dify_service" {
298309
min_instance_count = 1
299310
max_instance_count = 5
300311
}
312+
volumes {
313+
name = "plugin-daemon"
314+
gcs {
315+
bucket = var.plugin_daemon_storage_name
316+
read_only = false
317+
}
318+
}
301319
}
302320
}
303321

terraform/modules/cloudrun/variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ variable "dify_plugin_daemon_version" {
5858
type = string
5959
}
6060

61+
variable "plugin_daemon_storage_name" {
62+
type = string
63+
}
64+
6165
variable "shared_env_vars" {
6266
type = map(string)
6367
}

terraform/modules/storage/main.tf

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ resource "google_storage_bucket" "dify_storage" {
88
uniform_bucket_level_access = true
99
}
1010

11+
resource "google_storage_bucket" "plugin_daemon_storage" {
12+
force_destroy = false
13+
location = upper(var.region)
14+
name = "${var.project_id}_plugin-daemon-storage"
15+
project = var.project_id
16+
}
17+
1118
resource "google_service_account" "storage_admin" {
1219
account_id = "storage-admin-for-dify"
1320
display_name = "Storage Admin Service Account"

terraform/modules/storage/outputs.tf

+4
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ output "storage_admin_key_base64" {
44

55
output "storage_bucket_name" {
66
value = google_storage_bucket.dify_storage.name
7+
}
8+
9+
output "plugin_daemon_storage_bucket_name" {
10+
value = google_storage_bucket.plugin_daemon_storage.name
711
}

0 commit comments

Comments
 (0)