souls 0.30.10 → 0.32.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.
- checksums.yaml +4 -4
- data/README.md +13 -9
- data/exe/souls +56 -40
- data/lib/souls.rb +0 -183
- data/lib/souls/api/generate/application.rb +3 -21
- data/lib/souls/api/update/rspec_mutation.rb +1 -3
- data/lib/souls/api/update/rspec_resolver.rb +0 -2
- data/lib/souls/cli.rb +2 -0
- data/lib/souls/cli/docker/docker.rb +12 -0
- data/lib/souls/cli/gcloud.rb +2 -2
- data/lib/souls/cli/gcloud/{compute.rb → gcloud.rb} +0 -8
- data/lib/souls/cli/gcloud/iam.rb +3 -73
- data/lib/souls/cli/gcloud/iam/iam.rb +80 -0
- data/lib/souls/cli/gcloud/pubsub.rb +4 -28
- data/lib/souls/cli/gcloud/pubsub/subscriptions.rb +31 -0
- data/lib/souls/cli/gcloud/pubsub/topics.rb +11 -0
- data/lib/souls/cli/gcloud/run.rb +4 -11
- data/lib/souls/cli/gcloud/run/run.rb +18 -0
- data/lib/souls/cli/gcloud/sql.rb +9 -0
- data/lib/souls/cli/gcloud/sql/sql.rb +15 -0
- data/lib/souls/cli/sync.rb +6 -0
- data/lib/souls/cli/sync/model.rb +87 -0
- data/lib/souls/cli/upgrade.rb +5 -0
- data/lib/souls/cli/upgrade/gem_update.rb +107 -0
- 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
- data/lib/souls/worker/generate.rb +0 -1
- data/lib/souls/worker/generate/mailer.rb +0 -5
- metadata +20 -16
- data/lib/souls/cli/gcloud/methods.rb +0 -69
- data/lib/souls/worker/generate/application.rb +0 -150
@@ -49,8 +49,6 @@ module Souls
|
|
49
49
|
type = Souls::Api::Generate.type_check(col[:type])
|
50
50
|
text =
|
51
51
|
case type
|
52
|
-
when "String"
|
53
|
-
col[:array] ? "be_all(String)" : "be_a(String)"
|
54
52
|
when "Integer", "Float"
|
55
53
|
col[:array] ? "be_all(Integer)" : "be_a(Integer)"
|
56
54
|
when "Boolean"
|
@@ -59,7 +57,7 @@ module Souls
|
|
59
57
|
col[:array] ? "be_all(String)" : "be_a(String)"
|
60
58
|
end
|
61
59
|
unless test_args.include?(col[:column_name])
|
62
|
-
new_line.write("
|
60
|
+
new_line.write(" \"#{col[:column_name].camelize(:lower)}\" => #{text},\n")
|
63
61
|
end
|
64
62
|
end
|
65
63
|
test_res = false
|
data/lib/souls/cli.rb
CHANGED
@@ -26,6 +26,18 @@ module Souls
|
|
26
26
|
)
|
27
27
|
system("docker ps")
|
28
28
|
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
|
32
|
+
port =
|
33
|
+
if current_dir_name == "api"
|
34
|
+
"4000:4000"
|
35
|
+
else
|
36
|
+
"3000:3000"
|
37
|
+
end
|
38
|
+
system("docker build . -t souls-app -f Dockerfile.dev")
|
39
|
+
system("docker run --name souls-app --rm --env-file .env -p #{port} souls-app:latest")
|
40
|
+
end
|
29
41
|
end
|
30
42
|
end
|
31
43
|
end
|
data/lib/souls/cli/gcloud.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative "./gcloud/compute"
|
2
1
|
require_relative "./gcloud/iam"
|
3
2
|
require_relative "./gcloud/pubsub"
|
4
|
-
require_relative "./gcloud/methods"
|
5
3
|
require_relative "./gcloud/run"
|
4
|
+
require_relative "./gcloud/sql"
|
5
|
+
require_relative "./gcloud/gcloud"
|
6
6
|
|
7
7
|
module Souls
|
8
8
|
module Gcloud
|
@@ -24,14 +24,6 @@ module Souls
|
|
24
24
|
system("gcloud services enable run.googleapis.com")
|
25
25
|
puts("Operating permission to run.googleapis.com")
|
26
26
|
end
|
27
|
-
|
28
|
-
def create_sql_instance(instance_name: "souls-db", root_pass: "Postgre123!", zone: "asia-northeast1-b")
|
29
|
-
system(
|
30
|
-
"gcloud sql instances create #{instance_name}
|
31
|
-
--database-version=POSTGRES_13 --cpu=2 --memory=7680MB --zone=#{zone}
|
32
|
-
--root-password='#{root_pass}' --database-flags cloudsql.iam_authentication=on"
|
33
|
-
)
|
34
|
-
end
|
35
27
|
end
|
36
28
|
end
|
37
29
|
end
|
data/lib/souls/cli/gcloud/iam.rb
CHANGED
@@ -1,78 +1,8 @@
|
|
1
|
+
require_relative "./iam/iam"
|
2
|
+
|
1
3
|
module Souls
|
2
4
|
module Gcloud
|
3
|
-
|
4
|
-
def create_service_account(service_account: "souls-app")
|
5
|
-
system(
|
6
|
-
"gcloud iam service-accounts create #{service_account} \
|
7
|
-
--description='Souls Service Account' \
|
8
|
-
--display-name=#{service_account}"
|
9
|
-
)
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_service_account_key(service_account: "souls-app", project_id: "souls-app")
|
13
|
-
system(
|
14
|
-
"gcloud iam service-accounts keys create ./config/keyfile.json \
|
15
|
-
--iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com"
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
def export_key_to_console
|
20
|
-
github_repo = Souls.configuration.github_repo || "elsoul/souls"
|
21
|
-
file_path = "config/keyfile.json"
|
22
|
-
puts(Paint["======= below(ここから)=======", :cyan])
|
23
|
-
text = []
|
24
|
-
File.open(file_path, "r") do |line|
|
25
|
-
line.each_line do |l|
|
26
|
-
text << l
|
27
|
-
end
|
28
|
-
end
|
29
|
-
key = text.join(",").gsub(/^,/, "").chomp!
|
30
|
-
puts(Paint[key, :white])
|
31
|
-
puts(Paint["======= above(ここまで)=======", :cyan])
|
32
|
-
github_secret_url = "https://github.com/#{github_repo}/settings/secrets/actions"
|
33
|
-
souls_doc_url = "https://souls.elsoul.nl/docs/chapter2/#43-github-シークレットキーの登録"
|
34
|
-
txt1 = <<~TEXT
|
35
|
-
|
36
|
-
⬆⬆⬆ Copy the service account key above ⬆⬆⬆⬆
|
37
|
-
|
38
|
-
And
|
39
|
-
|
40
|
-
Go to %{yellow_text}
|
41
|
-
|
42
|
-
Reference: %{yellow_text2}
|
43
|
-
TEXT
|
44
|
-
puts(
|
45
|
-
Paint % [
|
46
|
-
txt1,
|
47
|
-
:white,
|
48
|
-
{ yellow_text: [github_secret_url, :yellow], yellow_text2: [souls_doc_url, :yellow] }
|
49
|
-
]
|
50
|
-
)
|
51
|
-
FileUtils.rm(file_path)
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_service_account_role(service_account: "souls-app", project_id: "souls-app", role: "roles/firebase.admin")
|
55
|
-
system(
|
56
|
-
"gcloud projects add-iam-policy-binding #{project_id} \
|
57
|
-
--member='serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com' \
|
58
|
-
--role=#{role}"
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
def add_permissions(service_account: "souls-app", project_id: "souls-app")
|
63
|
-
roles = [
|
64
|
-
"roles/cloudsql.instanceUser",
|
65
|
-
"roles/containerregistry.ServiceAgent",
|
66
|
-
"roles/pubsub.serviceAdmin",
|
67
|
-
"roles/firestore.serviceAdmin",
|
68
|
-
"roles/iam.serviceAccountUser",
|
69
|
-
"roles/storage.objectAdmin",
|
70
|
-
"roles/run.admin"
|
71
|
-
]
|
72
|
-
roles.each do |role|
|
73
|
-
add_service_account_role(service_account: service_account, project_id: project_id, role: role)
|
74
|
-
end
|
75
|
-
end
|
5
|
+
module Iam
|
76
6
|
end
|
77
7
|
end
|
78
8
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Souls
|
2
|
+
module Gcloud
|
3
|
+
module Iam
|
4
|
+
class << self
|
5
|
+
def create_service_account(service_account: "souls-app")
|
6
|
+
system(
|
7
|
+
"gcloud iam service-accounts create #{service_account} \
|
8
|
+
--description='Souls Service Account' \
|
9
|
+
--display-name=#{service_account}"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_service_account_key(service_account: "souls-app", project_id: "souls-app")
|
14
|
+
system(
|
15
|
+
"gcloud iam service-accounts keys create ./config/keyfile.json \
|
16
|
+
--iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def export_key_to_console
|
21
|
+
github_repo = Souls.configuration.github_repo || "elsoul/souls"
|
22
|
+
file_path = "config/keyfile.json"
|
23
|
+
puts(Paint["======= below(ここから)=======", :cyan])
|
24
|
+
text = []
|
25
|
+
File.open(file_path, "r") do |line|
|
26
|
+
line.each_line do |l|
|
27
|
+
text << l
|
28
|
+
end
|
29
|
+
end
|
30
|
+
key = text.join(",").gsub(/^,/, "").chomp!
|
31
|
+
puts(Paint[key, :white])
|
32
|
+
puts(Paint["======= above(ここまで)=======", :cyan])
|
33
|
+
github_secret_url = "https://github.com/#{github_repo}/settings/secrets/actions"
|
34
|
+
souls_doc_url = "https://souls.elsoul.nl/docs/tutorial/zero-to-deploy/#43-github-シークレットキーの登録"
|
35
|
+
txt1 = <<~TEXT
|
36
|
+
|
37
|
+
⬆⬆⬆ Copy the service account key above ⬆⬆⬆⬆
|
38
|
+
|
39
|
+
And
|
40
|
+
|
41
|
+
Go to %{yellow_text}
|
42
|
+
|
43
|
+
Reference: %{yellow_text2}
|
44
|
+
TEXT
|
45
|
+
puts(
|
46
|
+
Paint % [
|
47
|
+
txt1,
|
48
|
+
:white,
|
49
|
+
{ yellow_text: [github_secret_url, :yellow], yellow_text2: [souls_doc_url, :yellow] }
|
50
|
+
]
|
51
|
+
)
|
52
|
+
FileUtils.rm(file_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_service_account_role(service_account: "souls-app", project_id: "souls-app", role: "roles/firebase.admin")
|
56
|
+
system(
|
57
|
+
"gcloud projects add-iam-policy-binding #{project_id} \
|
58
|
+
--member='serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com' \
|
59
|
+
--role=#{role}"
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_permissions(service_account: "souls-app", project_id: "souls-app")
|
64
|
+
roles = [
|
65
|
+
"roles/cloudsql.instanceUser",
|
66
|
+
"roles/containerregistry.ServiceAgent",
|
67
|
+
"roles/pubsub.serviceAdmin",
|
68
|
+
"roles/firestore.serviceAdmin",
|
69
|
+
"roles/iam.serviceAccountUser",
|
70
|
+
"roles/storage.objectAdmin",
|
71
|
+
"roles/run.admin"
|
72
|
+
]
|
73
|
+
roles.each do |role|
|
74
|
+
add_service_account_role(service_account: service_account, project_id: project_id, role: role)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -1,33 +1,9 @@
|
|
1
|
+
require_relative "./pubsub/topics"
|
2
|
+
require_relative "./pubsub/subscriptions"
|
3
|
+
|
1
4
|
module Souls
|
2
5
|
module Gcloud
|
3
|
-
|
4
|
-
def create_pubsub_topic(topic_name: "send-user-mail")
|
5
|
-
system("gcloud pubsub topics create #{topic_name}")
|
6
|
-
end
|
7
|
-
|
8
|
-
def create_pubsub_subscription(
|
9
|
-
topic_name: "send-user-mail",
|
10
|
-
project_id: "souls-app",
|
11
|
-
service_account: "souls-app",
|
12
|
-
endpoint: "https:://test.com"
|
13
|
-
)
|
14
|
-
system(
|
15
|
-
"gcloud pubsub subscriptions create #{topic_name}-sub \
|
16
|
-
--topic #{topic_name} \
|
17
|
-
--topic-project #{project_id} \
|
18
|
-
--push-auth-service-account #{service_account} \
|
19
|
-
--push-endpoint #{endpoint} \
|
20
|
-
--expiration-period never
|
21
|
-
"
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
def update_pubsub_subscription(
|
26
|
-
topic_name: "send-user-mail",
|
27
|
-
endpoint: "https:://test.com"
|
28
|
-
)
|
29
|
-
system("gcloud pubsub subscriptions update #{topic_name}-sub --push-endpoint #{endpoint} ")
|
30
|
-
end
|
6
|
+
module Pubsub
|
31
7
|
end
|
32
8
|
end
|
33
9
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Souls
|
2
|
+
module Gcloud
|
3
|
+
module Pubsub
|
4
|
+
class << self
|
5
|
+
def create_subscription(
|
6
|
+
topic_name: "send-user-mail",
|
7
|
+
project_id: "souls-app",
|
8
|
+
service_account: "souls-app",
|
9
|
+
endpoint: "https:://test.com"
|
10
|
+
)
|
11
|
+
system(
|
12
|
+
"gcloud pubsub subscriptions create #{topic_name}-sub \
|
13
|
+
--topic #{topic_name} \
|
14
|
+
--topic-project #{project_id} \
|
15
|
+
--push-auth-service-account #{service_account} \
|
16
|
+
--push-endpoint #{endpoint} \
|
17
|
+
--expiration-period never
|
18
|
+
"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update_subscription(
|
23
|
+
topic_name: "send-user-mail",
|
24
|
+
endpoint: "https:://test.com"
|
25
|
+
)
|
26
|
+
system("gcloud pubsub subscriptions update #{topic_name}-sub --push-endpoint #{endpoint} ")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/souls/cli/gcloud/run.rb
CHANGED
@@ -1,16 +1,9 @@
|
|
1
|
+
require_relative "./run/run"
|
2
|
+
|
1
3
|
module Souls
|
2
4
|
module Gcloud
|
3
|
-
|
4
|
-
def run_awake(app_name: "souls-app", url: "")
|
5
|
-
system(
|
6
|
-
"gcloud scheduler jobs create http #{app_name}-awake
|
7
|
-
--schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
|
8
|
-
)
|
9
|
-
end
|
10
|
-
|
11
|
-
def run_list(project_id: "souls-app")
|
12
|
-
system("gcloud run services list --project #{project_id}")
|
13
|
-
end
|
5
|
+
module Run
|
14
6
|
end
|
15
7
|
end
|
16
8
|
end
|
9
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Souls
|
2
|
+
module Gcloud
|
3
|
+
module Run
|
4
|
+
class << self
|
5
|
+
def awake(app_name: "souls-app", url: "")
|
6
|
+
system(
|
7
|
+
"gcloud scheduler jobs create http #{app_name}-awake
|
8
|
+
--schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(project_id: "souls-app")
|
13
|
+
system("gcloud run services list --project #{project_id}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Souls
|
2
|
+
module Gcloud
|
3
|
+
module Sql
|
4
|
+
class << self
|
5
|
+
def create_instance(instance_name: "souls-db", root_pass: "Postgre123!", zone: "asia-northeast1-b")
|
6
|
+
system(
|
7
|
+
"gcloud sql instances create #{instance_name}
|
8
|
+
--database-version=POSTGRES_13 --cpu=2 --memory=7680MB --zone=#{zone}
|
9
|
+
--root-password='#{root_pass}' --database-flags cloudsql.iam_authentication=on"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Souls
|
2
|
+
module Sync
|
3
|
+
class << self
|
4
|
+
def model
|
5
|
+
current_dir_name = FileUtils.pwd.to_s.match(%r{/([^/]+)/?$})[1]
|
6
|
+
permitted_dirs = %w[worker api]
|
7
|
+
unless permitted_dirs.include?(current_dir_name)
|
8
|
+
raise(StandardError, "You are at wrong directory!Go to API or Worker Directory!")
|
9
|
+
end
|
10
|
+
|
11
|
+
cp_dir = get_models_path(service_name: current_dir_name)
|
12
|
+
cp_dir.each do |path|
|
13
|
+
cp_and_dl_files(api_dir: path[:api], worker_dir: path[:worker])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def file_diff(paths = [])
|
20
|
+
paths.map do |path|
|
21
|
+
stat(path)[:last_update]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def stat(path)
|
26
|
+
s = File::Stat.new(path)
|
27
|
+
last_update = s.mtime.to_s
|
28
|
+
last_status_change = s.ctime.to_s
|
29
|
+
last_access = s.atime.to_s
|
30
|
+
{
|
31
|
+
last_update: last_update,
|
32
|
+
last_status_change: last_status_change,
|
33
|
+
last_access: last_access
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def cp_and_dl_files(api_dir: "", worker_dir: "")
|
38
|
+
if Dir["#{worker_dir}/*.rb"].blank?
|
39
|
+
|
40
|
+
api_latest_date = 1
|
41
|
+
worker_latest_date = 0
|
42
|
+
else
|
43
|
+
api_file_data = file_diff(Dir["#{api_dir}/*.rb"])
|
44
|
+
worker_file_data = file_diff(Dir["#{worker_dir}/*.rb"])
|
45
|
+
|
46
|
+
api_latest_date = Date.parse(api_file_data.max)
|
47
|
+
worker_latest_date = Date.parse(worker_file_data.max)
|
48
|
+
end
|
49
|
+
|
50
|
+
if api_latest_date < worker_latest_date
|
51
|
+
FileUtils.rm_rf(api_dir) if Dir.exist?(api_dir)
|
52
|
+
FileUtils.mkdir(api_dir) unless Dir.exist?(api_dir)
|
53
|
+
system("cp -r #{worker_dir}/* #{api_dir}")
|
54
|
+
else
|
55
|
+
FileUtils.rm_rf(worker_dir) if Dir.exist?(worker_dir)
|
56
|
+
FileUtils.mkdir(worker_dir) unless Dir.exist?(worker_dir)
|
57
|
+
system("cp -r #{api_dir}/* #{worker_dir}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_models_path(service_name: "api")
|
62
|
+
case service_name
|
63
|
+
when "api"
|
64
|
+
api_path = "."
|
65
|
+
worker_path = "../worker"
|
66
|
+
when "worker"
|
67
|
+
api_path = "../api"
|
68
|
+
worker_path = "."
|
69
|
+
end
|
70
|
+
[
|
71
|
+
{
|
72
|
+
api: "#{api_path}/db",
|
73
|
+
worker: "#{worker_path}/db"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
api: "#{api_path}/app/models",
|
77
|
+
worker: "#{worker_path}/app/models"
|
78
|
+
},
|
79
|
+
{
|
80
|
+
api: "#{api_path}/spec/factories",
|
81
|
+
worker: "#{worker_path}/spec/factories"
|
82
|
+
}
|
83
|
+
]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|