souls 0.31.1 → 0.32.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6efcfd5a262a33c5d1323e9e2e423a8abf4d4e8f86783ce13bd1332bfe4c7fa7
4
- data.tar.gz: 1553a17298b0c55dc273f6b18eacd3165868346501c2431f85ecc7e4444519b1
3
+ metadata.gz: 3132263bcdd5298bcb85c331b84ff6e710d2da0b242980d98c16a00346cd6a57
4
+ data.tar.gz: 3f8505756b2b9c2920a6c16a59431033a6367d44b252a548aa81896970a85cf4
5
5
  SHA512:
6
- metadata.gz: 7e3b02ca9c947f4a9784ee07500fc2ed470e7d77f8a47e6d6ffe846860f8a769aa7a27d4ad84d735029445cd80e8e1f697959039049f771c00061948825d52ac
7
- data.tar.gz: 6f4649ee64d7ccb0300a51ed87c0107ed12b696e4f212a4fac088b588766c709fe660f88fb6b3dc1b23452b0cedb8218e7e2f675ec62aee6065164e0a8ca0ab6
6
+ metadata.gz: ca33516f16eca98178a0d001c6cbd1fcce2f4fc958d3fd8301aab68f641d42014206f95abb064567c670c7eeb328e35365dbde506500182bd85cdc13a78a5207
7
+ data.tar.gz: 2a7469b646ba9f67053f508957b68729d9f69e1343444c5decb8d1328b772309cec11a5767238601364a1afe133255461724e3e30d6ef01a70479861c4904e27
data/exe/souls CHANGED
@@ -2,7 +2,7 @@
2
2
  require "souls"
3
3
  begin
4
4
  souls_command = ARGV[0]
5
- require("./config/souls") unless ["new", "i", "-v", "deploy"].include?(souls_command)
5
+ require("./config/souls") unless ["new", "docker", "-v", "deploy"].include?(souls_command)
6
6
  rescue StandardError
7
7
  puts("Make sure you are at SOULs APP directory!")
8
8
  end
@@ -80,11 +80,34 @@ begin
80
80
  send_method = ARGV[1]
81
81
  Souls::Docker.public_send(send_method)
82
82
  when "gcloud"
83
- args = ARGV
83
+ command = ARGV[1]
84
84
  status = Paint["Running Gcloud Commands...", :yellow]
85
85
  Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
86
86
  Whirly.status = status
87
- Souls::Gcloud.return_method(args)
87
+ case command
88
+ when "get_iam_key"
89
+ app_name = Souls.configuration.app
90
+ project_id = Souls.configuration.project_id
91
+ Souls::Gcloud::Iam.create_service_account(service_account: app_name)
92
+ Souls::Gcloud::Iam.create_service_account_key(service_account: app_name, project_id: project_id)
93
+ Souls::Gcloud.enable_permissions
94
+ Souls::Gcloud::Iam.add_permissions(service_account: app_name, project_id: project_id)
95
+ Souls::Gcloud::Iam.export_key_to_console
96
+ when "auth_login"
97
+ project_id = Souls.configuration.project_id
98
+ Souls::Gcloud.auth_login(project_id: project_id)
99
+ else
100
+ module_name = ARGV[1]
101
+ method_name = ARGV[2]
102
+ ARGV.shift(3)
103
+ key_strings = []
104
+ keys = []
105
+ ARGV.each { |n| n.include?(":") ? keys << n.gsub(":", "").to_sym : key_strings << n }
106
+ raise(StandardError, "wrong arguments!") unless keys.size == key_strings.size
107
+
108
+ args = keys.zip(key_strings).to_h
109
+ Object.const_get("Souls::Gcloud::#{module_name.camelize}").public_send(method_name.to_sym, **args)
110
+ end
88
111
  Whirly.status = "Done!"
89
112
  end
90
113
  when "-v", "--version", "v", "version", "-version", "--v"
