souls 0.35.3 → 0.36.2

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: 45b858d0b8b28252dbc16a47b2a487cb5104904593b492692835eb2c6d12bf09
4
- data.tar.gz: 850867fab6be599cacef8124056e95a92a6310724a03d1cdd7e1ce4241bca275
3
+ metadata.gz: 72bd5b4cded40b625ae03c8fc8a6e6cadb35bc41cd51d1ecbea455fb408b97f4
4
+ data.tar.gz: 1adce2db13e657ba9f602a65e8bc75742ac9f1200edb449b9f385bd55092a47d
5
5
  SHA512:
6
- metadata.gz: fa8e7f5b3ea59f60440072b2feb50d194e2d3cc39f5a9f76acc51480b2faafce466f7f4f5654598a309d42be2db3941b57eb1267b019a2e2456cec907f884206
7
- data.tar.gz: 38e38aae726f20d4e54a23cd62091e89f47c0a4f0a279f2d58b1b35e9733ca93b903bad50390e3617dda48599cc6a7e1664fbef9e96b5ff6cf1fa2fbb4129e37
6
+ metadata.gz: b12eafb2701ebfcc26cc0b770d2fe1c0ae93540d49ccffaa5393e0946520e87cfbbb13c110830a89f3d74e3d05f363633762102e7270ffa9f77171d487fcea1c
7
+ data.tar.gz: 13e8d4c8032e1901189fabec8907cb9425558f8946832570e85842cc92bc67cfd382ce5b35a3026012e1f61d0bdb971cccc40702e260b6c2e3979997aab08444
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,219 @@
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
+ souls_config_init(worker_name: worker_name)
14
+ end
15
+
16
+ def procfile(worker_name: "mailer", port: 3000)
17
+ file_dir = "apps/#{worker_name}"
18
+ file_path = "#{file_dir}/Procfile.dev"
19
+ File.open(file_path, "w") do |f|
20
+ f.write("web: bundle exec puma -p #{port} -e development")
21
+ end
22
+ end
23
+
24
+ def mother_procfile(worker_name: "mailer")
25
+ file_path = "Procfile.dev"
26
+ File.open(file_path, "a") do |f|
27
+ f.write("\n#{worker_name}: foreman start -f ./apps/#{worker_name}/Procfile")
28
+ end
29
+ end
30
+
31
+ def souls_conf_update(worker_name: "", strain: "mother")
32
+ workers = Souls.configuration.workers
33
+ port = 3000 + workers.size
34
+ file_path = strain == "mother" ? "config/souls.rb" : "apps/api/config/souls.rb"
35
+ new_file_path = "souls.rb"
36
+ worker_switch = false
37
+ File.open(new_file_path, "w") do |new_line|
38
+ File.open(file_path, "r") do |f|
39
+ f.each_line do |line|
40
+ worker_switch = true if line.include?("config.workers")
41
+ next if line.strip == "end"
42
+
43
+ new_line.write(line) unless worker_switch
44
+
45
+ next unless worker_switch
46
+
47
+ new_line.write(" config.workers = [\n")
48
+ workers.each do |worker|
49
+ new_line.write(<<-TEXT)
50
+ {
51
+ name: "#{worker[:name]}",
52
+ endpoint: "#{worker[:endpoint]}",
53
+ port: #{worker[:port]}
54
+ },
55
+ TEXT
56
+ end
57
+ break
58
+ end
59
+ end
60
+ new_line.write(<<-TEXT)
61
+ {
62
+ name: "#{worker_name}",
63
+ endpoint: "",
64
+ port: #{port}
65
+ }
66
+ ]
67
+ end
68
+ TEXT
69
+ end
70
+ FileUtils.rm(file_path)
71
+ FileUtils.mv(new_file_path, file_path)
72
+ end
73
+
74
+ def workflow(worker_name: "")
75
+ file_dir = ".github/workflows"
76
+ FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
77
+ file_path = "#{file_dir}/#{worker_name}.yml"
78
+ worker_name = worker_name.underscore
79
+ worker_name_camelize = worker_name.camelize
80
+ File.open(file_path, "w") do |f|
81
+ f.write(<<~TEXT)
82
+ name: #{worker_name_camelize}
83
+
84
+ on:
85
+ push:
86
+ branches:
87
+ - master
88
+ paths:
89
+ - "apps/#{worker_name}/**"
90
+ - ".github/workflows/#{worker_name}.yml"
91
+
92
+ jobs:
93
+ build:
94
+
95
+ runs-on: ubuntu-20.04
96
+
97
+ services:
98
+ db:
99
+ image: postgres:13
100
+ ports: ["5433:5432"]
101
+ env:
102
+ POSTGRES_PASSWORD: postgres
103
+ options: >-
104
+ --health-cmd pg_isready
105
+ --health-interval 10s
106
+ --health-timeout 5s
107
+ --health-retries 5
108
+
109
+ steps:
110
+ - uses: actions/checkout@v2
111
+ - name: Set up Ruby 3.0
112
+ uses: actions/setup-ruby@v1
113
+ with:
114
+ ruby-version: 3.0
115
+ - name: Build and test with Rake
116
+ env:
117
+ PGHOST: 127.0.0.1
118
+ PGUSER: postgres
119
+ RACK_ENV: test
120
+ run: |
121
+ sudo apt-get -yqq install libpq-dev
122
+ cd apps/worker
123
+ gem install bundler
124
+ bundle install --jobs 4 --retry 3
125
+ bundle exec rake db:create RACK_ENV=test
126
+ bundle exec rake db:migrate RACK_ENV=test
127
+ bundle exec rspec
128
+
129
+ - name: Checkout the repository
130
+ uses: actions/checkout@v2
131
+
132
+ - name: GCP Authenticate
133
+ uses: google-github-actions/setup-gcloud@master
134
+ with:
135
+ version: "323.0.0"
136
+ project_id: ${{ secrets.GCP_PROJECT_ID }}
137
+ service_account_key: ${{ secrets.GCP_SA_KEY }}
138
+ export_default_credentials: true
139
+
140
+ - name: Configure Docker
141
+ run: gcloud auth configure-docker --quiet
142
+
143
+ - name: Build Docker container
144
+ run: docker build -f ./apps/#{worker_name}/Dockerfile ./apps/#{worker_name} -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{secrets.APP_NAME}}-#{worker_name}
145
+
146
+ - name: Push to Container Resistory
147
+ run: docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{secrets.APP_NAME}}-#{worker_name}
148
+
149
+ - name: Deploy to Cloud Run
150
+ run: |
151
+ gcloud run deploy ${{ secrets.APP_NAME }}-#{worker_name} \\
152
+ --service-account=${{ secrets.APP_NAME }}@${{ secrets.GCP_PROJECT_ID }}.iam.gserviceaccount.com \\
153
+ --image=gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{secrets.APP_NAME}}-#{worker_name} \\
154
+ --memory=4Gi \\
155
+ --region=asia-northeast1 \\
156
+ --allow-unauthenticated \\
157
+ --platform=managed \\
158
+ --quiet \\
159
+ --concurrency=80 \\
160
+ --port=8080 \\
161
+ --set-cloudsql-instances=${{ secrets.GCLOUDSQL_INSTANCE }} \\
162
+ --set-env-vars="DB_USER=${{ secrets.DB_USER }}" \\
163
+ --set-env-vars="DB_PW=${{ secrets.DB_PW }}" \\
164
+ --set-env-vars="DB_HOST=${{ secrets.DB_HOST }}" \\
165
+ --set-env-vars="TZ=${{ secrets.TZ }}" \\
166
+ --set-env-vars="SLACK=${{ secrets.SLACK }}" \\
167
+ --set-env-vars="SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}" \\
168
+ --set-env-vars="PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}"
169
+ TEXT
170
+ end
171
+ puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
172
+ file_path
173
+ rescue StandardError => e
174
+ raise(StandardError, e)
175
+ end
176
+
177
+ def souls_config_init(worker_name: "mailer")
178
+ app_name = Souls.configuration.app_name
179
+ project_id = Souls.configuration.project_id
180
+ config_dir = "apps/#{worker_name}/config"
181
+ FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir)
182
+ FileUtils.touch("#{config_dir}/souls.rb")
183
+ file_path = "#{config_dir}/souls.rb"
184
+ File.open(file_path, "w") do |f|
185
+ f.write(<<~TEXT)
186
+ Souls.configure do |config|
187
+ config.app = "#{app_name}"
188
+ config.project_id = "#{project_id}"
189
+ config.strain = "worker"
190
+ config.fixed_gems = ["excluded_gem"]
191
+ config.workers = []
192
+ end
193
+ TEXT
194
+ end
195
+ rescue StandardError => e
196
+ puts(e)
197
+ end
198
+
199
+ def download_worker(worker_name: "mailer")
200
+ raise(StandardError, "Can't use `worker` for worker. Change Name.") if worker_name == "worker"
201
+
202
+ current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
203
+ wrong_dir = %w[apps api worker]
204
+ if wrong_dir.include?(current_dir_name)
205
+ raise(StandardError, "You are at wrong directory!Go to Mother Directory!")
206
+ end
207
+
208
+ version = Souls.get_latest_version_txt(service_name: "worker").join(".")
209
+ file_name = "worker-v#{version}.tgz"
210
+ url = "https://storage.googleapis.com/souls-bucket/boilerplates/workers/#{file_name}"
211
+ system("curl -OL #{url}")
212
+ system("tar -zxvf ./#{file_name} -C ./apps/")
213
+ system("mv apps/worker apps/#{worker_name}")
214
+ system("cp ./apps/api/config/database.yml ./apps/#{worker_name}/config/")
215
+ FileUtils.rm(file_name)
216
+ end
217
+ end
218
+ end
219
+ end
@@ -44,7 +44,7 @@ module Souls
44
44
 
45
45
  def create_connector(app_name: "", region: "asia-northeast1")
46
46
  app_name = Souls.configuration.app if app_name.blank?
47
- project_id = Souls.configuration.app if project_id.blank?
47
+ project_id = Souls.configuration.project_id
48
48
  system(
49
49
  "gcloud compute networks vpc-access connectors create #{app_name}-connector \
50
50
  --region=#{region} \
@@ -73,7 +73,7 @@ module Souls
73
73
  system("gcloud compute network list")
74
74
  end
75
75
 
76
- def nat_credit(app_name: "", worker_name: "mailer")
76
+ def nat_credit(app_name: "")
77
77
  app_name = Souls.configuration.app if app_name.blank?
78
78
  line = Paint["====================================", :yellow]
79
79
  puts("\n")
@@ -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.3".freeze
2
+ VERSION = "0.36.2".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.14.3
1
+ 0.15.2
@@ -1 +1 @@
1
- 0.14.3
1
+ 0.15.2
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.3
4
+ version: 0.36.2
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 ワークフローを標準装備。開発者がビジネスロジックに集中し、楽しくコードが書けるような環境を目指しています。