File tree 6 files changed +35
-17
lines changed
6 files changed +35
-17
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ module "cloudrun" {
55
55
plugin_daemon_key = var. plugin_daemon_key
56
56
plugin_dify_inner_api_key = var. plugin_dify_inner_api_key
57
57
dify_plugin_daemon_version = var. dify_plugin_daemon_version
58
+ plugin_daemon_storage_name = module. storage . plugin_daemon_storage_bucket_name
58
59
shared_env_vars = local. shared_env_vars
59
60
}
60
61
Original file line number Diff line number Diff line change 1
1
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
-
18
2
backend "gcs" {
19
3
bucket = " your-tfstate-bucket" # replace with your bucket name
20
4
prefix = " dify"
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ resource "google_service_account" "dify_service_account" {
6
6
resource "google_project_iam_member" "dify_service_account_role" {
7
7
for_each = toset ([
8
8
" roles/run.admin" ,
9
+ " roles/storage.admin" ,
9
10
])
10
11
project = var. project_id
11
12
member = " serviceAccount:${ google_service_account . dify_service_account . email } "
@@ -35,7 +36,8 @@ resource "google_cloud_run_v2_service" "dify_service" {
35
36
location = var. region
36
37
ingress = var. cloud_run_ingress
37
38
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"
39
41
containers {
40
42
name = " nginx"
41
43
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" {
185
187
name = " PM2_INSTANCES"
186
188
value = 2
187
189
}
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
+ }
188
195
env {
189
196
name = " LOOP_NODE_MAX_COUNT"
190
197
value = 100
@@ -286,6 +293,10 @@ resource "google_cloud_run_v2_service" "dify_service" {
286
293
port = 5003
287
294
}
288
295
}
296
+ volume_mounts {
297
+ name = " plugin-daemon"
298
+ mount_path = " /app/storage"
299
+ }
289
300
}
290
301
vpc_access {
291
302
network_interfaces {
@@ -298,6 +309,13 @@ resource "google_cloud_run_v2_service" "dify_service" {
298
309
min_instance_count = 1
299
310
max_instance_count = 5
300
311
}
312
+ volumes {
313
+ name = " plugin-daemon"
314
+ gcs {
315
+ bucket = var. plugin_daemon_storage_name
316
+ read_only = false
317
+ }
318
+ }
301
319
}
302
320
}
303
321
Original file line number Diff line number Diff line change @@ -58,6 +58,10 @@ variable "dify_plugin_daemon_version" {
58
58
type = string
59
59
}
60
60
61
+ variable "plugin_daemon_storage_name" {
62
+ type = string
63
+ }
64
+
61
65
variable "shared_env_vars" {
62
66
type = map (string )
63
67
}
Original file line number Diff line number Diff line change @@ -8,6 +8,13 @@ resource "google_storage_bucket" "dify_storage" {
8
8
uniform_bucket_level_access = true
9
9
}
10
10
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
+
11
18
resource "google_service_account" "storage_admin" {
12
19
account_id = " storage-admin-for-dify"
13
20
display_name = " Storage Admin Service Account"
Original file line number Diff line number Diff line change @@ -4,4 +4,8 @@ output "storage_admin_key_base64" {
4
4
5
5
output "storage_bucket_name" {
6
6
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
7
11
}
You can’t perform that action at this time.
0 commit comments