souls 1.19.0 → 1.19.4

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: 02be7d892a5a7f988aa1d288eff6b847276d9462308d202752efc05e67b3accb
4
- data.tar.gz: 8ada002457f6c26f80d6fca80b104f5f6c92916a4582d8a95ff8e24523b80f21
3
+ metadata.gz: 6cd5ddd6a55b4b803fc8e815afdf4fbb27d638ae1ef7cd6714d1205b8c4c3818
4
+ data.tar.gz: 00f110a29e05dda4a3790c128ba9f9ff0b019057874009766e2cd18cab426dc4
5
5
  SHA512:
6
- metadata.gz: bab193ff10c201eacbdbdfc99bb986f090c82e07be29390bd95c36a4dee4a8f0ec07c970aff7721d5bebe67140ed68b79dc2a284614a5c233f568a077539ec1c
7
- data.tar.gz: 965f2d31ed0964ccfd2b6ebb00dc67de567ac17c13beb07c5452acf27b1d57119d4ea0b7dee1c5e0577a820affd59b8c2bdbf857cdcdaccd535c424682aeab3f
6
+ metadata.gz: fcaa0f1b6d9f1ca3dc20ef00a8550362c3bed338141cdb60cdde0e655dcc93185d4f8af738fac82a549ed27cf3198532c94009f27e8522eade002bd82cb2b109
7
+ data.tar.gz: c6c7a35a0d1ba0f8fb5797e61081f567a4627935d465e1756da524e983a81f1136623b95e98067248393be75b13129efab3d627d67ab27043bc0322d68e748fa
@@ -21,7 +21,7 @@ module SOULs
21
21
  version = prompt.select("Select Version?", supported_languages[runtime.downcase.to_sym].sort.reverse)
22
22
  version_string = "#{runtime_downcased}#{version.gsub('.', '')}"
23
23
  runtime_methods = get_runtime_create_method(runtime: runtime_downcased)
24
- file_dir = "./apps/cf_#{version_string}_#{function_name}"
24
+ file_dir = "./apps/cf-#{version_string}-#{function_name}"
25
25
  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
26
26
 
27
27
  runtime_methods.each do |method|
@@ -170,12 +170,12 @@ end
170
170
  bundle exec rake db:migrate RACK_ENV=test
171
171
  bundle exec rspec
172
172
 
173
- - name: Sync Tasks
174
- run: cd apps/#{worker_name} && souls gcloud scheduler sync_schedules --timezone=${{ secrets.TZ }}
175
-
176
173
  - name: Sync PubSub
177
174
  run: cd apps/#{worker_name} && souls sync pubsub
178
175
 
176
+ - name: Sync Tasks
177
+ run: cd apps/#{worker_name} && souls gcloud scheduler sync_schedules --timezone=${{ secrets.TZ }}
178
+
179
179
  - name: Configure Docker
180
180
  run: gcloud auth configure-docker --quiet
181
181
 
@@ -1,6 +1,7 @@
1
1
  module Template
2
2
  module Go
3
3
  def self.function(file_name)
4
+ file_name.underscore.camelize
4
5
  <<~APP
5
6
  // Package p contains an HTTP Cloud Function.
6
7
  package p
@@ -1,6 +1,7 @@
1
1
  module Template
2
2
  module Nodejs
3
3
  def self.index(file_name)
4
+ file_name.underscore.camelize(:lower)
4
5
  <<~APP
5
6
  const express = require('express');
6
7
  const bodyParser = require('body-parser');
@@ -1,6 +1,7 @@
1
1
  module Template
2
2
  module Python
3
3
  def self.main(file_name)
4
+ file_name.underscore
4
5
  <<~APP
5
6
  def #{file_name}(request):
