souls 0.35.4 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/souls +2 -1
- data/lib/souls/cli/create/index.rb +190 -0
- data/lib/souls/cli/gcloud/compute/index.rb +3 -2
- data/lib/souls/init.rb +0 -50
- data/lib/souls/version.rb +1 -1
- data/lib/souls/versions/.souls_api_version +1 -1
- data/lib/souls/versions/.souls_worker_version +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c1c6b1311ed1f41d5bf6ee189cda8e899569c68957a51c107861f7986e3218
|
4
|
+
data.tar.gz: 80825c655e0c14a5459e7918c69f6bc3857dc6777dd5490d7c6c983429b818cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b09fb73a8d2f35f440e268d8b97198f2a3fb77e8c028cfad52424a7d46b66d45f409327ddcb48139cdc5cbe6f4d2bf802ccc21a8219ad98e41aa0dfd8e84d562
|
7
|
+
data.tar.gz: 3888d33a67abfdc22d56c7e83a997d322983bcb282a781d35f01bfb5d034495e89c3782853a848b1a2e797923ecdcf766ada94840fae7d856159fdad52978a99
|
data/exe/souls
CHANGED
@@ -1,6 +1,196 @@
|
|
1
1
|
module Souls
|
2
2
|
module Create
|
3
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 = "tmp/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
|
+
break 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
|
+
worker_switch = false
|
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
|
4
194
|
end
|
5
195
|
end
|
6
196
|
end
|
@@ -44,10 +44,11 @@ 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.project_id
|
47
48
|
system(
|
48
49
|
"gcloud compute networks vpc-access connectors create #{app_name}-connector \
|
49
50
|
--region=#{region} \
|
50
|
-
--subnet-project=#{
|
51
|
+
--subnet-project=#{project_id} \
|
51
52
|
--subnet=#{app_name}-subnet"
|
52
53
|
)
|
53
54
|
end
|
@@ -72,7 +73,7 @@ module Souls
|
|
72
73
|
system("gcloud compute network list")
|
73
74
|
end
|
74
75
|
|
75
|
-
def nat_credit(app_name: ""
|
76
|
+
def nat_credit(app_name: "")
|
76
77
|
app_name = Souls.configuration.app if app_name.blank?
|
77
78
|
line = Paint["====================================", :yellow]
|
78
79
|
puts("\n")
|
data/lib/souls/init.rb
CHANGED
@@ -147,55 +147,5 @@ module Souls
|
|
147
147
|
puts(cd)
|
148
148
|
puts(line)
|
149
149
|
end
|
150
|
-
|
151
|
-
def self.download_worker
|
152
|
-
current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
|
153
|
-
wrong_dir = %w[apps api worker]
|
154
|
-
raise(StandardError, "You are at wrong directory!Go to Mother Directory!") if wrong_dir.include?(current_dir_name)
|
155
|
-
|
156
|
-
version = Souls.get_latest_version_txt(service_name: "worker").join(".")
|
157
|
-
file_name = "worker-v#{version}.tgz"
|
158
|
-
url = "https://storage.googleapis.com/souls-bucket/boilerplates/workers/#{file_name}"
|
159
|
-
system("curl -OL #{url}")
|
160
|
-
system("mkdir -p ./apps/worker")
|
161
|
-
system("tar -zxvf ./#{file_name} -C ./apps/")
|
162
|
-
system("cp ./apps/api/config/database.yml ./apps/worker/config/")
|
163
|
-
FileUtils.rm(file_name)
|
164
|
-
line = Paint["====================================", :yellow]
|
165
|
-
puts("\n")
|
166
|
-
puts(line)
|
167
|
-
txt2 = <<~TEXT
|
168
|
-
_____ ____ __ ____#{' '}
|
169
|
-
/ ___// __ \\/ / / / / %{red1}
|
170
|
-
\\__ \\/ / / / / / / / %{red2}
|
171
|
-
___/ / /_/ / /_/ / /___%{red3}#{' '}
|
172
|
-
/____/\\____/\\____/_____%{red4}#{' '}
|
173
|
-
TEXT
|
174
|
-
red1 = ["_____", :red]
|
175
|
-
red2 = ["/ ___/", :red]
|
176
|
-
red3 = ["(__ )", :red]
|
177
|
-
red4 = ["/____/", :red]
|
178
|
-
ms = Paint % [txt2, :cyan, { red1: red1, red2: red2, red3: red3, red4: red4 }]
|
179
|
-
puts(ms)
|
180
|
-
puts(line)
|
181
|
-
welcome = Paint["SOULs Worker Activated!", :white]
|
182
|
-
puts(welcome)
|
183
|
-
souls_ver = Paint["SOULs Version: #{Souls::VERSION}", :white]
|
184
|
-
puts(souls_ver)
|
185
|
-
puts(line)
|
186
|
-
endroll = <<~TEXT
|
187
|
-
Easy to Run
|
188
|
-
$ cd ./apps/worker
|
189
|
-
$ bundle
|
190
|
-
$ souls sync model
|
191
|
-
$ souls s
|
192
|
-
Go To : http://localhost:3000
|
193
|
-
|
194
|
-
Doc: https://souls.elsoul.nl
|
195
|
-
TEXT
|
196
|
-
cd = Paint[endroll, :white]
|
197
|
-
puts(cd)
|
198
|
-
puts(line)
|
199
|
-
end
|
200
150
|
end
|
201
151
|
end
|
data/lib/souls/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.15.0
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.15.0
|
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.
|
4
|
+
version: 0.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- POPPIN-FUMI
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|