souls 0.35.2 → 0.36.1

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: dacb9b58643bb6a26a4cb2a994296c6c1ed81a761ff5244141d28fdf1343958a
4
- data.tar.gz: ed557b37c4e6c39471795b1b7fc08e1f75fae7521179099738a2becb3b630eb5
3
+ metadata.gz: d6a59673cbe8fbbc5fd02e75a7ca5d04d5e190e0555be86f721c3ef3c1d33624
4
+ data.tar.gz: c4f4e094d3bc26d79c9d1bc37c2f15361f191335cc15fcc29a74e3c85af392ae
5
5
  SHA512:
6
- metadata.gz: 6a61f4d5a83f359dfe38e787e99584e00a0f245d810058468185843c7f13559cc9a4323bcd718f5130973c14cf9bd09bccbc606ebc793ae0183fbf14b5406070
7
- data.tar.gz: 208239db7f27943c5cd0b4ac2cb13fec2e3af7c7a76bce43cdc044d51ba66ea235b4549cb4e0d5ef94930a1ebf613aa15218033c1151b2ec31a53fb81706ba70
6
+ metadata.gz: 1957d2a8a3a1389a2c6306c3a695f2c4e5e7b6ff03c46c9e552961a77c8f277a9a58c12a92ba27b5dc6d2791bfdf2a85a888decab54c0481ac2df8464fcdf6c4
7
+ data.tar.gz: 936917a7190919b9fb48b0aa69a08e09cfa9225b12bbbf94209bfc70e6acbca4a0e1d3f2568851e2dba2c88906315ca3673d7f676c4c436a974611fdf3be6558
data/exe/souls CHANGED
@@ -151,7 +151,8 @@ begin
151
151
  service_name = ARGV[1]
152
152
  case service_name
153
153
  when "worker"
154
- Souls::Init.download_worker
154
+ worker_name = ARGV[2]
155
+ Souls::Create.worker(worker_name: worker_name)
155
156
  else
156
157
  puts(Paint["Coming Soon...", :green])
157
158
  end
@@ -0,0 +1,196 @@
1
+ module Souls
2
+ module Create
3
+ class << self
4
+ def worker(worker_name: "mailer")
5
+ workers = Souls.configuration.workers
6
+ port = 3000 + workers.size
7
+ download_worker(worker_name: worker_name)
8
+ souls_conf_update(worker_name: worker_name)
9
+ souls_conf_update(worker_name: worker_name, strain: "api")
10
+ workflow(worker_name: worker_name)
11
+ procfile(worker_name: worker_name, port: port)
12
+ mother_procfile(worker_name: worker_name)
13
+ end
14
+
15
+ def procfile(worker_name: "mailer", port: 3000)
16
+ file_dir = "apps/#{worker_name}"
17
+ file_path = "#{file_dir}/Procfile.dev"
18
+ File.open(file_path, "w") do |f|
19
+ f.write("web: bundle exec puma -p #{port} -e development")
20
+ end
21
+ end
22
+
23
+ def mother_procfile(worker_name: "mailer")
24
+ file_path = "Procfile.dev"
25
+ File.open(file_path, "a") do |f|
26
+ f.write("\n#{worker_name}: foreman start -f ./apps/#{worker_name}/Procfile")
27
+ end
28
+ end
29
+
30
+ def souls_conf_update(worker_name: "", strain: "mother")
31
+ workers = Souls.configuration.workers
32
+ port = 3000 + workers.size
33
+ file_path = strain == "mother" ? "config/souls.rb" : "apps/api/config/souls.rb"
34
+ new_file_path = "souls.rb"
35
+ worker_switch = false
36
+ File.open(new_file_path, "w") do |new_line|
37
+ File.open(file_path, "r") do |f|
38
+ f.each_line do |line|
39
+ worker_switch = true if line.include?("config.workers")
40
+ next if line.strip == "end"
41
+
42
+ new_line.write(line) unless worker_switch
43
+
44
+ next unless worker_switch
45
+
46
+ new_line.write(" config.workers = [\n")
47
+ workers.each do |worker|
48
+ new_line.write(<<-TEXT)
49
+ {
50
+ name: "#{worker[:name]}",
51
+ endpoint: "#{worker[:endpoint]}",
52
+ port: #{worker[:port]}
53
+ },
54
+ TEXT
55
+ end
56
+ break
57
+ end
58
+ end
59
+ new_line.write(<<-TEXT)
60
+ {
61
+ name: "#{worker_name}",
62
+ endpoint: "",
63
+ port: #{port}
64
+ }
65
+ ]
66
+ end
67
+ TEXT
68
+ end
69
+ FileUtils.rm(file_path)
70
+ FileUtils.mv(new_file_path, file_path)
71
+ end
72
+
73
+ def workflow(worker_name: "")
74
+ file_dir = ".github/workflows"
75
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
76
+ file_path = "#{file_dir}/#{worker_name}.yml"
77
+ worker_name = worker_name.underscore
78
+ worker_name_camelize = worker_name.camelize
79
+ File.open(file_path, "w") do |f|
80
+ f.write(<<~TEXT)
81
+ name: #{worker_name_camelize}
82
+
83
+ on:
84
+ push:
85
+ branches:
86
+ - master
87
+ paths:
88
+ - "apps/#{worker_name}/**"
89
+ - ".github/workflows/#{worker_name}.yml"
90
+
91
+ jobs:
92
+ build:
93
+
94
+ runs-on: ubuntu-20.04
95
+
96
+ services:
97
+ db:
98
+ image: postgres:13
99
+ ports: ["5433:5432"]
100
+ env:
101
+ POSTGRES_PASSWORD: postgres
102
+ options: >-
103
+ --health-cmd pg_isready
104
+ --health-interval 10s
105
+ --health-timeout 5s
106
+ --health-retries 5
107
+
108
+ steps:
109
+ - uses: actions/checkout@v2
110
+ - name: Set up Ruby 3.0
111
+ uses: actions/setup-ruby@v1
112
+ with:
113
+ ruby-version: 3.0
114
+ - name: Build and test with Rake
115
+ env:
116
+ PGHOST: 127.0.0.1
117
+ PGUSER: postgres
118
+ RACK_ENV: test
119
+ run: |
120
+ sudo apt-get -yqq install libpq-dev
121
+ cd apps/worker
122
+ gem install bundler
123
+ bundle install --jobs 4 --retry 3
124
+ bundle exec rake db:create RACK_ENV=test
125
+ bundle exec rake db:migrate RACK_ENV=test
126
+ bundle exec rspec
127
+
128
+ - name: Checkout the repository
129
+ uses: actions/checkout@v2
130
+
131
+ - name: GCP Authenticate
132
+ uses: google-github-actions/setup-gcloud@master
133
+ with:
134
+ version: "323.0.0"
135
+ project_id: ${{ secrets.GCP_PROJECT_ID }}
136
+ service_account_key: ${{ secrets.GCP_SA_KEY }}
137
+ export_default_credentials: true
138
+
139
+ - name: Configure Docker
140
+ run: gcloud auth configure-docker --quiet
141
+
142
+ - name: Build Docker container
143
+ run: docker build -f ./apps/#{worker_name}/Dockerfile ./apps/#{worker_name} -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{secrets.APP_NAME}}-#{worker_name}
144
+
145
+ - name: Push to Container Resistory
146
+ run: docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{secrets.APP_NAME}}-#{worker_name}
147
+
148
+ - name: Deploy to Cloud Run
149
+ run: |
150
+ gcloud run deploy ${{ secrets.APP_NAME }}-#{worker_name} \\
151
+ --service-account=${{ secrets.APP_NAME }}@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com \\
152
+ --image=gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{secrets.APP_NAME}}-#{worker_name} \\
153
+ --memory=4Gi \\
154
+ --region=asia-northeast1 \\
155
+ --allow-unauthenticated \\
156
+ --platform=managed \\
157
+ --quiet \\
158
+ --concurrency=80 \\
159
+ --port=8080 \\
160
+ --set-cloudsql-instances=${{ secrets.GCLOUDSQL_INSTANCE }} \\
161
+ --set-env-vars="DB_USER=${{ secrets.DB_USER }}" \\
162
+ --set-env-vars="DB_PW=${{ secrets.DB_PW }}" \\
163
+ --set-env-vars="DB_HOST=${{ secrets.DB_HOST }}" \\
164
+ --set-env-vars="TZ=${{ secrets.TZ }}" \\
165
+ --set-env-vars="SLACK=${{ secrets.SLACK }}" \\
166
+ --set-env-vars="SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}" \\
167
+ --set-env-vars="PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}"
168
+ TEXT
169
+ end
170
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
171
+ file_path
172
+ rescue StandardError => e
173
+ raise(StandardError, e)
174
+ end
175
+
176
+ def download_worker(worker_name: "mailer")
177
+ raise(StandardError, "Can't use `worker` for worker. Change Name.") if worker_name == "worker"
178
+
179
+ current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
180
+ wrong_dir = %w[apps api worker]
181
+ if wrong_dir.include?(current_dir_name)
182
+ raise(StandardError, "You are at wrong directory!Go to Mother Directory!")
183
+ end
184
+
185
+ version = Souls.get_latest_version_txt(service_name: "worker").join(".")
186
+ file_name = "worker-v#{version}.tgz"
187
+ url = "https://storage.googleapis.com/souls-bucket/boilerplates/workers/#{file_name}"
188
+ system("curl -OL #{url}")
189
+ system("tar -zxvf ./#{file_name} -C ./apps/")
190
+ system("mv apps/worker apps/#{worker_name}")
191
+ system("cp ./apps/api/config/database.yml ./apps/#{worker_name}/config/")
192
+ FileUtils.rm(file_name)
193
+ end
194
+ end
195
+ end
196
+ end
@@ -5,11 +5,12 @@ module Souls
5
5
  def setup_vpc_nat(app_name: "", region: "asia-northeast1", range: "10.124.0.0/28")
