souls 0.17.6 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbb549404b0a81f37dff81fc568f7d93b69f4ef23ac321fd6f7ed4602e1a1195
4
- data.tar.gz: 18b4d58e4969cb122387bb893d476fa3bf246a47a9ea31338adb95b80fea3b13
3
+ metadata.gz: ecd7bd535b9dd6f53563f18d66405389d21f1dca3e8dd9a34409d33ae19b52dc
4
+ data.tar.gz: 96d87720d10184363a3ba66f92e8abffa5a132c0540372e9fbfa02709eb5bf10
5
5
  SHA512:
6
- metadata.gz: a060e41c870266b1441285ebe87e5cf25aacea694299858ffdf1223aae0b880ca688735a8f8ec5957eae87c0ebf4358365a69673fb33d4379f25c9aa52cb9d2c
7
- data.tar.gz: 1fa8878a36982334b4244bd39e90da9010ca8e9a097bc33a75e49ce44360502e4bc6fe05a339cba30cd1ff5e6e6e4f7d7d29bbf769cf9a498579b9244ad0d760
6
+ metadata.gz: cd5baac0984a41f18edd23f9b98f333b37acb1ad32ce01c788cb8222a11b7059789f58e02b03f9c886fbf3d78776ea9953a9f9e57da4bb21161b62d3c96506b3
7
+ data.tar.gz: cb2d77c3915d11bb56fe357858468b2a559c05f206d4eb08cc15727f56d12d8b293861bd83a9443a82b1e2ae9d957c0694c5c18d3f2d0f5e9b1f493a9d1756ec
data/Gemfile CHANGED
@@ -4,7 +4,8 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "activesupport", "6.1.0"
7
+ gem "parser", "3.0.0"
7
8
  gem "rake", "13.0.3"
8
9
  gem "rspec", "3.1.0"