@@ -1,8 +1,8 @@
1
- require_relative "./gcloud/compute"
2
1
  require_relative "./gcloud/iam"
3
2
  require_relative "./gcloud/pubsub"
4
- require_relative "./gcloud/methods"
5
3
  require_relative "./gcloud/run"
4
+ require_relative "./gcloud/sql"
5
+ require_relative "./gcloud/gcloud"
6
6
 
7
7
  module Souls
8
8
  module Gcloud
@@ -24,14 +24,6 @@ module Souls
24
24
  system("gcloud services enable run.googleapis.com")
25
25
  puts("Operating permission to run.googleapis.com")
26
26
  end
27
-
28
- def create_sql_instance(instance_name: "souls-db", root_pass: "Postgre123!", zone: "asia-northeast1-b")
29
- system(
30
- "gcloud sql instances create #{instance_name}
31
- --database-version=POSTGRES_13 --cpu=2 --memory=7680MB --zone=#{zone}
32
- --root-password='#{root_pass}' --database-flags cloudsql.iam_authentication=on"
33
- )
34
- end
35
27
  end
36
28
  end
37
29
  end
@@ -1,78 +1,8 @@
1
+ require_relative "./iam/iam"
2
+
1
3
  module Souls
2
4
  module Gcloud
3
- class << self
4
- def create_service_account(service_account: "souls-app")
5
- system(
6
- "gcloud iam service-accounts create #{service_account} \
7
- --description='Souls Service Account' \
8
- --display-name=#{service_account}"
9
- )
10
- end
11
-
12
- def create_service_account_key(service_account: "souls-app", project_id: "souls-app")
13
- system(
14
- "gcloud iam service-accounts keys create ./config/keyfile.json \
15
- --iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com"
16
- )
17
- end
18
-
19
- def export_key_to_console
20
- github_repo = Souls.configuration.github_repo || "elsoul/souls"
21
- file_path = "config/keyfile.json"
22
- puts(Paint["======= below(ここから)=======", :cyan])
23
- text = []
24
- File.open(file_path, "r") do |line|
25
- line.each_line do |l|
26
- text << l
27
- end
28
- end
29
- key = text.join(",").gsub(/^,/, "").chomp!
30
- puts(Paint[key, :white])
31
- puts(Paint["======= above(ここまで)=======", :cyan])
32
- github_secret_url = "https://github.com/#{github_repo}/settings/secrets/actions"
33
- souls_doc_url = "https://souls.elsoul.nl/docs/chapter2/#43-github-シークレットキーの登録"
34
- txt1 = <<~TEXT
35
-
36
- ⬆⬆⬆ Copy the service account key above ⬆⬆⬆⬆
37
-
38
- And
39
-
40
- Go to %{yellow_text}
41
-
42
- Reference: %{yellow_text2}
43
- TEXT
44
- puts(
45
- Paint % [
46
- txt1,
47
- :white,
48
- { yellow_text: [github_secret_url, :yellow], yellow_text2: [souls_doc_url, :yellow] }
49
- ]
50
- )
51
- FileUtils.rm(file_path)
52
- end
53
-
54
- def add_service_account_role(service_account: "souls-app", project_id: "souls-app", role: "roles/firebase.admin")
55
- system(
56
- "gcloud projects add-iam-policy-binding #{project_id} \
57
- --member='serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com' \
58
- --role=#{role}"
59
- )
60
- end
61
-
62
- def add_permissions(service_account: "souls-app", project_id: "souls-app")
63
- roles = [
64
- "roles/cloudsql.instanceUser",
65
- "roles/containerregistry.ServiceAgent",
66
- "roles/pubsub.serviceAdmin",
67
- "roles/firestore.serviceAdmin",
68
- "roles/iam.serviceAccountUser",
69
- "roles/storage.objectAdmin",
70
- "roles/run.admin"
71
- ]
72
- roles.each do |role|
73
- add_service_account_role(service_account: service_account, project_id: project_id, role: role)
74
- end
75
- end
5
+ module Iam
76
6
  end
77
7
  end
78
8
  end
@@ -0,0 +1,80 @@
1
+ module Souls
2
+ module Gcloud
3
+ module Iam
4
+ class << self
5
+ def create_service_account(service_account: "souls-app")
6
+ system(
7
+ "gcloud iam service-accounts create #{service_account} \
8
+ --description='Souls Service Account' \
9
+ --display-name=#{service_account}"
10
+ )
11
+ end
12
+
13
+ def create_service_account_key(service_account: "souls-app", project_id: "souls-app")
14
+ system(
15
+ "gcloud iam service-accounts keys create ./config/keyfile.json \
16
+ --iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com"
17
+ )
18
+ end
19
+
20
+ def export_key_to_console
21
+ github_repo = Souls.configuration.github_repo || "elsoul/souls"
22
+ file_path = "config/keyfile.json"
23
+ puts(Paint["======= below(ここから)=======", :cyan])
24
+ text = []
25
+ File.open(file_path, "r") do |line|
26
+ line.each_line do |l|
27
+ text << l
28
+ end
29
+ end
30
+ key = text.join(",").gsub(/^,/, "").chomp!
31
+ puts(Paint[key, :white])
32
+ puts(Paint["======= above(ここまで)=======", :cyan])
33
+ github_secret_url = "https://github.com/#{github_repo}/settings/secrets/actions"
34
+ souls_doc_url = "https://souls.elsoul.nl/docs/tutorial/zero-to-deploy/#43-github-シークレットキーの登録"
35
+ txt1 = <<~TEXT
36
+
37
+ ⬆⬆⬆ Copy the service account key above ⬆⬆⬆⬆
38
+
39
+ And
40
+
41
+ Go to %{yellow_text}
42
+
43
+ Reference: %{yellow_text2}
44
+ TEXT
45
+ puts(
46
+ Paint % [
47
+ txt1,
48
+ :white,
49
+ { yellow_text: [github_secret_url, :yellow], yellow_text2: [souls_doc_url, :yellow] }
50
+ ]
51
+ )
52
+ FileUtils.rm(file_path)
53
+ end
54
+
55
+ def add_service_account_role(service_account: "souls-app", project_id: "souls-app", role: "roles/firebase.admin")
56
+ system(
57
+ "gcloud projects add-iam-policy-binding #{project_id} \
58
+ --member='serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com' \
59
+ --role=#{role}"
60
+ )
61
+ end
62
+
63
+ def add_permissions(service_account: "souls-app", project_id: "souls-app")
64
+ roles = [
65
+ "roles/cloudsql.editor",
66
+ "roles/containerregistry.ServiceAgent",
67
+ "roles/pubsub.editor",
68
+ "roles/datastore.user",
69
+ "roles/iam.serviceAccountUser",
70
+ "roles/storage.objectAdmin",
71
+ "roles/run.admin"
72
+ ]
73
+ roles.each do |role|
74
+ add_service_account_role(service_account: service_account, project_id: project_id, role: role)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,33 +1,9 @@
1
+ require_relative "./pubsub/topics"
2
+ require_relative "./pubsub/subscriptions"
3
+
1
4
  module Souls
2
5
  module Gcloud
3
- class << self
4
- def create_pubsub_topic(topic_name: "send-user-mail")
5
- system("gcloud pubsub topics create #{topic_name}")
6
- end
7
-
8
- def create_pubsub_subscription(
9
- topic_name: "send-user-mail",
10
- project_id: "souls-app",
11
- service_account: "souls-app",
12
- endpoint: "https:://test.com"
13
- )
14
- system(
15
- "gcloud pubsub subscriptions create #{topic_name}-sub \
16
- --topic #{topic_name} \
17
- --topic-project #{project_id} \
18
- --push-auth-service-account #{service_account} \
19
- --push-endpoint #{endpoint} \
20
- --expiration-period never
21
- "
22
- )
23
- end
24
-
25
- def update_pubsub_subscription(
26
- topic_name: "send-user-mail",
27
- endpoint: "https:://test.com"
28
- )
29
- system("gcloud pubsub subscriptions update #{topic_name}-sub --push-endpoint #{endpoint} ")
30
- end
6
+ module Pubsub
31
7
  end
32
8
  end
33
9
  end
@@ -0,0 +1,31 @@
1
+ module Souls
2
+ module Gcloud
3
+ module Pubsub
4
+ class << self
5
+ def create_subscription(
6
+ topic_name: "send-user-mail",
7
+ project_id: "souls-app",
8
+ service_account: "souls-app",
9
+ endpoint: "https:://test.com"
10
+ )
11
+ system(
12
+ "gcloud pubsub subscriptions create #{topic_name}-sub \
13
+ --topic #{topic_name} \
14
+ --topic-project #{project_id} \
15
+ --push-auth-service-account #{service_account} \
16
+ --push-endpoint #{endpoint} \
17
+ --expiration-period never
18
+ "
19
+ )
20
+ end
21
+
22
+ def update_subscription(
23
+ topic_name: "send-user-mail",
24
+ endpoint: "https:://test.com"
25
+ )
26
+ system("gcloud pubsub subscriptions update #{topic_name}-sub --push-endpoint #{endpoint} ")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ module Souls
2
+ module Gcloud
3
+ module Pubsub
4
+ class << self
5
+ def create_topic(topic_name: "send-user-mail")
6
+ system("gcloud pubsub topics create #{topic_name}")
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,16 +1,9 @@
1
+ require_relative "./run/run"
2
+
1
3
  module Souls
2
4
  module Gcloud
3
- class << self
4
- def run_awake(app_name: "souls-app", url: "")
5
- system(
6
- "gcloud scheduler jobs create http #{app_name}-awake
7
- --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
8
- )
9
- end
10
-
11
- def run_list(project_id: "souls-app")
12
- system("gcloud run services list --project #{project_id}")
13
- end
5
+ module Run
14
6
  end
15
7
  end
16
8
  end
9
+
@@ -0,0 +1,18 @@
1
+ module Souls
2
+ module Gcloud
3
+ module Run
4
+ class << self
5
+ def awake(app_name: "souls-app", url: "")
6
+ system(
7
+ "gcloud scheduler jobs create http #{app_name}-awake
8
+ --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
9
+ )
10
+ end
11
+
12
+ def list(project_id: "souls-app")
13
+ system("gcloud run services list --project #{project_id}")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "./sql/sql"
2
+
3
+ module Souls
4
+ module Gcloud
5
+ module Sql
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,15 @@
1
+ module Souls
2
+ module Gcloud
3
+ module Sql
4
+ class << self
5
+ def create_instance(instance_name: "souls-db", root_pass: "Postgre123!", zone: "asia-northeast1-b")
6
+ system(
7
+ "gcloud sql instances create #{instance_name}
8
+ --database-version=POSTGRES_13 --cpu=2 --memory=7680MB --zone=#{zone}
9
+ --root-password='#{root_pass}' --database-flags cloudsql.iam_authentication=on"
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.31.1".freeze
2
+ VERSION = "0.32.3".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.10.1
1
+ 0.11.3
@@ -1 +1 @@
1
- 0.10.1
1
+ 0.11.3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.1
4
+ version: 0.32.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -129,11 +129,16 @@ files:
129
129
  - lib/souls/cli/docker.rb
130
130
  - lib/souls/cli/docker/docker.rb
131
131
  - lib/souls/cli/gcloud.rb
132
- - lib/souls/cli/gcloud/compute.rb
132
+ - lib/souls/cli/gcloud/gcloud.rb
133
133
  - lib/souls/cli/gcloud/iam.rb
134
- - lib/souls/cli/gcloud/methods.rb
134
+ - lib/souls/cli/gcloud/iam/iam.rb
135
135
  - lib/souls/cli/gcloud/pubsub.rb
136
+ - lib/souls/cli/gcloud/pubsub/subscriptions.rb
137
+ - lib/souls/cli/gcloud/pubsub/topics.rb
136
138
  - lib/souls/cli/gcloud/run.rb
139
+ - lib/souls/cli/gcloud/run/run.rb
140
+ - lib/souls/cli/gcloud/sql.rb
141
+ - lib/souls/cli/gcloud/sql/sql.rb
137
142
  - lib/souls/cli/release.rb
138
143
  - lib/souls/cli/release/release.rb
139
144
  - lib/souls/cli/sync.rb
@@ -1,69 +0,0 @@
1
- module Souls
2
- module Gcloud
3
- class << self
4
- def return_method(args)
5
- method = args[1]
6
- case method
7
- when "get_iam_key"
8
- app_name = Souls.configuration.app
9
- project_id = Souls.configuration.project_id
10
- Souls::Gcloud.create_service_account(service_account: app_name)
11
- Souls::Gcloud.create_service_account_key(service_account: app_name, project_id: project_id)
12
- Souls::Gcloud.export_key_to_console
13
- Souls::Gcloud.enable_permissions
14
- when "auth_login"
15
- project_id = Souls.configuration.project_id
16
- Souls::Gcloud.auth_login(project_id: project_id)
17
- when "enable_permissions"
18
- service_account = Souls.configuration.app
19
- project_id = Souls.configuration.project_id
20
- Souls::Gcloud.enable_permissions
21
- Souls::Gcloud.add_permissions(service_account: service_account, project_id: project_id)
22
- when "create_pubsub_topic"
23
- topic_name = args[2] || "send-user-mail"
24
- Souls::Gcloud.create_pubsub_topic(topic_name: topic_name)
25
- when "create_pubsub_subscription"
26
- project_id = Souls.configuration.project_id
27
- topic_name = args[2] || "send-user-mail"
28
- service_account = "#{Souls.configuration.app}@#{project_id}.iam.gserviceaccount.com"
29
- endpoint = Souls.configuration.worker_endpoint
30
- Souls::Gcloud.create_pubsub_subscription(
31
- topic_name: topic_name,
32
- project_id: project_id,
33
- service_account: service_account,
34
- endpoint: endpoint
35
- )
36
- when "create_sql_instance"
37
- instance_name = "#{Souls.configuration.app}-db"
38
- root_pass = args[2] || "password"
39
- zone = args[3] || "asia-northeast1-b"
40
- Souls::Gcloud.create_sql_instance(instance_name: instance_name, root_pass: root_pass, zone: zone)
41
- when "create_service_account"
42
- service_account = Souls.configuration.app
43
- Souls::Gcloud.create_service_account(service_account: service_account)
44
- when "create_service_account_key"
45
- service_account = Souls.configuration.app
46
- project_id = Souls.configuration.project_id
47
- Souls::Gcloud.create_service_account_key(service_account: service_account, project_id: project_id)
48
- when "add_service_account_role"
49
- service_account = Souls.configuration.app
50
- project_id = Souls.configuration.project_id
51
- role = args[2] || "roles/firebase.admin"
52
- Souls::Gcloud.add_service_account_role(service_account: service_account, project_id: project_id, role: role)
53
- when "add_permissions"
54
- service_account = Souls.configuration.app
55
- project_id = Souls.configuration.project_id
56
- Souls::Gcloud.add_permissions(service_account: service_account, project_id: project_id)
57
- when "run_list"
58
- project_id = Souls.configuration.project_id
59
- Souls::Gcloud.run_list(project_id: project_id)
60
- when "run_awake"
61
- app_name = Souls.configuration.app
62
- Souls::Gcloud.run_awake(app_name: app_name)
63
- else
64
- raise(StandardError, "Wrong Method!")
65
- end
66
- end
67
- end
68
- end
69
- end