6
6
  create_network(app_name: app_name)
7
7
  create_firewall_tcp(app_name: app_name, range: range)
8
- create_firewall_ssh(app_name: app_name, range: range)
8
+ create_firewall_ssh(app_name: app_name)
9
9
  create_subnet(app_name: app_name, region: region, range: range)
10
10
  create_connector(app_name: app_name, region: region)
11
11
  create_external_ip(app_name: app_name, region: region)
12
12
  create_nat(app_name: app_name, region: region)
13
+ nat_credit(app_name: app_name)
13
14
  end
14
15
 
15
16
  def create_network(app_name: "")
@@ -43,7 +44,7 @@ module Souls
43
44
 
44
45
  def create_connector(app_name: "", region: "asia-northeast1")
45
46
  app_name = Souls.configuration.app if app_name.blank?
46
- project_id = Souls.configuration.app if project_id.blank?
47
+ project_id = Souls.configuration.project_id
47
48
  system(
48
49
  "gcloud compute networks vpc-access connectors create #{app_name}-connector \
49
50
  --region=#{region} \
@@ -71,6 +72,42 @@ module Souls
71
72
  def network_list
72
73
  system("gcloud compute network list")
73
74
  end
75
+
76
+ def nat_credit(app_name: "")
77
+ app_name = Souls.configuration.app if app_name.blank?
78
+ line = Paint["====================================", :yellow]
79
+ puts("\n")
80
+ puts(line)
81
+ txt2 = <<~TEXT
82
+ _____ ____ __ ____#{' '}
83
+ / ___// __ \\/ / / / / %{red1}
84
+ \\__ \\/ / / / / / / / %{red2}
85
+ ___/ / /_/ / /_/ / /___%{red3}#{' '}
86
+ /____/\\____/\\____/_____%{red4}#{' '}
87
+ TEXT
88
+ red1 = ["_____", :red]
89
+ red2 = ["/ ___/", :red]
90
+ red3 = ["(__ )", :red]
91
+ red4 = ["/____/", :red]
92
+ ms = Paint % [txt2, :cyan, { red1: red1, red2: red2, red3: red3, red4: red4 }]
93
+ puts(ms)
94
+ puts(line)
95
+ welcome = Paint["VPC Network is All Set!", :white]
96
+ puts(welcome)
97
+ puts(line)
98
+ endroll = <<~TEXT
99
+
100
+ Edit `.github/workflow/worker.yml`
101
+
102
+ Add these 2 options in `- name: Deploy to Cloud Run` step
103
+ --vpc-connector=#{app_name}-connector \
104
+ --vpc-egress=all \
105
+
106
+ TEXT
107
+ cd = Paint[endroll, :white]
108
+ puts(cd)
109
+ puts(line)
110
+ end
74
111
  end
75
112
  end
76
113
  end
@@ -30,6 +30,8 @@ module Souls
30
30
  puts("Operating permission to containerregistry.googleapis.com")
31
31
  system("gcloud services enable run.googleapis.com")
32
32
  puts("Operating permission to run.googleapis.com")
33
+ system("gcloud services enable vpcaccess.googleapis.com")
34
+ puts("Operating permission to vpcaccess.googleapis.com")
33
35
  end
34
36
  end
35
37
  module Iam
@@ -14,6 +14,10 @@ module Souls
14
14
  project_id = Souls.configuration.project_id if project_id.blank?
15
15
  system("gcloud run services list --project #{project_id}")
16
16
  end
17
+
18
+ def get_endpoint(worker_name: "")
19
+ system("gcloud run services list | grep #{worker_name} | awk '{print $4}'")
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -1,3 +1,4 @@
1
+ require_relative "./create/index"
1
2
  require_relative "./docker/index"
2
3
  require_relative "./gcloud/index"
3
4
  require_relative "./release/index"
@@ -5,6 +6,9 @@ require_relative "./sync/index"
5
6
  require_relative "./upgrade/index"
6
7
 
7
8
  module Souls
9
+ module Create
10
+ end
11
+
8
12
  module Docker
9
13
  end
10
14
 
data/lib/souls/init.rb CHANGED
@@ -44,6 +44,7 @@ module Souls
44
44
  config.project_id = "#{app_name}-project"
45
45
  config.strain = "api"
46
46
  config.fixed_gems = ["excluded_gem"]
47
+ config.workers = []
47
48
  end
48
49
  TEXT
49
50
  end
@@ -72,6 +73,7 @@ module Souls
72
73
  config.project_id = "#{app_name}-project"
73
74
  config.strain = "mother"
74
75
  config.fixed_gems = ["excluded_gem"]
76
+ config.workers = []
75
77
  end
76
78
  TEXT
77
79
  end
@@ -145,55 +147,5 @@ module Souls
145
147
  puts(cd)
146
148
  puts(line)
147
149
  end
148
-
149
- def self.download_worker
150
- current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
151
- wrong_dir = %w[apps api worker]
152
- raise(StandardError, "You are at wrong directory!Go to Mother Directory!") if wrong_dir.include?(current_dir_name)
153
-
154
- version = Souls.get_latest_version_txt(service_name: "worker").join(".")
155
- file_name = "worker-v#{version}.tgz"
156
- url = "https://storage.googleapis.com/souls-bucket/boilerplates/workers/#{file_name}"
157
- system("curl -OL #{url}")
158
- system("mkdir -p ./apps/worker")
159
- system("tar -zxvf ./#{file_name} -C ./apps/")
160
- system("cp ./apps/api/config/database.yml ./apps/worker/config/")
161
- FileUtils.rm(file_name)
162
- line = Paint["====================================", :yellow]
163
- puts("\n")
164
- puts(line)
165
- txt2 = <<~TEXT
166
- _____ ____ __ ____#{' '}
167
- / ___// __ \\/ / / / / %{red1}
168
- \\__ \\/ / / / / / / / %{red2}
169
- ___/ / /_/ / /_/ / /___%{red3}#{' '}
170
- /____/\\____/\\____/_____%{red4}#{' '}
171
- TEXT
172
- red1 = ["_____", :red]
173
- red2 = ["/ ___/", :red]
174
- red3 = ["(__ )", :red]
175
- red4 = ["/____/", :red]
176
- ms = Paint % [txt2, :cyan, { red1: red1, red2: red2, red3: red3, red4: red4 }]
177
- puts(ms)
178
- puts(line)
179
- welcome = Paint["SOULs Worker Activated!", :white]
180
- puts(welcome)
181
- souls_ver = Paint["SOULs Version: #{Souls::VERSION}", :white]
182
- puts(souls_ver)
183
- puts(line)
184
- endroll = <<~TEXT
185
- Easy to Run
186
- $ cd ./apps/worker
187
- $ bundle
188
- $ souls sync model
189
- $ souls s
190
- Go To : http://localhost:3000
191
-
192
- Doc: https://souls.elsoul.nl
193
- TEXT
194
- cd = Paint[endroll, :white]
195
- puts(cd)
196
- puts(line)
197
- end
198
150
  end
199
151
  end
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.35.2".freeze
2
+ VERSION = "0.36.1".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.14.2
1
+ 0.15.1
@@ -1 +1 @@
1
- 0.14.2
1
+ 0.15.1
data/lib/souls.rb CHANGED
@@ -246,7 +246,7 @@ module Souls
246
246
  end
247
247
 
248
248
  class Configuration
249
- attr_accessor :app, :strain, :project_id, :github_repo, :worker_endpoint, :fixed_gems
249
+ attr_accessor :app, :strain, :project_id, :github_repo, :worker_endpoint, :fixed_gems, :workers
250
250
 
251
251
  def initialize
252
252
  @app = nil
@@ -255,6 +255,7 @@ module Souls
255
255
  @github_repo = nil
256
256
  @worker_endpoint = nil
257
257
  @fixed_gems = nil
258
+ @workers = nil
258
259
  end
259
260
  end
260
261
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.2
4
+ version: 0.36.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
8
8
  - KishiTheMechanic
9
9
  - James Neve
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-08-31 00:00:00.000000000 Z
13
+ date: 2021-09-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -125,6 +125,7 @@ files:
125
125
  - lib/souls/api/update/rspec_mutation.rb
126
126
  - lib/souls/api/update/rspec_resolver.rb
127
127
  - lib/souls/api/update/type.rb
128
+ - lib/souls/cli/create/index.rb
128
129
  - lib/souls/cli/docker/index.rb
129
130
  - lib/souls/cli/gcloud/compute/index.rb
130
131
  - lib/souls/cli/gcloud/iam/index.rb
@@ -157,7 +158,7 @@ metadata:
157
158
  homepage_uri: https://souls.elsoul.nl
158
159
  source_code_uri: https://github.com/elsoul/souls
159
160
  changelog_uri: https://github.com/elsoul/souls
160
- post_install_message:
161
+ post_install_message:
161
162
  rdoc_options: []
162
163
  require_paths:
163
164
  - lib
@@ -173,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
174
  version: '0'
174
175
  requirements: []
175
176
  rubygems_version: 3.2.22
176
- signing_key:
177
+ signing_key:
177
178
  specification_version: 4
178
179
  summary: SOULs はサーバーレスフルスタックフレームワークです。柔軟な Ruby GraphQL API と Worker はルーティングの必要がありません。
179
180
  クラウド環境への自動デプロイ、CI/CD ワークフローを標準装備。開発者がビジネスロジックに集中し、楽しくコードが書けるような環境を目指しています。