9
- gem "rubocop", "1.7.0"
10
- gem "steep", "0.39.0"
10
+ gem "rubocop", "1.12.1"
11
+ gem "steep", "0.43.1"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.17.5)
4
+ souls (0.17.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -13,30 +13,27 @@ GEM
13
13
  tzinfo (~> 2.0)
14
14
  zeitwerk (~> 2.3)
15
15
  ast (2.4.2)
16
- ast_utils (0.3.0)
17
- parser (~> 2.4)
18
- thor (>= 0.19)
19
16
  concurrent-ruby (1.1.8)
20
17
  diff-lcs (1.4.4)
21
- ffi (1.14.2)
22
- i18n (1.8.9)
18
+ ffi (1.15.0)
19
+ i18n (1.8.10)
23
20
  concurrent-ruby (~> 1.0)
24
- language_server-protocol (3.15.0.1)
25
- listen (3.4.1)
21
+ language_server-protocol (3.16.0.0)
22
+ listen (3.5.1)
26
23
  rb-fsevent (~> 0.10, >= 0.10.3)
27
24
  rb-inotify (~> 0.9, >= 0.9.10)
28
25
  minitest (5.14.4)
29
26
  parallel (1.20.1)
30
- parser (2.7.2.0)
27
+ parser (3.0.0.0)
31
28
  ast (~> 2.4.1)
32
29
  rainbow (3.0.0)
33
30
  rake (13.0.3)
34
31
  rb-fsevent (0.10.4)
35
32
  rb-inotify (0.10.1)
36
33
  ffi (~> 1.0)
37
- rbs (1.0.6)
34
+ rbs (1.1.1)
38
35
  regexp_parser (2.1.1)
39
- rexml (3.2.4)
36
+ rexml (3.2.5)
40
37
  rspec (3.1.0)
41
38
  rspec-core (~> 3.1.0)
42
39
  rspec-expectations (~> 3.1.0)
@@ -49,43 +46,45 @@ GEM
49
46
  rspec-mocks (3.1.3)
50
47
  rspec-support (~> 3.1.0)
51
48
  rspec-support (3.1.2)
52
- rubocop (1.7.0)
49
+ rubocop (1.12.1)
53
50
  parallel (~> 1.10)
54
- parser (>= 2.7.1.5)
51
+ parser (>= 3.0.0.0)
55
52
  rainbow (>= 2.2.2, < 4.0)
56
53
  regexp_parser (>= 1.8, < 3.0)
57
54
  rexml
58
55
  rubocop-ast (>= 1.2.0, < 2.0)
59
56
  ruby-progressbar (~> 1.7)
60
- unicode-display_width (>= 1.4.0, < 2.0)
57
+ unicode-display_width (>= 1.4.0, < 3.0)
61
58
  rubocop-ast (1.4.1)
62
59
  parser (>= 2.7.1.5)
63
60
  ruby-progressbar (1.11.0)
64
- steep (0.39.0)
61
+ steep (0.43.1)
65
62
  activesupport (>= 5.1)
66
- ast_utils (~> 0.3.0)
67
- language_server-protocol (~> 3.15.0.1)
63
+ language_server-protocol (>= 3.15, < 4.0)
68
64
  listen (~> 3.0)
69
- parser (~> 2.7.0)
65
+ parallel (>= 1.0.0)
66
+ parser (>= 2.7)
70
67
  rainbow (>= 2.2.2, < 4.0)
71
- rbs (~> 1.0.0)
72
- thor (1.1.0)
68
+ rbs (~> 1.1.0)
69
+ terminal-table (>= 2, < 4)
70
+ terminal-table (3.0.0)
71
+ unicode-display_width (~> 1.1, >= 1.1.1)
73
72
  tzinfo (2.0.4)
74
73
  concurrent-ruby (~> 1.0)
75
74
  unicode-display_width (1.7.0)
76
75
  zeitwerk (2.4.2)
77
76
 
78
77
  PLATFORMS
79
- x86_64-darwin-20
80
78
  x86_64-linux
81
79
 
82
80
  DEPENDENCIES
83
81
  activesupport (= 6.1.0)
82
+ parser (= 3.0.0)
84
83
  rake (= 13.0.3)
85
84
  rspec (= 3.1.0)
86
- rubocop (= 1.7.0)
85
+ rubocop (= 1.12.1)
87
86
  souls!
88
- steep (= 0.39.0)
87
+ steep (= 0.43.1)
89
88
 
90
89
  BUNDLED WITH
91
90
  2.2.14
data/LICENSE.txt CHANGED
@@ -52,7 +52,7 @@ You may add Your own copyright statement to Your modifications and may provide a
52
52
 
53
53
  END OF TERMS AND CONDITIONS
54
54
 
55
- Copyright 2020 ELSOUL LABO B.V.
55
+ Copyright 2021 ELSOUL LABO B.V.
56
56
 
57
57
  Licensed under the Apache License, Version 2.0 (the "License");
58
58
  you may not use this file except in compliance with the License.
data/config/souls.rb ADDED
@@ -0,0 +1,4 @@
1
+ Souls.configure do |config|
2
+ config.app = "souls"
3
+ config.strain = "api"
4
+ end
data/exe/souls CHANGED
@@ -1,29 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "souls"
3
-
3
+ STRAINS = ["graph", "worker", "media", "admin"]
4
+ begin
5
+ require "./config/souls" unless ARGV[0] == "new" || ARGV[0] == "i"
6
+ rescue
7
+ Souls::Init.config_init
8
+ end
4
9
  begin
5
- begin
6
- require "./config/initializers/souls" unless ARGV[0] == "new" || ARGV[0] == "init"
7
- rescue
8
- Souls::Init.config_init
9
- end
10
10
  case ARGV[0]
11
11
  when "new"
12
12
  if ARGV[1].nil?
13
13
  puts "you need to specify your app name \n `souls new app_name`"
14
14
  exit
15
15
  end
16
- puts "Which framework: \n 1. SOULs GraphQL API \n 2. SOULs GraphQL API gRPC compatible \n 3. SOULs gRPC Service \n 4. SOULs Media Web \n 5. SOULs Admin Web \n Enter Number: "
16
+ puts "Which framework: \n 1. SOULs GraphQL API \n 2. SOULs Worker \n 3. SOULs Media Web \n 4. SOULs Admin Web \n Enter Number: "
17
17
  strain = STDIN.gets.chomp.to_i
18
- (1..5).include?(strain) ? puts("Generating SOULs.. \n") : raise(StandardError, "Choose Number 1..5")
19
- Souls::Init.create_souls strain: strain, app_name: ARGV[1]
18
+ (1..4).include?(strain) ? puts("Generating SOULs.. \n") : raise(StandardError, "Choose Number 1..4")
19
+ Souls::Init.download_souls app_name: ARGV[1], repository_name: "souls_#{STRAINS[strain.to_i - 1]}"
20
+ Souls::Init.initial_config_init app_name: "souls", project: { strain: STRAINS[strain.to_i - 1] }
20
21
  when "s", "server"
21
22
  strain = Souls.configuration.strain
22
23
  case strain
23
24
  when "media", "admin"
24
25
  system "yarn dev"
25
- when "service"
26
- system "bundle exec rake run_server"
26
+ when "worker"
27
+ system "bundle exec puma -p 3000 -e development"
27
28
  else
28
29
  system "foreman start -f Procfile.dev"
29
30
  end
@@ -42,10 +43,6 @@ begin
42
43
  end
43
44
  when "i", "infra"
44
45
  Souls.send ARGV[1]
45
- when "p", "proto"
46
- Souls::Init.proto proto_package_name: "souls", service: ARGV[1]
47
- when "init"
48
- Souls::Init.config_init
49
46
  when "-v", "--version"
50
47
  puts Souls::VERSION
51
48
  when "add"
@@ -141,8 +138,7 @@ begin
141
138
  system "docker build . -t souls:latest"
142
139
  system "docker run --rm -p 3000:3000 souls:latest"
143
140
  when "deploy"
144
- project_id = Souls.configuration.project_id
145
- system "gcloud builds submit --config=cloudbuild.yml --project #{project_id}"
141
+ system "gcloud builds submit --config=cloudbuild.yml --project #{ARGV[1]}"
146
142
  else
147
143
  puts "Welcome to SOULs!"
148
144
  end
data/lib/souls.rb CHANGED
@@ -10,385 +10,20 @@ module Souls
10
10
  class << self
11
11
  attr_accessor :configuration
12
12
 
13
- def delete_forwarding_rule forwarding_rule_name: "grpc-gke-forwarding-rule"
14
- system "gcloud compute -q forwarding-rules delete #{forwarding_rule_name} --global"
15
- end
16
-
17
- def create_forwarding_rule forwarding_rule_name: "grpc-gke-forwarding-rule", proxy_name: "grpc-gke-proxy", port: 8000
18
- system "gcloud compute -q forwarding-rules create #{forwarding_rule_name} \
19
- --global \
20
- --load-balancing-scheme=INTERNAL_SELF_MANAGED \
21
- --address=0.0.0.0 \
22
- --target-grpc-proxy=#{proxy_name} \
23
- --ports #{port} \
24
- --network #{Souls.configuration.network}"
25
- end
26
-
27
- def delete_target_grpc_proxy proxy_name: "grpc-gke-proxy"
28
- system "gcloud compute -q target-grpc-proxies delete #{proxy_name}"
29
- end
30
-
31
- def create_target_grpc_proxy proxy_name: "grpc-gke-proxy", url_map_name: "grpc-gke-url-map"
32
- system "gcloud compute -q target-grpc-proxies create #{proxy_name} \
33
- --url-map #{url_map_name} \
34
- --validate-for-proxyless"
35
- end
36
-
37
- def create_path_matcher url_map_name: "grpc-gke-url-map", service_name: "grpc-gke-helloworld-service", path_matcher_name: "grpc-gke-path-matcher", hostname: "helloworld-gke", port: "8000"
38
- system "gcloud compute -q url-maps add-path-matcher #{url_map_name} \
39
- --default-service #{service_name} \
40
- --path-matcher-name #{path_matcher_name} \
41
- --new-hosts #{hostname}:#{port}"
42
- end
43
-
44
- def delete_url_map url_map_name: "grpc-gke-url-map"
45
- system "gcloud compute -q url-maps delete #{url_map_name}"
46
- end
47
-
48
- def create_url_map url_map_name: "grpc-gke-url-map", service_name: "grpc-gke-helloworld-service"
49
- system "gcloud compute -q url-maps create #{url_map_name} \
50
- --default-service #{service_name}"
51
- end
52
-
53
- def add_backend_service service_name: "grpc-gke-helloworld-service", zone: "us-central1-a", neg_name: ""
54
- system "gcloud compute -q backend-services add-backend #{service_name} \
55
- --global \
56
- --network-endpoint-group #{neg_name} \
57
- --network-endpoint-group-zone #{zone} \
58
- --balancing-mode RATE \
59
- --max-rate-per-endpoint 5"
60
- end
61
-
62
- def delete_backend_service service_name: "grpc-gke-helloworld-service"
63
- system "gcloud compute -q backend-services delete #{service_name} --global"
64
- end
65
-
66
- def create_backend_service service_name: "grpc-gke-helloworld-service", health_check_name: "grpc-gke-helloworld-hc"
67
- system "gcloud compute -q backend-services create #{service_name} \
68
- --global \
69
- --load-balancing-scheme=INTERNAL_SELF_MANAGED \
70
- --protocol=GRPC \
71
- --health-checks #{health_check_name}"
72
- end
73
-
74
- def delete_firewall_rule firewall_rule_name: "grpc-gke-allow-health-checks"
75
- system "gcloud compute -q firewall-rules delete #{firewall_rule_name}"
76
- end
77
-
78
- def create_firewall_rule firewall_rule_name: "grpc-gke-allow-health-checks"
79
- network = Souls.configuration.network
80
- system "gcloud compute -q firewall-rules create #{firewall_rule_name} \
81
- --network #{network} \
82
- --action allow \
83
- --direction INGRESS \
84
- --source-ranges 35.191.0.0/16,130.211.0.0/22 \
85
- --target-tags allow-health-checks \
86
- --rules tcp:50051"
87
- end
88
-
89
- def delete_health_check health_check_name: "grpc-gke-helloworld-hc"
90
- system "gcloud compute -q health-checks delete #{health_check_name}"
91
- end
92
-
93
- def create_health_check health_check_name: "grpc-gke-helloworld-hc"
94
- system "gcloud compute -q health-checks create grpc #{health_check_name} --use-serving-port"
95
- end
96
-
97
- def create_network
98
- return "Error: Please Set Souls.configuration" if Souls.configuration.nil?
99
- network = Souls.configuration.network
100
- system "gcloud compute networks create #{network}"
101
- end
102
-
103
- def create_firewall_tcp ip_range:
104
- network = Souls.configuration.network
105
- `gcloud compute firewall-rules create #{network} --network #{network} --allow tcp,udp,icmp --source-ranges #{ip_range}`
106
- end
107
-
108
- def create_firewall_ssh
109
- network = Souls.configuration.network
110
- `gcloud compute firewall-rules create #{network}-ssh --network #{network} --allow tcp:22,tcp:3389,icmp`
111
- end
112
-
113
- def get_network_group_list
114
- system "gcloud compute network-endpoint-groups list"
115
- end
116
-
117
- def create_network_group
118
- app = Souls.configuration.app
119
- network = Souls.configuration.network
120
- sub_network = Souls.configuration.network
121
- system(
122
- "gcloud compute network-endpoint-groups create #{app} \
123
- --default-port=0 \
124
- --network #{network} \
125
- --subnet #{sub_network} \
126
- --global"
127
- )
128
- end
129
-
130
- def export_network_group
131
- app = Souls.configuration.app
132
- system "NEG_NAME=$(gcloud compute network-endpoint-groups list | grep #{app} | awk '{print $1}')"
133
- `echo $NEG_NAME > ./config/neg_name`
134
- end
135
-
136
- def delete_network_group_list neg_name:
137
- zone = Souls.configuration.zone
138
- system "gcloud compute network-endpoint-groups delete #{neg_name} --zone #{zone} -q"
139
- end
140
-
141
- def delete_cluster
142
- app = Souls.configuration.app
143
- zone = Souls.configuration.zone
144
- system "gcloud container clusters delete #{app} --zone #{zone} -q"
145
- end
146
-
147
- def config_set_main
148
- project_id = Souls.configuration.main_project_id
149
- system "gcloud config set project #{project_id}"
150
- end
151
-
152
- def config_set
153
- project_id = Souls.configuration.project_id
154
- system "gcloud config set project #{project_id}"
155
- end
156
-
157
- def create_cluster
158
- app = Souls.configuration.app
159
- network = Souls.configuration.network
160
- sub_network = Souls.configuration.network
161
- machine_type = Souls.configuration.machine_type
162
- zone = Souls.configuration.zone
163
- system(
164
- "gcloud container clusters create #{app} \
165
- --network #{network} \
166
- --subnetwork #{sub_network} \
167
- --zone #{zone} \
168
- --scopes=https://www.googleapis.com/auth/cloud-platform \
169
- --machine-type #{machine_type} \
170
- --enable-autorepair \
171
- --enable-ip-alias \
172
- --num-nodes 2 \
173
- --enable-autoscaling \
174
- --min-nodes 1 \
175
- --max-nodes 4 \
176
- --tags=allow-health-checks"
177
- )
178
- end
179
-
180
- def deploy
181
- strain = Souls.configuration.strain
182
- case strain
183
- when "api"
184
- Souls::Init.api_deploy
185
- when "service"
186
- Souls::Init.service_deploy
187
- else
188
- puts "coming soon..."
189
- end
190
- end
191
-
192
- def update
193
- `souls i apply_deployment`
194
- end
195
-
196
- def resize_cluster pool_name: "default-pool", node_num: 1
197
- app = Souls.configuration.app
198
- zone = Souls.configuration.zone
199
- system "gcloud container clusters resize #{app} --node-pool #{pool_name} --num-nodes #{node_num} --zone #{zone}"
200
- end
201
-
202
- def create_namespace
203
- namespace = Souls.configuration.namespace
204
- system("kubectl create namespace #{namespace}")
205
- end
206
-
207
- def create_ip
208
- ip_name = "#{Souls.configuration.app}-ip"
209
- system("gcloud compute addresses create #{ip_name} --global")
210
- end
211
-
212
- def apply_deployment
213
- namespace = Souls.configuration.namespace
214
- system("kubectl apply -f ./infra/deployment.yml --namespace=#{namespace}")
215
- end
216
-
217
- def apply_secret
218
- namespace = Souls.configuration.namespace
219
- system("kubectl apply -f ./infra/secret.yml --namespace=#{namespace}")
220
- end
221
-
222
- def apply_service
223
- namespace = Souls.configuration.namespace
224
- system("kubectl apply -f ./infra/service.yml --namespace=#{namespace}")
225
- end
226
-
227
- def apply_ingress
228
- namespace = Souls.configuration.namespace
229
- system("kubectl apply -f ./infra/ingress.yml --namespace=#{namespace}")
230
- end
231
-
232
- def delete_deployment
233
- namespace = Souls.configuration.namespace
234
- system("kubectl delete -f ./infra/deployment.yml --namespace=#{namespace}")
235
- end
236
-
237
- def delete_secret
238
- namespace = Souls.configuration.namespace
239
- system("kubectl delete -f ./infra/secret.yml --namespace=#{namespace}")
240
- end
241
-
242
- def delete_service
243
- namespace = Souls.configuration.namespace
244
- system("kubectl delete -f ./infra/service.yml --namespace=#{namespace}")
245
- end
246
-
247
- def delete_ingress
248
- namespace = Souls.configuration.namespace
249
- system("kubectl delete -f ./infra/ingress.yml --namespace=#{namespace}")
250
- end
251
-
252
- def create_dns_conf
253
- app = Souls.configuration.app
254
- namespace = Souls.configuration.namespace
255
- domain = Souls.configuration.domain
256
- `echo "#{domain}. 300 IN A $(kubectl get ingress --namespace #{namespace} | grep #{app} | awk '{print $3}')" >> ./infra/dns_conf`
257
- "created dns file!"
258
- end
259
-
260
- def set_dns
261
- project_id = Souls.configuration.main_project_id
262
- `gcloud dns record-sets import -z=#{project_id} --zone-file-format ./infra/dns_conf`
263
- end
264
-
265
- def service_api_enable
266
- `gcloud services enable iam.googleapis.com`
267
- `gcloud services enable dns.googleapis.com`
268
- `gcloud services enable container.googleapis.com`
269
- `gcloud services enable containerregistry.googleapis.com`
270
- `gcloud services enable servicenetworking.googleapis.com`
271
- `gcloud services enable sqladmin.googleapis.com`
272
- `gcloud services enable sql-component.googleapis.com`
273
- `gcloud services enable cloudbuild.googleapis.com`
274
- end
275
-
276
- def update_container zone: :asia
277
- project_id = Souls.configuration.project_id
278
- firestore = Google::Cloud::Firestore.new
279
- strain = Souls.configuration.strain
280
- app = Souls.configuration.app
281
- container = case strain
282
- when "api"
283
- app
284
- else
285
- Souls.configuration.service_name
286
- end
287
- zones = {
288
- us: "gcr.io",
289
- eu: "eu.gcr.io",
290
- asia: "asia.gcr.io"
291
- }
292
- versions = firestore.doc "containers/#{container}/versions/1"
293
- if versions.get.exists?
294
- versions = firestore.col("containers").doc(container).col("versions")
295
- query = versions.order("version_counter", "desc").limit 1
296
- query.get do |v|
297
- @next_version = v.data[:version_counter] + 1
298
- end
299
- else
300
- @next_version = 1
301
- end
302
- version = firestore.col("containers").doc(container).col("versions").doc @next_version
303
- version.set version: "v#{@next_version}", version_counter: @next_version, zone: zones[zone], created_at: Time.now.utc
304
-
305
- system("docker build . -t #{app}:v#{@next_version}")
306
- system("docker tag #{app}:v#{@next_version} #{zones[zone]}/#{project_id}/#{app}:v#{@next_version}")
307
- system("docker push #{zones[zone]}/#{project_id}/#{app}:v#{@next_version}")
308
- end
309
-
310
- def create_service_account
311
- service_account = Souls.configuration.app
312
- `gcloud iam service-accounts create #{service_account} \
313
- --description="Souls Service Account" \
314
- --display-name="#{service_account}"`
315
- end
316
-
317
- def create_service_account_key
318
- project_id = Souls.configuration.project_id
319
- service_account = Souls.configuration.app
320
- `gcloud iam service-accounts keys create ./config/keyfile.json \
321
- --iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com`
322
- end
323
-
324
- def add_service_account_role role: "roles/firebase.admin"
325
- project_id = Souls.configuration.project_id
326
- service_account = Souls.configuration.app
327
- `gcloud projects add-iam-policy-binding #{project_id} \
328
- --member="serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com" \
329
- --role="#{role}"`
330
- end
331
-
332
- def get_pods
333
- namespace = Souls.configuration.namespace
334
- system("kubectl get pods --namespace=#{namespace}")
335
- end
336
-
337
- def get_svc
338
- namespace = Souls.configuration.namespace
339
- system("kubectl get svc --namespace=#{namespace}")
340
- end
341
-
342
- def get_ingress
343
- namespace = Souls.configuration.namespace
344
- system("kubectl get ingress --namespace=#{namespace}")
345
- end
346
-
347
- def run
348
- app = Souls.configuration.app
349
- system("docker rm -f web")
350
- system("docker build . -t #{app}:latest")
351
- system("docker run --name web -it --env-file $PWD/.env -p 3000:3000 #{app}:latest")
352
- end
353
-
354
- def get_clusters
355
- system("kubectl config get-clusters")
356
- end
357
-
358
- def get_current_cluster
359
- system("kubectl config current-context")
360
- end
361
-
362
- def use_context cluster:
363
- system("kubectl config use-context #{cluster}")
364
- end
365
-
366
- def get_credentials
367
- app = Souls.configuration.app
368
- zone = Souls.configuration.zone
369
- system "gcloud container clusters get-credentials #{app} --zone #{zone}"
370
- end
371
-
372
- def create_ssl
373
- app = Souls.configuration.app
374
- domain = Souls.configuration.domain
375
- system "gcloud compute ssl-certificates create #{app}-ssl --domains=#{domain} --global"
376
- end
377
-
378
13
  def run_psql
379
- `docker run --rm -d \
14
+ system "docker run --rm -d \
380
15
  -p 5433:5432 \
381
16
  -v postgres-tmp:/var/lib/postgresql/data \
382
17
  -e POSTGRES_USER=postgres \
383
18
  -e POSTGRES_PASSWORD=postgres \
384
19
  -e POSTGRES_DB=souls_test \
385
- postgres:13-alpine`
386
- puts `docker ps`
20
+ postgres:13-alpine"
21
+ system "docker ps"
387
22
  end
388
23
 
389
- def run_awake
24
+ def run_awake url
390
25
  app = Souls.configuration.app
391
- `gcloud scheduler jobs create http #{app}-awake --schedule "0,10,20,30,40,50 * * * *" --uri "https://#{app}.el-soul.com" --http-method GET`
26
+ system "gcloud scheduler jobs create http #{app}-awake --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
392
27
  end
393
28
 
394
29
  def deploy_local
@@ -434,21 +69,10 @@ module Souls
434
69
  end
435
70
 
436
71
  class Configuration
437
- attr_accessor :main_project_id, :project_id, :app, :network, :namespace, :service_name, :machine_type, :zone, :domain, :google_application_credentials, :strain, :proto_package_name
72
+ attr_accessor :app
438
73
 
439
74
  def initialize
440
- @main_project_id = nil
441
- @project_id = nil
442
75
  @app = nil
443
- @network = nil
444
- @namespace = nil
445
- @service_name = nil
446
- @machine_type = nil
447
- @zone = nil
448
- @domain = nil
449
- @google_application_credentials = nil
450
- @strain = nil
451
- @proto_package_name = nil
452
76
  end
453
77
  end
454
78
  end
@@ -20,9 +20,9 @@ module Souls
20
20
  end
21
21
 
22
22
  def policy class_name: "souls"
23
- dir_name = "./app/policy"
23
+ dir_name = "./app/policies"
24
24
  FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
25
- file_path = "./app/policy/#{class_name.singularize}_policy.rb"
25
+ file_path = "./app/policies/#{class_name.singularize}_policy.rb"
26
26
  File.open(file_path, "w") do |f|
27
27
  f.write <<~EOS
28
28
  class #{class_name.camelize}Policy < ApplicationPolicy
data/lib/souls/init.rb CHANGED
@@ -1,117 +1,33 @@
1
1
  module Souls
2
- STRAINS = ["graph", "api", "service", "media", "admin"]
3
2
  module Init
4
3
  class << self
5
- def create_souls strain: 1, app_name: "souls"
6
- config_needed = (1..3)
7
- project = {}
8
- project[:strain] = STRAINS[strain.to_i - 1]
9
- begin
10
- puts "Google Cloud Main PROJECT_ID(This project will controll Cloud DNS): (default: elsoul2)"
11
- project[:main_project_id] = STDIN.gets.chomp
12
- project[:main_project_id] == "" ? project[:main_project_id] = "elsoul2" : true
13
- puts "Google Cloud PROJECT_ID: (default: elsoul2)"
14
- project[:project_id] = STDIN.gets.chomp
15
- project[:project_id] = "elsoul2" if project[:project_id] == ""
16
- puts "VPC Network Name: (default: default)"
17
- project[:network] = STDIN.gets.chomp
18
- project[:network] == "" ? project[:network] = "default" : true
19
- puts "Namespace: (default: souls)"
20
- project[:namespace] = STDIN.gets.chomp
21
- project[:namespace] == "" ? project[:namespace] = "souls" : true
22
- if project[:strain] == "service"
23
- puts "Service Name: (default: blog-service)"
24
- project[:service_name] = STDIN.gets.chomp
25
- project[:service_name] == "" ? project[:service_name] = "blog-service" : true
26
- end
27
- puts "Instance MachineType: (default: custom-1-6656)"
28
- project[:machine_type] = STDIN.gets.chomp
29
- project[:machine_type] == "" ? project[:machine_type] = "custom-1-6656" : true
30
- puts "Zone: (default: us-central1-a)"
31
- project[:zone] = STDIN.gets.chomp
32
- project[:zone] == "" ? project[:zone] = "us-central1-a" : true
33
- puts "Domain: (e.g API: el-soul.com, Serive: xds:///blog-service:8000)"
34
- project[:domain] = STDIN.gets.chomp
35
- project[:domain] == "" ? project[:domain] = "el-soul.com" : true
36
- puts "Google Application Credentials Path: (default: #{app_name}/config/credentials.json)"
37
- project[:google_application_credentials] = STDIN.gets.chomp
38
- project[:google_application_credentials] == "" ? project[:google_application_credentials] = "./config/credentials.json" : true
39
- puts project
40
- puts "Enter to finish set up!"
41
- confirm = STDIN.gets.chomp
42
- raise StandardError, "Retry" unless confirm == ""
43
- download_souls app_name: app_name, repository_name: "souls_#{STRAINS[strain.to_i - 1]}"
44
- initial_config_init app_name: app_name, project: project if config_needed.include?(strain)
45
- rescue StandardError => error
46
- puts error
47
- retry
48
- end
4
+ def get_version repository_name: "souls_service"
5
+ data = JSON.parse `curl \
6
+ -H "Accept: application/vnd.github.v3+json" \
7
+ -s https://api.github.com/repos/elsoul/#{repository_name}/releases`
8
+ data[0]["tag_name"]
49
9
  end
50
10
 
51
11
  def initial_config_init app_name: "souls", project: {}
52
- `touch "#{app_name}/config/initializers/souls.rb"`
53
- file_path = "#{app_name}/config/initializers/souls.rb"
12
+ `touch "#{app_name}/config/souls.rb"`
13
+ file_path = "#{app_name}/config/souls.rb"
54
14
  File.open(file_path, "w") do |f|
55
15
  f.write <<~EOS
56
16
  Souls.configure do |config|
57
- config.main_project_id = "#{project[:main_project_id]}"
58
- config.project_id = "#{project[:project_id]}"
59
17
  config.app = "#{app_name}"
60
- config.namespace = "#{project[:namespace]}"
61
- config.service_name = "#{project[:service_name]}"
62
- config.network = "#{project[:network]}"
63
- config.machine_type = "#{project[:machine_type]}"
64
- config.zone = "#{project[:zone]}"
65
- config.domain = "#{project[:domain]}"
66
- config.google_application_credentials = "#{project[:google_application_credentials]}"
67
18
  config.strain = "#{project[:strain]}"
68
- config.proto_package_name = "souls"
69
19
  end
70
20
  EOS
71
21
  end
72
22
  end
73
23
 
74
- def config_init app_name: "souls", project: {}
75
- `touch ./config/initializers/souls.rb`
76
- file_path = "./config/initializers/souls.rb"
77
- puts "Generating souls conf..."
78
- sleep(rand(0.1..0.3))
79
- puts "Generated!"
80
- puts "Let's Edit SOULs Conf: `#{file_path}`"
81
- File.open(file_path, "w") do |f|
82
- f.write <<~EOS
83
- Souls.configure do |config|
84
- config.main_project_id = "#{project[:main_project_id]}"
85
- config.project_id = "#{project[:project_id]}"
86
- config.app = "#{app_name}"
87
- config.namespace = "#{project[:namespace]}"
88
- config.service_name = "#{project[:service_name]}"
89
- config.network = "#{project[:network]}"
90
- config.machine_type = "#{project[:machine_type]}"
91
- config.zone = "#{project[:zone]}"
92
- config.domain = "#{project[:domain]}"
93
- config.google_application_credentials = "#{project[:google_application_credentials]}"
94
- config.strain = "#{project[:strain]}"
95
- config.proto_package_name = "souls"
96
- end
97
- EOS
98
- end
99
- end
100
-
101
- def get_version repository_name: "souls_service"
102
- data = JSON.parse `curl \
103
- -H "Accept: application/vnd.github.v3+json" \
104
- -s https://api.github.com/repos/elsoul/#{repository_name}/releases`
105
- data[0]["tag_name"]
106
- end
107
-
108
24
  def download_souls app_name: "souls", repository_name: "souls_service"
109
25
  version = get_version repository_name: repository_name
110
26
  system "curl -OL https://github.com/elsoul/#{repository_name}/archive/#{version}.tar.gz"
111
27
  system "tar -zxvf ./#{version}.tar.gz"
112
28
  system "mkdir #{app_name}"
113
29
  folder = version.delete "v"
114
- system "cp -r #{repository_name}-#{folder}/ #{app_name}/"
30
+ system "cp -r #{repository_name}-#{folder}/* #{app_name}/"
115
31
  system "rm -rf #{version}.tar.gz && rm -rf #{repository_name}-#{folder}"
116
32
  txt = <<~TEXT
117
33
  _____ ____ __ ____#{' '}
@@ -129,119 +45,6 @@ module Souls
129
45
  puts "------------------------------"
130
46
  end
131
47
 
132
- def proto proto_package_name: "souls", service: "blog"
133
- system "grpc_tools_ruby_protoc -I ./protos --ruby_out=./app/services --grpc_out=./app/services ./protos/#{service}.proto"
134
- service_pb_path = "./app/services/#{service}_services_pb.rb"
135
- new_file = "./app/services/#{proto_package_name}.rb"
136
- File.open(new_file, "w") do |new_line|
137
- File.open(service_pb_path, "r") do |f|
138
- f.each_line.with_index do |line, i|
139
- case i
140
- when 0
141
- new_line.write "# Generated by the SOULs protocol buffer compiler. DO NOT EDIT!\n"
142
- when 3
143
- next
144
- else
145
- puts "#{i}: #{line}"
146
- new_line.write line.to_s
147
- end
148
- end
149
- end
150
- end
151
- FileUtils.rm service_pb_path
152
- puts "SOULs Proto Created!"
153
- end
154
-
155
- def service_deploy
156
- service_name = Souls.configuration.service_name
157
- health_check_name = "#{service_name}-hc"
158
- firewall_rule_name = "#{service_name}-allow-health-checks"
159
- zone = Souls.configuration.zone
160
- url_map_name = "#{service_name}-url-map"
161
- path_matcher_name = "#{service_name}-path-mathcher"
162
- port = "5000"
163
- proxy_name = "#{service_name}-proxy"
164
- forwarding_rule_name = "#{service_name}-forwarding-rule"
165
-
166
- Souls.create_service_account
167
- Souls.create_service_account_key
168
- Souls.add_service_account_role
169
- Souls.add_service_account_role role: "roles/containerregistry.ServiceAgent"
170
- Souls.create_health_check health_check_name: health_check_name
171
- Souls.create_firewall_rule firewall_rule_name: firewall_rule_name
172
- Souls.create_backend_service service_name: service_name, health_check_name: health_check_name
173
- Souls.export_network_group
174
- file_path = "./config/neg_name"
175
- File.open(file_path) do |f|
176
- Souls.add_backend_service service_name: service_name, neg_name: f.gets.to_s, zone: zone
177
- end
178
- Souls.create_url_map url_map_name: url_map_name, service_name: service_name
179
- Souls.create_path_matcher url_map_name: url_map_name, service_name: service_name, path_matcher_name: path_matcher_name, hostname: app, port: port
180
- Souls.create_target_grpc_proxy proxy_name: proxy_name, url_map_name: url_map_name
181
- Souls.create_forwarding_rule forwarding_rule_name: forwarding_rule_name, proxy_name: proxy_name, port: port
182
- end
183
-
184
- def api_deploy
185
- Souls.service_api_enable
186
- Souls.create_service_account
187
- Souls.create_service_account_key
188
- Souls.add_service_account_role
189
- Souls.add_service_account_role role: "roles/containerregistry.ServiceAgent"
190
- Souls.config_set
191
- Souls.create_network
192
- Souls.create_cluster
193
- Souls.get_credentials
194
- Souls.create_namespace
195
- Souls.create_ip
196
- Souls.create_ssl
197
- Souls.apply_deployment
198
- Souls.apply_service
199
- Souls.apply_ingress
200
- puts "Wainting for Ingress to get IP..."
201
- sleep 1
202
- puts "This migth take a few mins..."
203
- sleep 90
204
- Souls.create_dns_conf
205
- Souls.config_set_main
206
- Souls.set_dns
207
- Souls.config_set
208
- end
209
-
210
- def local_deploy
211
- `souls i run_psql`
212
- `docker pull`
213
- end
214
-
215
- def service_update
216
- `souls i apply_deployment`
217
- end
218
-
219
- def api_update
220
- `souls i apply_deployment`
221
- end
222
-
223
- def service_delete
224
- service_name = Souls.configuration.service_name
225
- firewall_rule_name = "#{service_name}-allow-health-checks"
226
- url_map_name = "#{service_name}-url-map"
227
- proxy_name = "#{service_name}-proxy"
228
- forwarding_rule_name = "#{service_name}-forwarding-rule"
229
-
230
- Souls.delete_forwarding_rule forwarding_rule_name: forwarding_rule_name
231
- Souls.delete_target_grpc_proxy proxy_name: proxy_name
232
- Souls.delete_url_map url_map_name: url_map_name
233
- Souls.delete_backend_service service_name: service_name
234
- Souls.delete_health_check health_check_name: health_check_name
235
- Souls.delete_firewall_rule firewall_rule_name: firewall_rule_name
236
- end
237
-
238
- def api_delete
239
- `souls i delete_deployment`
240
- `souls i delete_secret`
241
- `souls i delete_service`
242
- `souls i delete_ingress`
243
- end
244
-
245
48
  def model class_name: "souls"
246
49
  file_path = "./app/models/#{class_name.singularize}.rb"
247
50
  return ["Model already exist! #{file_path}"] if File.exist? file_path
data/lib/souls/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.17.6"
2
+ VERSION = "0.18.1"
3
3
  end
data/souls.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
4
4
  spec.name = "souls"
5
5
  spec.version = Souls::VERSION
6
6
  spec.authors = ["POPPIN-FUMI", "KishiTheMechanic", "James Neve"]
7
- spec.email = ["fumitake.kawasaki@el-soul.com", "shota.kishi@el-soul.com", "jamesoneve@gmail.com"]
7
+ spec.email = ["f.kawasaki@elsoul.nl", "s.kishi@elsoul.nl", "jamesoneve@gmail.com"]
8
8
 
9
9
  spec.summary = "SOULS is a GraphQL Based Web Application Framework for Microservices on Multi Cloud Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud. Auto deploy with scalable condition. You can focus on business logic. No more infra problems."
10
10
  spec.description = "SOULS is a Web Application Framework for Microservices on Multi Cloud Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud. Auto deploy with scalable condition. You can focus on business logic. No more infra problems."
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.17.6
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -10,15 +10,15 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-04-02 00:00:00.000000000 Z
13
+ date: 2021-04-07 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: SOULS is a Web Application Framework for Microservices on Multi Cloud
16
16
  Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud.
17
17
  Auto deploy with scalable condition. You can focus on business logic. No more infra
18
18
  problems.
19
19
  email:
20
- - fumitake.kawasaki@el-soul.com
21
- - shota.kishi@el-soul.com
20
+ - f.kawasaki@elsoul.nl
21
+ - s.kishi@elsoul.nl
22
22
  - jamesoneve@gmail.com
23
23
  executables:
24
24
  - souls
@@ -40,7 +40,7 @@ files:
40
40
  - Steepfile
41
41
  - bin/console
42
42
  - bin/setup
43
- - config/initializers/souls.rb
43
+ - config/souls.rb
44
44
  - exe/souls
45
45
  - lib/souls.rb
46
46
  - lib/souls/generate.rb
@@ -1,14 +0,0 @@
1
- Souls.configure do |config|
2
- config.main_project_id = ""
3
- config.project_id = ""
4
- config.app = "souls"
5
- config.namespace = ""
6
- config.service_name = ""
7
- config.network = ""
8
- config.machine_type = ""
9
- config.zone = ""
10
- config.domain = ""
11
- config.google_application_credentials = ""
12
- config.strain = ""
13
- config.proto_package_name = "souls"
14
- end