6
7
  """Responds to any HTTP request.
@@ -5,12 +5,12 @@ module SOULs
5
5
  require(SOULs.get_mother_path.to_s + "/config/souls")
6
6
  project_id = SOULs.configuration.project_id
7
7
  current_dir = FileUtils.pwd.split("/").last
8
- unless current_dir.match?(/^cf_/)
8
+ unless current_dir.match?(/^cf-/)
9
9
  SOULs::Painter.error("You are at wrong dir!\nPlease go to `apps/functions` dir!")
10
10
  return false
11
11
  end
12
12
 
13
- runtime = current_dir.match(/cf_(\D+\d+)_/)[1]
13
+ runtime = current_dir.match(/cf-(\D+\d+)-/)[1]
14
14
  system(
15
15
  "
16
16
  gcloud functions deploy #{current_dir} --project=#{project_id} \
@@ -22,11 +22,12 @@ module SOULs
22
22
  desc "describe", "Describe SOULs Functions"
23
23
  def describe
24
24
  require(SOULs.get_mother_path.to_s + "/config/souls")
25
+ current_dir = FileUtils.pwd.split("/").last
25
26
  project_id = SOULs.configuration.project_id
26
- system("gcloud functions describe souls_functions --project=#{project_id}")
27
+ system("gcloud functions describe #{current_dir} --project=#{project_id}")
27
28
  end
28
29
 
29
- desc "delete", "Delete SOULs Functions"
30
+ desc "delete [name]", "Delete SOULs Functions"
30
31
  def delete(name)
31
32
  require(SOULs.get_mother_path.to_s + "/config/souls")
32
33
  project_id = SOULs.configuration.project_id
@@ -50,7 +51,7 @@ module SOULs
50
51
  require(SOULs.get_mother_path.to_s + "/config/souls")
51
52
  project_id = SOULs.configuration.project_id
52
53
  Dir.chdir(SOULs.get_mother_path.to_s) do
53
- souls_functions = Dir["apps/cf_*"]
54
+ souls_functions = Dir["apps/cf-*"]
54
55
  cf_dir = souls_functions.map { |n| n.split("/").last }
55
56
  cf_dir.each do |dir|
56
57
  SOULs::Painter.success(`gcloud functions describe #{dir} --project=#{project_id}| grep url`)
@@ -2,23 +2,28 @@ module SOULs
2
2
  class Iam < Thor
3
3
  desc "setup_key", "Create Google Cloud IAM Service Account Key And Set All Permissions"
4
4
  def setup_key
5
- region = SOULs.configuration.region
6
- SOULs::Gcloud.new.auth_login
7
- SOULs::Upgrade.new.config
8
- create_service_account
9
- create_service_account_key
10
- SOULs::Gcloud.new.enable_permissions
11
- add_permissions
12
- begin
13
- system("gcloud app create --region=#{region} --quiet")
14
- rescue StandardError, error
15
- puts("gcloud app region is Already exist! - SOULs::Gcloud::Iam.setup_key")
16
- end
17
- begin
18
- set_gh_secret_json
19
- rescue StandardError
20
- export_key_to_console
5
+ Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
6
+ Whirly.status = "Setting up credentials and permissions..."
7
+ region = SOULs.configuration.region
8
+ SOULs::Gcloud.new.auth_login
9
+ SOULs::Upgrade.new.config
10
+ create_service_account
11
+ create_service_account_key
12
+ SOULs::Gcloud.new.enable_permissions
13
+ add_permissions
14
+ begin
15
+ system("gcloud app create --region=#{region} --quiet")
16
+ rescue StandardError, error
17
+ puts("gcloud app region is Already exist! - SOULs::Gcloud::Iam.setup_key")
18
+ end
19
+ begin
20
+ set_gh_secret_json
21
+ rescue StandardError
22
+ export_key_to_console
23
+ end
21
24
  end
25
+ SOULs::Painter.success("You're all set!")
26
+ true
22
27
  end
23
28
 
24
29
  private
@@ -62,6 +62,7 @@ module SOULs
62
62
  system("gcloud services enable cloudresourcemanager.googleapis.com")
63
63
  system("gcloud services enable translate.googleapis.com")
64
64
  system("gcloud services enable firestore.googleapis.com")
65
+ system("gcloud services enable cloudfunctions.googleapis.com")
65
66
  end
66
67
  end
67
68
  end
@@ -6,7 +6,6 @@ module SOULs
6
6
  def create_instance
7
7
  prompt = TTY::Prompt.new
8
8
  password = prompt.mask("Set DB PassWord:")
9
- app_name = SOULs.configuration.app
10
9
  project_id = SOULs.configuration.project_id
11
10
  instance_name = SOULs.configuration.instance_name
12
11
  region = SOULs.configuration.region if options[:region].blank?
@@ -20,43 +19,57 @@ module SOULs
20
19
  --database-version=#{db_type} --cpu=1 --memory=4096MB --zone=#{zone} \
21
20
  --root-password='#{password}' --database-flags cloudsql.iam_authentication=on"
22
21
  )
23
- instance_ip = `gcloud sql instances list | grep #{instance_name} | awk '{print $5}'`.strip
24
- Dir.chdir(SOULs.get_api_path.to_s) do
25
- file_path = ".env"
26
- File.open(file_path, "w") do |line|
27
- line.write(<<~TEXT)
28
- GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS=1
29
- SOULS_DB_HOST=#{instance_ip}
30
- SOULS_DB_PW=#{password}
31
- SOULS_DB_USER=postgres
32
- SOULS_GCP_PROJECT_ID=#{project_id}
33
- SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
34
- TZ="#{region_to_timezone(region: region)}"
35
- TEXT
36
- end
37
- end
38
- Dir.chdir(SOULs.get_mother_path.to_s) do
39
- file_path = ".env.production"
40
- File.open(file_path, "w") do |line|
41
- line.write(<<~TEXT)
42
- SOULS_DB_HOST="/cloudsql/#{project_id}:#{region}:#{instance_name}"
43
- SOULS_DB_PW=#{password}
44
- SOULS_DB_USER=postgres
45
- SOULS_APP_NAME=#{app_name}
46
- SOULS_GCP_PROJECT_ID=#{project_id}
47
- SOULS_GCP_REGION=#{region}
48
- SOULS_GCLOUDSQL_INSTANCE="#{project_id}:#{region}:#{instance_name}"
49
- SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
50
- TZ="#{region_to_timezone(region: region)}"
51
- TEXT
52
- end
53
- end
22
+ SOULs::Sql.new.env(password: password)
54
23
  SOULs::Github.new.secret_set
55
24
  Whirly.status = Paint["Cloud SQL #{instance_name} is successfully created! You can push to deploy!", :green]
56
25
  end
57
26
  true
58
27
  end
59
28
 
29
+ desc "env", "Generate .env.production file to deploy"
30
+ def env(password: "Password")
31
+ require(SOULs.get_mother_path.to_s + "/config/souls")
32
+ project_id = SOULs.configuration.project_id
33
+ instance_name = SOULs.configuration.instance_name
34
+ region = SOULs.configuration.region
35
+ app_name = SOULs.configuration.app
36
+ prompt = TTY::Prompt.new
37
+ db_password = password == "Password" ? prompt.mask("Set DB PassWord:") : password
38
+ instance_ip = `gcloud sql instances list --project=#{project_id} | grep #{instance_name} | awk '{print $5}'`.strip
39
+ Dir.chdir(SOULs.get_api_path.to_s) do
40
+ file_path = ".env"
41
+ File.open(file_path, "w") do |line|
42
+ line.write(<<~TEXT)
43
+ GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS=1
44
+ SOULS_DB_HOST=#{instance_ip}
45
+ SOULS_DB_PW=#{db_password}
46
+ SOULS_DB_USER=postgres
47
+ SOULS_GCP_PROJECT_ID=#{project_id}
48
+ SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
49
+ TZ="#{region_to_timezone(region: region)}"
50
+ TEXT
51
+ end
52
+ SOULs::Painter.create_file(file_path)
53
+ end
54
+ Dir.chdir(SOULs.get_mother_path.to_s) do
55
+ file_path = ".env.production"
56
+ File.open(file_path, "w") do |line|
57
+ line.write(<<~TEXT)
58
+ SOULS_DB_HOST="/cloudsql/#{project_id}:#{region}:#{instance_name}"
59
+ SOULS_DB_PW=#{db_password}
60
+ SOULS_DB_USER=postgres
61
+ SOULS_APP_NAME=#{app_name}
62
+ SOULS_GCP_PROJECT_ID=#{project_id}
63
+ SOULS_GCP_REGION=#{region}
64
+ SOULS_GCLOUDSQL_INSTANCE="#{project_id}:#{region}:#{instance_name}"
65
+ SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
66
+ TZ="#{region_to_timezone(region: region)}"
67
+ TEXT
68
+ end
69
+ SOULs::Painter.create_file(file_path)
70
+ end
71
+ end
72
+
60
73
  desc "list", "Show Cloud SQL Instances List"
61
74
  def list
62
75
  system("gcloud sql instances list")
@@ -111,6 +124,7 @@ module SOULs
111
124
  desc "assgin_ip", "Add Current Grobal IP to White List"
112
125
  method_option :ip, default: "", aliases: "--ip", desc: "Adding IP to Google Cloud SQL White List: e.g.'11.11.1.1'"
113
126
  def assign_ip
127
+ require(SOULs.get_mother_path.to_s + "/config/souls")
114
128
  project_id = SOULs.configuration.project_id
115
129
  instance_name = SOULs.configuration.instance_name
116
130
  ips = []
@@ -126,12 +140,15 @@ module SOULs
126
140
  -H "Authorization: Bearer "$(gcloud auth print-access-token) \
127
141
  "https://sqladmin.googleapis.com/v1/projects/#{project_id}/instances/#{instance_name}?fields=settings"`
128
142
  )
129
- unless cloud_sql["settings"]["ipConfiguration"]["authorizedNetworks"].blank?
143
+ begin
144
+ cloud_sql["settings"]["ipConfiguration"]["authorizedNetworks"].blank?
130
145
  white_ips =
131
146
  cloud_sql["settings"]["ipConfiguration"]["authorizedNetworks"].map do |sql_ips|
132
147
  sql_ips["value"]
133
148
  end
134
149
  ips = (ips + white_ips).uniq
150
+ rescue StandardError => e
151
+ puts(e)
135
152
  end
136
153
  ips = ips.join(",")
137
154
  Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
@@ -2,6 +2,7 @@ module SOULs
2
2
  class Sync < Thor
3
3
  desc "pubsub", "Sync Worker Jobs & Google Cloud Pubsub Topics/Subscriptions"
4
4
  def pubsub
5
+ project_id = SOULs.configuration.project_id
5
6
  worker_name = FileUtils.pwd.split("/").last
6
7
 
7
8
  unless worker_name.match(/^worker-(\d|\w)+(-)*(\d|\w)+$/)
@@ -9,7 +10,8 @@ module SOULs
9
10
  return false
10
11
  end
11
12
 
12
- url = `gcloud run services list |grep souls-#{project_id}-#{worker_name}| awk '{print $4}'`.strip
13
+ url = `gcloud run services list --platform=managed \
14
+ --project=#{project_id} |grep souls-#{project_id}-#{worker_name}| awk '{print $4}'`.strip
13
15
  return false if url.blank?
14
16
 
15
17
  worker_file_names = get_workers_file_paths
@@ -55,7 +57,7 @@ module SOULs
55
57
  project_id = SOULs.configuration.project_id
56
58
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
57
59
  topic = pubsub.create_topic(topic_id.to_s)
58
- puts("Topic #{topic.name} created.")
60
+ SOULs::Painter.success("Topic #{topic.name} created.")
59
61
  end
60
62
 
61
63
  def delete_topic(topic_id: "worker-mailer")
@@ -63,7 +65,7 @@ module SOULs
63
65
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
64
66
  topic = pubsub.topic(topic_id.to_s)
65
67
  topic.delete
66
- puts("Topic #{topic_id} deleted.")
68
+ SOULs::Painter.error("Topic #{topic_id} deleted.")
67
69
  end
68
70
 
69
71
  def delete_subscription(topic_id: "worker-mailer")
@@ -85,7 +87,7 @@ module SOULs
85
87
  topic = pubsub.topic(topic_id)
86
88
  sub = topic.subscribe(subscription_id, endpoint: endpoint, deadline: 20)
87
89
  sub.expires_in = nil
88
- puts("Push subscription #{subscription_id} created.")
90
+ SOULs::Painter.success("Push subscription #{subscription_id} created.")
89
91
  end
90
92
 
91
93
  def get_workers_file_paths
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module SOULs
2
- VERSION = "1.19.0".freeze
2
+ VERSION = "1.19.4".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 1.19.0
1
+ 1.19.4
@@ -1 +1 @@
1
- 1.19.0
1
+ 1.19.4
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: 1.19.0
4
+ version: 1.19.4
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: 2022-01-05 00:00:00.000000000 Z
13
+ date: 2022-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport