souls 0.7.0

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.
@@ -0,0 +1,226 @@
1
+ require "mechanize"
2
+
3
+ module Souls
4
+ STRAINS = ["service", "api", "media", "admin"]
5
+ module Init
6
+ class << self
7
+ def create_souls strain: 1, app_name: "souls"
8
+ config_needed = (1..2)
9
+ project = {}
10
+ project[:strain] = STRAINS[strain.to_i - 1]
11
+ begin
12
+ puts "Google Cloud Main PROJECT_ID(This project will controll Cloud DNS): (default: elsoul2)"
13
+ project[:main_project_id] = STDIN.gets.chomp
14
+ project[:main_project_id] == "" ? project[:main_project_id] = "elsoul2" : true
15
+ puts "Google Cloud PROJECT_ID: (default: elsoul2)"
16
+ project[:project_id] = STDIN.gets.chomp
17
+ project[:project_id] == "" ? project[:project_id] = "elsoul2" : true
18
+ puts "VPC Network Name: (default: default)"
19
+ project[:network] = STDIN.gets.chomp
20
+ project[:network] == "" ? project[:network] = "default" : true
21
+ puts "Namespace: (default: souls)"
22
+ project[:namespace] = STDIN.gets.chomp
23
+ project[:namespace] == "" ? project[:namespace] = "souls" : true
24
+ if project[:strain] == "service"
25
+ puts "Service Name: (default: blog-service)"
26
+ project[:service_name] = STDIN.gets.chomp
27
+ project[:service_name] == "" ? project[:service_name] = "blog-service" : true
28
+ end
29
+ puts "Instance MachineType: (default: custom-1-6656)"
30
+ project[:machine_type] = STDIN.gets.chomp
31
+ project[:machine_type] == "" ? project[:machine_type] = "custom-1-6656" : true
32
+ puts "Zone: (default: us-central1-a)"
33
+ project[:zone] = STDIN.gets.chomp
34
+ project[:zone] == "" ? project[:zone] = "us-central1-a" : true
35
+ puts "Domain: (e.g API: el-soul.com, Serive: xds:///blog-service:8000)"
36
+ project[:domain] = STDIN.gets.chomp
37
+ project[:domain] == "" ? project[:domain] = "el-soul.com" : true
38
+ puts "Google Application Credentials Path: (default: #{app_name}/config/credentials.json)"
39
+ project[:google_application_credentials] = STDIN.gets.chomp
40
+ project[:google_application_credentials] == "" ? project[:google_application_credentials] = "./config/credentials.json" : true
41
+ puts project
42
+ puts "Enter to finish set up!"
43
+ confirm = STDIN.gets.chomp
44
+ raise StandardError, "Retry" unless confirm == ""
45
+ download_souls app_name: app_name, repository_name: "souls_#{STRAINS[strain.to_i - 1]}"
46
+ config_init app_name: app_name, project: project if config_needed.include?(strain)
47
+ rescue StandardError => error
48
+ puts error
49
+ retry
50
+ end
51
+ end
52
+
53
+ def config_init app_name: "souls", project: {}
54
+ file_path = "#{app_name}/config/initializers/souls.rb"
55
+ File.open(file_path, "w") do |f|
56
+ f.write <<~EOS
57
+ Souls.configure do |config|
58
+ config.main_project_id = "#{project[:main_project_id]}"
59
+ config.project_id = "#{project[:project_id]}"
60
+ config.app = "#{app_name}"
61
+ config.namespace = "#{project[:namespace]}"
62
+ config.service_name = "#{project[:service_name]}"
63
+ config.network = "#{project[:network]}"
64
+ config.machine_type = "#{project[:machine_type]}"
65
+ config.zone = "#{project[:zone]}"
66
+ config.domain = "#{project[:domain]}"
67
+ config.google_application_credentials = "#{project[:google_application_credentials]}"
68
+ config.strain = "#{project[:strain]}"
69
+ config.proto_package_name = "souls"
70
+ end
71
+ EOS
72
+ end
73
+ end
74
+
75
+ def get_version repository_name: "souls_service"
76
+ agent = Mechanize.new
77
+ page = agent.get("https://github.com/elsoul/#{repository_name}/releases")
78
+ page.search("span.css-truncate-target")[0].to_s.scan(/^*+>(.+)</)[0][0].to_s
79
+ end
80
+
81
+ def download_souls app_name: "souls", repository_name: "souls_service"
82
+ version = get_version repository_name: repository_name
83
+ system "curl -OL https://github.com/elsoul/#{repository_name}/archive/#{version}.tar.gz"
84
+ system "tar -zxvf ./#{version}.tar.gz"
85
+ system "mkdir #{app_name}"
86
+ folder = version.delete "v"
87
+ system "cp -aiv #{repository_name}-#{folder}/* #{app_name}/"
88
+ system "rm -rf #{version}.tar.gz && rm -rf #{repository_name}-#{folder}"
89
+ txt = <<~TEXT
90
+ _____ ____ __ ____
91
+ / ___// __ \\/ / / / / _____
92
+ \\__ \\/ / / / / / / / / ___/
93
+ ___/ / /_/ / /_/ / /___(__ )
94
+ /____/\\____/\\____/_____/____/
95
+ TEXT
96
+ puts txt
97
+ puts "=============================="
98
+ puts "Welcome to SOULs!"
99
+ puts "SOULs Version: #{Souls::VERSION}"
100
+ puts "=============================="
101
+ puts "$ cd #{app_name}"
102
+ puts "------------------------------"
103
+ end
104
+
105
+ def proto proto_package_name: "souls", service: "blog"
106
+ system "grpc_tools_ruby_protoc -I ./protos --ruby_out=./app/services --grpc_out=./app/services ./protos/#{service}.proto"
107
+ file_path = "./app/services/#{service}_pb.rb"
108
+ File.open(file_path, "a") do |f|
109
+ f.write <<~EOS
110
+ module #{service.capitalize}Pb
111
+ end
112
+ EOS
113
+ end
114
+ service_pb_path = "./app/services/#{service}_services_pb.rb"
115
+ new_file = "./app/services/#{proto_package_name}.rb"
116
+ File.open(new_file, "w") do |new_line|
117
+ File.open(service_pb_path, "r") do |f|
118
+ f.each_line.with_index do |line, i|
119
+ case i
120
+ when 0
121
+ new_line.write "# Generated by the SOULs protocol buffer compiler. DO NOT EDIT!\n"
122
+ when 3
123
+ next
124
+ else
125
+ puts "#{i}: #{line}"
126
+ new_line.write line.to_s
127
+ end
128
+ end
129
+ end
130
+ end
131
+ FileUtils.rm service_pb_path
132
+ puts "SOULs Proto Created!"
133
+ end
134
+
135
+ def service_deploy
136
+ service_name = Souls.configuration.service_name
137
+ health_check_name = "#{service_name}-hc"
138
+ firewall_rule_name = "#{service_name}-allow-health-checks"
139
+ zone = Souls.configuration.zone
140
+ url_map_name = "#{service_name}-url-map"
141
+ path_matcher_name = "#{service_name}-path-mathcher"
142
+ port = "5000"
143
+ proxy_name = "#{service_name}-proxy"
144
+ forwarding_rule_name = "#{service_name}-forwarding-rule"
145
+
146
+ Souls.create_service_account
147
+ Souls.create_service_account_key
148
+ Souls.add_service_account_role
149
+ Souls.add_service_account_role role: "roles/containerregistry.ServiceAgent"
150
+ Souls.create_health_check health_check_name: health_check_name
151
+ Souls.create_firewall_rule firewall_rule_name: firewall_rule_name
152
+ Souls.create_backend_service service_name: service_name, health_check_name: health_check_name
153
+ Souls.export_network_group
154
+ file_path = "./infra/config/neg_name"
155
+ File.open(file_path) do |f|
156
+ Souls.add_backend_service service_name: service_name, neg_name: f.gets.to_s, zone: zone
157
+ end
158
+ Souls.create_url_map url_map_name: url_map_name, service_name: service_name
159
+ Souls.create_path_matcher url_map_name: url_map_name, service_name: service_name, path_matcher_name: path_matcher_name, hostname: app, port: port
160
+ Souls.create_target_grpc_proxy proxy_name: proxy_name, url_map_name: url_map_name
161
+ Souls.create_forwarding_rule forwarding_rule_name: forwarding_rule_name, proxy_name: proxy_name, port: port
162
+ end
163
+
164
+ def api_deploy
165
+ Souls.create_service_account
166
+ Souls.create_service_account_key
167
+ Souls.add_service_account_role
168
+ Souls.add_service_account_role role: "roles/containerregistry.ServiceAgent"
169
+ Souls.config_set
170
+ Souls.create_network
171
+ Souls.create_cluster
172
+ Souls.get_credentials
173
+ Souls.create_namespace
174
+ Souls.create_ip
175
+ Souls.create_ssl
176
+ Souls.apply_deployment
177
+ Souls.apply_service
178
+ Souls.apply_ingress
179
+ puts "Wainting for Ingress to get IP..."
180
+ sleep 1
181
+ puts "This migth take a few mins..."
182
+ sleep 90
183
+ Souls.create_dns_conf
184
+ Souls.config_set_main
185
+ Souls.set_dns
186
+ Souls.config_set
187
+ end
188
+
189
+ def local_deploy
190
+ `souls i run_psql`
191
+ `docker pull`
192
+ end
193
+
194
+ def service_update
195
+ `souls i apply_deployment`
196
+ end
197
+
198
+ def api_update
199
+ `souls i apply_deployment`
200
+ end
201
+
202
+ def service_delete
203
+ service_name = Souls.configuration.service_name
204
+ firewall_rule_name = "#{service_name}-allow-health-checks"
205
+ url_map_name = "#{service_name}-url-map"
206
+ proxy_name = "#{service_name}-proxy"
207
+ forwarding_rule_name = "#{service_name}-forwarding-rule"
208
+
209
+ Souls.delete_forwarding_rule forwarding_rule_name: forwarding_rule_name
210
+ Souls.delete_target_grpc_proxy proxy_name: proxy_name
211
+ Souls.delete_url_map url_map_name: url_map_name
212
+ Souls.delete_backend_service service_name: service_name
213
+ Souls.delete_health_check health_check_name: health_check_name
214
+ Souls.delete_firewall_rule firewall_rule_name: firewall_rule_name
215
+ end
216
+
217
+ def api_delete
218
+ `souls i delete_deployment`
219
+ `souls i delete_secret`
220
+ `souls i delete_service`
221
+ `souls i delete_ingress`
222
+ end
223
+
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,3 @@
1
+ module Souls
2
+ VERSION = "0.7.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/souls/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "souls"
5
+ spec.version = Souls::VERSION
6
+ spec.authors = ["POPPIN-FUMI", "KishiTheMechanic"]
7
+ spec.email = ["fumitake.kawasaki@el-soul.com", "shota.kishi@el-soul.com"]
8
+
9
+ spec.summary = "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."
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."
11
+ spec.homepage = "https://github.com/elsoul/souls"
12
+ spec.license = "Apache-2.0"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/elsoul/souls"
17
+ spec.metadata["changelog_uri"] = "https://github.com/elsoul/souls"
18
+
19
+ # Specify which files should be added to the gem when it is released.
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
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.add_dependency("google-cloud-firestore", "2.4.0")
28
+ spec.add_dependency("mechanize", "2.7.6")
29
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: souls
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - POPPIN-FUMI
8
+ - KishiTheMechanic
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-12-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: google-cloud-firestore
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 2.4.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 2.4.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: mechanize
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 2.7.6
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 2.7.6
42
+ description: SOULS is a Web Application Framework for Microservices on Multi Cloud
43
+ Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud.
44
+ Auto deploy with scalable condition. You can focus on business logic. No more infra
45
+ problems.
46
+ email:
47
+ - fumitake.kawasaki@el-soul.com
48
+ - shota.kishi@el-soul.com
49
+ executables:
50
+ - souls
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".gitignore"
55
+ - ".irbrc"
56
+ - ".rspec"
57
+ - ".rubocop.yml"
58
+ - ".ruby-version"
59
+ - ".travis.yml"
60
+ - CODE_OF_CONDUCT.md
61
+ - Gemfile
62
+ - Gemfile.lock
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - config/initializers/souls.rb
69
+ - exe/souls
70
+ - lib/souls.rb
71
+ - lib/souls/init.rb
72
+ - lib/souls/version.rb
73
+ - souls.gemspec
74
+ homepage: https://github.com/elsoul/souls
75
+ licenses:
76
+ - Apache-2.0
77
+ metadata:
78
+ homepage_uri: https://github.com/elsoul/souls
79
+ source_code_uri: https://github.com/elsoul/souls
80
+ changelog_uri: https://github.com/elsoul/souls
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.7.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.1.4
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: SOULS is a Web Application Framework for Microservices on Multi Cloud Platform
100
+ such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud. Auto deploy
101
+ with scalable condition. You can focus on business logic. No more infra problems.
102
+ test_files: []