souls 0.17.4 → 0.17.9

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: 3d75356f72b972890fc8381fc9b0bafeb5785fb8d6dcc7a6d7e20b4c2e6bba27
4
- data.tar.gz: 2f91cc0387b40bb24f2cbc4ce95d9c8c60c51f32683472957b56d69ee942b111
3
+ metadata.gz: 163a0612fcb59636db008669eb27569e63fe1e4a3701fc211ae5ff92690be49e
4
+ data.tar.gz: 3850ab3b22daedd286886373963807e46af14040d7a021d6dedb9968801c40e0
5
5
  SHA512:
6
- metadata.gz: f77af6d106b7d7fe8ea44d79902712e8f4121b98f3a15dff038fda23d54f518866485be26d8ff3455786386bd7cab4c47b0ffcf5825764656b660dc754f9f79d
7
- data.tar.gz: dfc7a4779c8fc36341a56dc52facc8ad3c5274575aa176270d32d76d78e598552178ce4c5c17e90bd2f69b08860468f33639c07f4de0140ea5545b71b556e950
6
+ metadata.gz: dd2cb7901bc22a359f6cced93fafe7f28ee4f978ab798c85eb8d39365270e8fb34bd193efb7614f3a6f550c3c062e9d2740ab8e70a51cc8b821c6b21af999baa
7
+ data.tar.gz: 1307838fc825c08cfc91b0f72bf4b28d0742c3c2594f4e3a7c07bd1e48058c323fe721c509cf9c1ca4657f4033e40ce100ca3ad123656fd94561ba175e3b7abf
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.16.7)
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,42 +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
78
+ x86_64-linux
80
79
 
81
80
  DEPENDENCIES
82
81
  activesupport (= 6.1.0)
82
+ parser (= 3.0.0)
83
83
  rake (= 13.0.3)
84
84
  rspec (= 3.1.0)
85
- rubocop (= 1.7.0)
85
+ rubocop (= 1.12.1)
86
86
  souls!
87
- steep (= 0.39.0)
87
+ steep (= 0.43.1)
88
88
 
89
89
  BUNDLED WITH
90
- 2.2.11
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/Steepfile CHANGED
@@ -5,5 +5,4 @@ target :app do
5
5
 
6
6
  # check 'app'
7
7
  check "rbs"
8
-
9
8
  end
data/exe/souls CHANGED
@@ -1,29 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "souls"
3
-
3
+ STRAINS = ["graph", "worker", "media", "admin"]
4
4
  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
5
  case ARGV[0]
11
6
  when "new"
12
7
  if ARGV[1].nil?
13
8
  puts "you need to specify your app name \n `souls new app_name`"
14
9
  exit
15
10
  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: "
11
+ 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
12
  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]
13
+ (1..4).include?(strain) ? puts("Generating SOULs.. \n") : raise(StandardError, "Choose Number 1..4")
14
+ Souls::Init.download_souls app_name: ARGV[1], repository_name: "souls_#{STRAINS[strain.to_i - 1]}"
20
15
  when "s", "server"
21
16
  strain = Souls.configuration.strain
22
17
  case strain
23
18
  when "media", "admin"
24
19
  system "yarn dev"
25
- when "service"
26
- system "bundle exec rake run_server"
20
+ when "worker"
21
+ system "bundle exec puma -p 3000 -e development"
27
22
  else
28
23
  system "foreman start -f Procfile.dev"
29
24
  end
@@ -42,8 +37,6 @@ begin
42
37
  end
43
38
  when "i", "infra"
44
39
  Souls.send ARGV[1]
45
- when "p", "proto"
46
- Souls::Init.proto proto_package_name: "souls", service: ARGV[1]
47
40
  when "init"
48
41
  Souls::Init.config_init
49
42
  when "-v", "--version"
@@ -69,6 +62,8 @@ begin
69
62
  Souls::Init.test_dir
70
63
  when "policy"
71
64
  Souls::Init.policy class_name: ARGV[2]
65
+ when "rspec_policy"
66
+ Souls::Init.rspec_policy class_name: ARGV[2]
72
67
  when "node_type"
73
68
  Souls::Init.node_type class_name: ARGV[2]
74
69
  when "resolver"
@@ -139,8 +134,7 @@ begin
139
134
  system "docker build . -t souls:latest"
140
135
  system "docker run --rm -p 3000:3000 souls:latest"
141
136
  when "deploy"
142
- project_id = Souls.configuration.project_id
143
- system "gcloud builds submit --config=cloudbuild.yml --project #{project_id}"
137
+ system "gcloud builds submit --config=cloudbuild.yml --project #{ARGV[1]}"
144
138
  else
145
139
  puts "Welcome to SOULs!"
146
140
  end
data/lib/souls.rb CHANGED
@@ -10,367 +10,6 @@ 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("gcloud compute network-endpoint-groups create #{app} \
122
- --default-port=0 \
123
- --network #{network} \
124
- --subnet #{sub_network} \
125
- --global")
126
- end
127
-
128
- def export_network_group
129
- app = Souls.configuration.app
130
- system "NEG_NAME=$(gcloud compute network-endpoint-groups list | grep #{app} | awk '{print $1}')"
131
- `echo $NEG_NAME > ./config/neg_name`
132
- end
133
-
134
- def delete_network_group_list neg_name:
135
- zone = Souls.configuration.zone
136
- system "gcloud compute network-endpoint-groups delete #{neg_name} --zone #{zone} -q"
137
- end
138
-
139
- def delete_cluster
140
- app = Souls.configuration.app
141
- zone = Souls.configuration.zone
142
- system "gcloud container clusters delete #{app} --zone #{zone} -q"
143
- end
144
-
145
- def config_set_main
146
- project_id = Souls.configuration.main_project_id
147
- system "gcloud config set project #{project_id}"
148
- end
149
-
150
- def config_set
151
- project_id = Souls.configuration.project_id
152
- system "gcloud config set project #{project_id}"
153
- end
154
-
155
- def create_cluster
156
- app = Souls.configuration.app
157
- network = Souls.configuration.network
158
- sub_network = Souls.configuration.network
159
- machine_type = Souls.configuration.machine_type
160
- zone = Souls.configuration.zone
161
- system("gcloud container clusters create #{app} \
162
- --network #{network} \
163
- --subnetwork #{sub_network} \
164
- --zone #{zone} \
165
- --scopes=https://www.googleapis.com/auth/cloud-platform \
166
- --machine-type #{machine_type} \
167
- --enable-autorepair \
168
- --enable-ip-alias \
169
- --num-nodes 2 \
170
- --enable-autoscaling \
171
- --min-nodes 1 \
172
- --max-nodes 4 \
173
- --tags=allow-health-checks")
174
- end
175
-
176
- def deploy
177
- strain = Souls.configuration.strain
178
- case strain
179
- when "api"
180
- Souls::Init.api_deploy
181
- when "service"
182
- Souls::Init.service_deploy
183
- else
184
- puts "coming soon..."
185
- end
186
- end
187
-
188
- def update
189
- `souls i apply_deployment`
190
- end
191
-
192
- def resize_cluster pool_name: "default-pool", node_num: 1
193
- app = Souls.configuration.app
194
- zone = Souls.configuration.zone
195
- system "gcloud container clusters resize #{app} --node-pool #{pool_name} --num-nodes #{node_num} --zone #{zone}"
196
- end
197
-
198
- def create_namespace
199
- namespace = Souls.configuration.namespace
200
- system("kubectl create namespace #{namespace}")
201
- end
202
-
203
- def create_ip
204
- ip_name = "#{Souls.configuration.app}-ip"
205
- system("gcloud compute addresses create #{ip_name} --global")
206
- end
207
-
208
- def apply_deployment
209
- namespace = Souls.configuration.namespace
210
- system("kubectl apply -f ./infra/deployment.yml --namespace=#{namespace}")
211
- end
212
-
213
- def apply_secret
214
- namespace = Souls.configuration.namespace
215
- system("kubectl apply -f ./infra/secret.yml --namespace=#{namespace}")
216
- end
217
-
218
- def apply_service
219
- namespace = Souls.configuration.namespace
220
- system("kubectl apply -f ./infra/service.yml --namespace=#{namespace}")
221
- end
222
-
223
- def apply_ingress
224
- namespace = Souls.configuration.namespace
225
- system("kubectl apply -f ./infra/ingress.yml --namespace=#{namespace}")
226
- end
227
-
228
- def delete_deployment
229
- namespace = Souls.configuration.namespace
230
- system("kubectl delete -f ./infra/deployment.yml --namespace=#{namespace}")
231
- end
232
-
233
- def delete_secret
234
- namespace = Souls.configuration.namespace
235
- system("kubectl delete -f ./infra/secret.yml --namespace=#{namespace}")
236
- end
237
-
238
- def delete_service
239
- namespace = Souls.configuration.namespace
240
- system("kubectl delete -f ./infra/service.yml --namespace=#{namespace}")
241
- end
242
-
243
- def delete_ingress
244
- namespace = Souls.configuration.namespace
245
- system("kubectl delete -f ./infra/ingress.yml --namespace=#{namespace}")
246
- end
247
-
248
- def create_dns_conf
249
- app = Souls.configuration.app
250
- namespace = Souls.configuration.namespace
251
- domain = Souls.configuration.domain
252
- `echo "#{domain}. 300 IN A $(kubectl get ingress --namespace #{namespace} | grep #{app} | awk '{print $3}')" >> ./infra/dns_conf`
253
- "created dns file!"
254
- end
255
-
256
- def set_dns
257
- project_id = Souls.configuration.main_project_id
258
- `gcloud dns record-sets import -z=#{project_id} --zone-file-format ./infra/dns_conf`
259
- end
260
-
261
- def service_api_enable
262
- `gcloud services enable iam.googleapis.com`
263
- `gcloud services enable dns.googleapis.com`
264
- `gcloud services enable container.googleapis.com`
265
- `gcloud services enable containerregistry.googleapis.com`
266
- `gcloud services enable servicenetworking.googleapis.com`
267
- `gcloud services enable sqladmin.googleapis.com`
268
- `gcloud services enable sql-component.googleapis.com`
269
- `gcloud services enable cloudbuild.googleapis.com`
270
- end
271
-
272
- def update_container zone: :asia
273
- project_id = Souls.configuration.project_id
274
- firestore = Google::Cloud::Firestore.new
275
- strain = Souls.configuration.strain
276
- app = Souls.configuration.app
277
- container = case strain
278
- when "api"
279
- app
280
- else
281
- Souls.configuration.service_name
282
- end
283
- zones = {
284
- us: "gcr.io",
285
- eu: "eu.gcr.io",
286
- asia: "asia.gcr.io"
287
- }
288
- versions = firestore.doc "containers/#{container}/versions/1"
289
- if versions.get.exists?
290
- versions = firestore.col("containers").doc(container).col("versions")
291
- query = versions.order("version_counter", "desc").limit 1
292
- query.get do |v|
293
- @next_version = v.data[:version_counter] + 1
294
- end
295
- else
296
- @next_version = 1
297
- end
298
- version = firestore.col("containers").doc(container).col("versions").doc @next_version
299
- version.set version: "v#{@next_version}", version_counter: @next_version, zone: zones[zone], created_at: Time.now.utc
300
-
301
- system("docker build . -t #{app}:v#{@next_version}")
302
- system("docker tag #{app}:v#{@next_version} #{zones[zone]}/#{project_id}/#{app}:v#{@next_version}")
303
- system("docker push #{zones[zone]}/#{project_id}/#{app}:v#{@next_version}")
304
- end
305
-
306
- def create_service_account
307
- service_account = Souls.configuration.app
308
- `gcloud iam service-accounts create #{service_account} \
309
- --description="Souls Service Account" \
310
- --display-name="#{service_account}"`
311
- end
312
-
313
- def create_service_account_key
314
- project_id = Souls.configuration.project_id
315
- service_account = Souls.configuration.app
316
- `gcloud iam service-accounts keys create ./config/keyfile.json \
317
- --iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com`
318
- end
319
-
320
- def add_service_account_role role: "roles/firebase.admin"
321
- project_id = Souls.configuration.project_id
322
- service_account = Souls.configuration.app
323
- `gcloud projects add-iam-policy-binding #{project_id} \
324
- --member="serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com" \
325
- --role="#{role}"`
326
- end
327
-
328
- def get_pods
329
- namespace = Souls.configuration.namespace
330
- system("kubectl get pods --namespace=#{namespace}")
331
- end
332
-
333
- def get_svc
334
- namespace = Souls.configuration.namespace
335
- system("kubectl get svc --namespace=#{namespace}")
336
- end
337
-
338
- def get_ingress
339
- namespace = Souls.configuration.namespace
340
- system("kubectl get ingress --namespace=#{namespace}")
341
- end
342
-
343
- def run
344
- app = Souls.configuration.app
345
- system("docker rm -f web")
346
- system("docker build . -t #{app}:latest")
347
- system("docker run --name web -it --env-file $PWD/.env -p 3000:3000 #{app}:latest")
348
- end
349
-
350
- def get_clusters
351
- system("kubectl config get-clusters")
352
- end
353
-
354
- def get_current_cluster
355
- system("kubectl config current-context")
356
- end
357
-
358
- def use_context cluster:
359
- system("kubectl config use-context #{cluster}")
360
- end
361
-
362
- def get_credentials
363
- app = Souls.configuration.app
364
- zone = Souls.configuration.zone
365
- system "gcloud container clusters get-credentials #{app} --zone #{zone}"
366
- end
367
-
368
- def create_ssl
369
- app = Souls.configuration.app
370
- domain = Souls.configuration.domain
371
- system "gcloud compute ssl-certificates create #{app}-ssl --domains=#{domain} --global"
372
- end
373
-
374
13
  def run_psql
375
14
  `docker run --rm -d \
376
15
  -p 5433:5432 \
@@ -430,21 +69,10 @@ module Souls
430
69
  end
431
70
 
432
71
  class Configuration
433
- 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
434
73
 
435
74
  def initialize
436
- @main_project_id = nil
437
- @project_id = nil
438
75
  @app = nil
439
- @network = nil
440
- @namespace = nil
441
- @service_name = nil
442
- @machine_type = nil
443
- @zone = nil
444
- @domain = nil
445
- @google_application_credentials = nil
446
- @strain = nil
447
- @proto_package_name = nil
448
76
  end
449
77
  end
450
78
  end
@@ -20,7 +20,9 @@ module Souls
20
20
  end
21
21
 
22
22
  def policy class_name: "souls"
23
- file_path = "./app/policy/#{class_name.singularize}_policy.rb"
23
+ dir_name = "./app/policies"
24
+ FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
25
+ file_path = "./app/policies/#{class_name.singularize}_policy.rb"
24
26
  File.open(file_path, "w") do |f|
25
27
  f.write <<~EOS
26
28
  class #{class_name.camelize}Policy < ApplicationPolicy
@@ -59,6 +61,50 @@ module Souls
59
61
  [file_path]
60
62
  end
61
63
 
64
+ def rspec_policy class_name: "souls"
65
+ dir_name = "./spec/policies"
66
+ FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
67
+ file_path = "./spec/policies/#{class_name}_policy_spec.rb"
68
+ File.open(file_path, "w") do |new_line|
69
+ new_line.write <<~EOS
70
+ describe #{class_name.camelize}Policy do
71
+ subject { described_class.new(user, #{class_name.underscore}) }
72
+
73
+ let(:#{class_name.underscore}) { FactoryBot.create(:#{class_name.underscore}) }
74
+
75
+ context "being a visitor" do
76
+ let(:user) { FactoryBot.create(:user) }
77
+
78
+ it { is_expected.to permit_action(:index) }
79
+ it { is_expected.to permit_action(:show) }
80
+ it { is_expected.to forbid_actions([:create, :update, :delete]) }
81
+ end
82
+
83
+ context "being a retailer" do
84
+ let(:user) { FactoryBot.create(:user, user_role: 1) }
85
+
86
+ it { is_expected.to permit_action(:index) }
87
+ it { is_expected.to permit_action(:show) }
88
+ it { is_expected.to forbid_actions([:create, :update, :delete]) }
89
+ end
90
+
91
+ context "being a staff" do
92
+ let(:user) { FactoryBot.create(:user, user_role: 3) }
93
+
94
+ it { is_expected.to permit_actions([:create, :update, :delete]) }
95
+ end
96
+
97
+ context "being an administrator" do
98
+ let(:user) { FactoryBot.create(:user, user_role: 4) }
99
+
100
+ it { is_expected.to permit_actions([:create, :update, :delete]) }
101
+ end
102
+ end
103
+ EOS
104
+ end
105
+ [file_path]
106
+ end
107
+
62
108
  def resolver_head class_name: "souls"
63
109
  FileUtils.mkdir_p "./app/graphql/resolvers" unless Dir.exist? "./app/graphql/resolvers"
64
110
  file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
@@ -180,18 +226,18 @@ module Souls
180
226
  def resolver_end class_name: "souls"
181
227
  file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
182
228
  File.open(file_path, "a") do |f|
183
- f.write <<-EOS
184
- scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
185
- scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
186
-
187
- branches << scope
188
-
189
- value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
190
-
191
- branches
192
- end
193
- end
194
- end
229
+ f.write <<~EOS
230
+ scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
231
+ scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
232
+ #{' '}
233
+ branches << scope
234
+ #{' '}
235
+ value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
236
+ #{' '}
237
+ branches
238
+ end
239
+ end
240
+ end
195
241
  EOS
196
242
  end
197
243
  [file_path]
@@ -358,11 +404,11 @@ end
358
404
  f.each_line.with_index do |line, i|
359
405
  if @on
360
406
  if line.include?("end") || line.include?("t.index")
361
- new_line.write <<-EOS
362
- )
363
- end
364
- end
365
- end
407
+ new_line.write <<~EOS
408
+ )
409
+ end
410
+ end
411
+ end
366
412
  EOS
367
413
  break
368
414
  end
@@ -406,9 +452,6 @@ end
406
452
  rspec_resolver_end class_name: singularized_class_name
407
453
  end
408
454
 
409
-
410
-
411
-
412
455
  def add_delete class_name: "souls"
413
456
  singularized_class_name = class_name.singularize.underscore
414
457
  pluralized_class_name = class_name.pluralize.underscore
@@ -450,32 +493,27 @@ end
450
493
 
451
494
  def add_mutation class_name: "souls", file_name: "hoi"
452
495
  singularized_class_name = class_name.singularize.underscore
453
- file_path = "./app/graphql/mutations/#{singularized_class_name}/#{file_name}.rb"
454
- file_path
496
+ "./app/graphql/mutations/#{singularized_class_name}/#{file_name}.rb"
455
497
  end
456
498
 
457
499
  def add_type class_name: "souls", file_name: "hoi"
458
500
  singularized_class_name = class_name.singularize.underscore
459
- file_path = "./app/graphql/types/#{file_name}.rb"
460
- file_path
501
+ "./app/graphql/types/#{file_name}.rb"
461
502
  end
462
503
 
463
504
  def add_edge class_name: "souls", file_name: "hoi"
464
505
  singularized_class_name = class_name.singularize.underscore
465
- file_path = "./app/graphql/types/#{file_name}.rb"
466
- file_path
506
+ "./app/graphql/types/#{file_name}.rb"
467
507
  end
468
508
 
469
509
  def add_connection class_name: "souls", file_name: "hoi"
470
510
  singularized_class_name = class_name.singularize.underscore
471
- file_path = "./app/graphql/types/#{file_name}.rb"
472
- file_path
511
+ "./app/graphql/types/#{file_name}.rb"
473
512
  end
474
513
 
475
514
  def add_rspec_mutation class_name: "souls", file_name: "hoi"
476
515
  singularized_class_name = class_name.singularize.underscore
477
- file_path = "./app/graphql/types/#{file_name}.rb"
478
- file_path
516
+ "./app/graphql/types/#{file_name}.rb"
479
517
  end
480
518
  end
481
519
  end
data/lib/souls/init.rb CHANGED
@@ -1,103 +1,6 @@
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
49
- end
50
-
51
- 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"
54
- File.open(file_path, "w") do |f|
55
- f.write <<~EOS
56
- Souls.configure do |config|
57
- config.main_project_id = "#{project[:main_project_id]}"
58
- config.project_id = "#{project[:project_id]}"
59
- 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
- config.strain = "#{project[:strain]}"
68
- config.proto_package_name = "souls"
69
- end
70
- EOS
71
- end
72
- end
73
-
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
4
  def get_version repository_name: "souls_service"
102
5
  data = JSON.parse `curl \
103
6
  -H "Accept: application/vnd.github.v3+json" \
@@ -111,7 +14,7 @@ module Souls
111
14
  system "tar -zxvf ./#{version}.tar.gz"
112
15
  system "mkdir #{app_name}"
113
16
  folder = version.delete "v"
114
- system "cp -r #{repository_name}-#{folder}/ #{app_name}/"
17
+ system "cp -r #{repository_name}-#{folder}/* #{app_name}/"
115
18
  system "rm -rf #{version}.tar.gz && rm -rf #{repository_name}-#{folder}"
116
19
  txt = <<~TEXT
117
20
  _____ ____ __ ____#{' '}
@@ -129,119 +32,6 @@ module Souls
129
32
  puts "------------------------------"
130
33
  end
131
34
 
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
35
  def model class_name: "souls"
246
36
  file_path = "./app/models/#{class_name.singularize}.rb"
247
37
  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.4"
2
+ VERSION = "0.17.9"
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."
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
22
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
23
  end
24
24
  spec.bindir = "exe"
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.4
4
+ version: 0.17.9
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-01 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