rubypitaya 2.7.0 → 2.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87587b02594a88b88edbf8c1f834a088a375a159d8382aae4199529690d7adad
4
- data.tar.gz: 56ba5c551c06c7cc36feaede56353adb522a917047fefc47788b7f49409c73b7
3
+ metadata.gz: 29b7ecc7e113e398e9295133b97a79f04af607848ba185db0005027af86b70c9
4
+ data.tar.gz: 6ae5d8f4b78041e30bf8d362f443ce18a22bdc3fd1f909afb037622b9b4201b1
5
5
  SHA512:
6
- metadata.gz: a3b0512be9ad4f86ed742a49856fd814d2ad116c2895b89362e9bb623bcc1aa29019c08eb0ed42f16f6c28b3b1977c7ff8d2634c37574d17f9261a17af1b966c
7
- data.tar.gz: 0a0b2173420b168a6326465da9272db42ad04b67c8b9573a38bde67b9d08d7811e69f1f5db549d9de64dfb5058736298f97276d3a7c6944c994bd9018689e1ae
6
+ metadata.gz: 0a4209c6106cca1ecd8f88cb7dc6db0615c4bb3e1455d5b4319a986cb76c96a9359edd2f1189292724e64b2f8e4b38f5156854f2ba42476fa1fda9d4ae68c1b1
7
+ data.tar.gz: 4fee00de34828c2810b64f4af518987c48963e5a9b48dd2e25b46accd31413b852e5f41ebcd55f989c467a342212c3f9888c07114147fee98371e18772497986
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.7.0'
3
+ gem 'rubypitaya', '2.8.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.12.2'
@@ -69,7 +69,7 @@ GEM
69
69
  rspec-support (~> 3.8.0)
70
70
  rspec-support (3.8.3)
71
71
  ruby2_keywords (0.0.2)
72
- rubypitaya (2.7.0)
72
+ rubypitaya (2.8.0)
73
73
  activerecord (= 6.0.2)
74
74
  etcdv3 (= 0.10.2)
75
75
  eventmachine (= 1.2.7)
@@ -106,7 +106,7 @@ DEPENDENCIES
106
106
  listen (= 3.2.1)
107
107
  pry (= 0.12.2)
108
108
  rspec (= 3.8.0)
109
- rubypitaya (= 2.7.0)
109
+ rubypitaya (= 2.8.0)
110
110
 
111
111
  BUNDLED WITH
112
112
  1.17.2
@@ -1,3 +1,9 @@
1
+ IMAGE_TAG ?= latest
2
+ IMAGE_REGISTRY ?= [put-your-registry-here]
3
+ KUBE_NAMESPACE ?= [put-your-namespace-here]
4
+ KUBE_DEPLOYMENT_SERVER ?= rubypitaya
5
+ KUBECONTEXT ?= ''
6
+
1
7
  ## Run ruby pitaya metagame project
2
8
  run:
3
9
  @docker-compose run --service-ports --rm rubypitaya bundle exec rubypitaya run
@@ -30,6 +36,10 @@ db-create:
30
36
  db-migrate:
31
37
  @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:migrate
32
38
 
39
+ ## Show migrations status on database
40
+ db-migrate-status:
41
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:status
42
+
33
43
  ## Rollback migrations STEP=1
34
44
  db-rollback:
35
45
  @docker-compose run --service-ports --rm -e STEP="$(STEP)" rubypitaya bundle exec rake db:rollback
@@ -48,15 +58,15 @@ generate-gemfilelock:
48
58
 
49
59
  ## Build image to production environment
50
60
  prod-build-image:
51
- @docker build . -f docker/prod/Dockerfile -t [registry-address]:$(IMAGE_TAG)
61
+ @docker build . -f docker/prod/Dockerfile -t $(IMAGE_REGISTRY):$(IMAGE_TAG)
52
62
 
53
63
  ## Push prod image to gitlab
54
64
  prod-push-image:
55
- @docker push [registry-address]:$(IMAGE_TAG)
65
+ @docker push $(IMAGE_REGISTRY):$(IMAGE_TAG)
56
66
 
57
67
  ## Deploy prod image to kubernetes cluster
58
68
  prod-deploy-image:
59
- kubectl -n $(PROD_NAMESPACE) set image deployment rubypitaya rubypitaya=[registry-address]:$(IMAGE_TAG)
69
+ kubectl --context='$(KUBECONTEXT)' -n $(KUBE_NAMESPACE) set image deployment $(KUBE_DEPLOYMENT_SERVER) $(KUBE_DEPLOYMENT_SERVER)=$(IMAGE_REGISTRY):$(IMAGE_TAG)
60
70
 
61
71
  .DEFAULT_GOAL := show-help
62
72
 
@@ -98,6 +108,3 @@ show-help:
98
108
  } \
99
109
  printf "\n"; \
100
110
  }'
101
-
102
-
103
-
@@ -75,6 +75,25 @@ namespace :db do
75
75
  puts 'Database deleted.'
76
76
  end
77
77
 
78
+ desc 'migration status'
79
+ task :status do
80
+ environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
81
+ database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
82
+ connection_data = database_config.connection_data
83
+ migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
84
+ migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
85
+ migrations_paths += [RubyPitaya::Path::MIGRATIONS_FOLDER_PATH]
86
+
87
+ ActiveRecord::Base.establish_connection(connection_data)
88
+ ActiveRecord::Migrator.migrations_paths = migrations_paths
89
+ ActiveRecord::Base.connection.migration_context.migrations_status.each do |status, version, name|
90
+ puts "#{status.center(8)} #{version.ljust(14)} #{name}"
91
+ end
92
+ ActiveRecord::Base.connection.close
93
+
94
+ puts 'Rollback done.'
95
+ end
96
+
78
97
  desc 'Reset the database'
79
98
  task :reset do
80
99
  Rake::Task['db:drop'].invoke
@@ -27,6 +27,12 @@ module MyApp
27
27
  # - methods:
28
28
  # - [](key)
29
29
  # - get config file by config path
30
+ # - log
31
+ # - class: Logger
32
+ # - link: https://ruby-doc.org/stdlib-2.6.4/libdoc/logger/rdoc/Logger.html
33
+ # - methods:
34
+ # - info
35
+ # - log information
30
36
 
31
37
  def run(initializer_content)
32
38
  bll = initializer_content.bll
@@ -35,5 +41,9 @@ module MyApp
35
41
 
36
42
  bll.add_instance(:player, playerBll)
37
43
  end
44
+
45
+ def self.path
46
+ __FILE__
47
+ end
38
48
  end
39
49
  end
@@ -18,10 +18,14 @@ Gem.find_files('rubypitaya/**/*.rb').each do |path|
18
18
  path.include?('app-template')
19
19
  end
20
20
 
21
- app_files_path = File.join(RubyPitaya::Path::APP_FOLDER_PATH, '**/*.rb')
22
- Dir[app_files_path].each do |path|
23
- require path unless path.end_with?('spec.rb') ||
24
- path.include?('db/migration')
21
+ app_folder_paths = RubyPitaya::Path::Plugins::APP_FOLDER_PATHS + [RubyPitaya::Path::APP_FOLDER_PATH]
22
+ app_folder_paths.each do |app_folder_path|
23
+ app_files_path = File.join(app_folder_path, '**/*.rb')
24
+
25
+ Dir[app_files_path].each do |path|
26
+ require path unless path.end_with?('spec.rb') ||
27
+ path.include?('db/migration')
28
+ end
25
29
  end
26
30
 
27
31
  require 'irb'
@@ -56,6 +56,7 @@ services:
56
56
  working_dir: '/app/rubypitaya'
57
57
  volumes:
58
58
  - '.:/app/rubypitaya'
59
+ - '/var/run/docker.sock:/var/run/docker.sock'
59
60
  ports:
60
61
  - '80:4567'
61
62
  environment:
@@ -1,7 +1,7 @@
1
1
  FROM ruby:2.6.6
2
2
 
3
3
  RUN apt update
4
- RUN apt install -y git vim postgresql-client --no-install-recommends
4
+ RUN apt install -y git vim postgresql-client docker.io --no-install-recommends
5
5
 
6
6
  WORKDIR /app/rubypitaya/
7
7
 
@@ -16,7 +16,7 @@ spec:
16
16
  spec:
17
17
  containers:
18
18
  - name: rubypitaya
19
- image: git.topfreegames.com:4567/prestes/tech-prototype/rubypitaya:latest
19
+ image: registry.gitlab.com/lucianopc/ruby-pitaya:latest
20
20
  command: ["bundle", "exec", "rubypitaya", "run"]
21
21
  ports:
22
22
  - containerPort: 4567
@@ -45,4 +45,4 @@ spec:
45
45
  - name: DATABASE_NAME
46
46
  value: "ruby_pitaya"
47
47
  imagePullSecrets:
48
- - name: gitlab-registry
48
+ - name: gitlab-registry
@@ -2,7 +2,7 @@ kind: Role
2
2
  apiVersion: apps/v1
3
3
  metadata:
4
4
  namespace: default
5
- name: namespace
5
+ name: rubypitaya
6
6
  rules:
7
7
  - apiGroups:
8
8
  - ""
@@ -4,10 +4,11 @@ module RubyPitaya
4
4
 
5
5
  class_attribute :non_authenticated_routes, default: []
6
6
 
7
- attr_accessor :bll, :redis, :setup, :config, :params, :session, :postman
7
+ attr_accessor :bll, :log, :redis, :setup, :config, :params, :session, :postman
8
8
 
9
9
  def initialize
10
10
  @bll = nil
11
+ @log = nil
11
12
  @redis = nil
12
13
  @setup = nil
13
14
  @config = nil
@@ -53,7 +53,7 @@ module RubyPitaya
53
53
  end
54
54
 
55
55
  def call(handler_name, action_name, session, postman, redis, setup, config,
56
- bll, params)
56
+ bll, log, params)
57
57
  unless @handler_name_map.include?(handler_name)
58
58
  return {
59
59
  code: StatusCodes::CODE_HANDLER_NOT_FOUND,
@@ -71,6 +71,7 @@ module RubyPitaya
71
71
  handler = @handler_name_map[handler_name]
72
72
 
73
73
  handler.bll = bll
74
+ handler.log = log
74
75
  handler.redis = redis
75
76
  handler.setup = setup
76
77
  handler.config = config
@@ -23,7 +23,7 @@ module RubyPitaya
23
23
  @setup = settings.setup
24
24
  @config = settings.config
25
25
 
26
- if request.content_type == 'aplication/json'
26
+ if request.content_type == 'application/json'
27
27
  request_body = request.body.read
28
28
  @params.merge!(JSON.parse(request_body)) if !request_body.blank?
29
29
  end
@@ -2,6 +2,10 @@ module RubyPitaya
2
2
 
3
3
  class InitializerBase
4
4
 
5
+ def self.path
6
+ __FILE__
7
+ end
8
+
5
9
  def run(main)
6
10
  end
7
11
  end
@@ -6,7 +6,25 @@ module RubyPitaya
6
6
  class InitializerBroadcast
7
7
 
8
8
  def run(initializer_content)
9
+ app_classes = []
10
+ plugin_classes = []
11
+
9
12
  ObjectSpace.each_object(InitializerBase.singleton_class) do |klass|
13
+ is_plugin_class = klass.path.include?('plugins')
14
+
15
+ if is_plugin_class
16
+ plugin_classes << klass
17
+ else
18
+ app_classes << klass
19
+ end
20
+ end
21
+
22
+ plugin_classes.each do |klass|
23
+ instance = klass.new
24
+ instance.run(initializer_content)
25
+ end
26
+
27
+ app_classes.each do |klass|
10
28
  instance = klass.new
11
29
  instance.run(initializer_content)
12
30
  end
@@ -2,10 +2,11 @@ module RubyPitaya
2
2
 
3
3
  class InitializerContent
4
4
 
5
- attr_reader :bll, :redis, :config
5
+ attr_reader :bll, :log, :redis, :setup, :config
6
6
 
7
- def initialize(bll, redis, setup, config)
7
+ def initialize(bll, log, redis, setup, config)
8
8
  @bll = bll
9
+ @log = log
9
10
  @redis = redis
10
11
  @setup = setup
11
12
  @config = config
@@ -1,4 +1,5 @@
1
1
  require 'socket'
2
+ require 'logger'
2
3
  require 'securerandom'
3
4
  require 'active_model'
4
5
 
@@ -8,6 +9,7 @@ require 'rubypitaya/core/config'
8
9
  require 'rubypitaya/core/session'
9
10
  require 'rubypitaya/core/postman'
10
11
  require 'rubypitaya/core/parameters'
12
+ require 'rubypitaya/core/http_routes'
11
13
  require 'rubypitaya/core/routes_base'
12
14
  require 'rubypitaya/core/status_codes'
13
15
  require 'rubypitaya/core/handler_router'
@@ -31,6 +33,12 @@ module RubyPitaya
31
33
  @environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
32
34
  @is_development_environment = @environment_name == 'development'
33
35
 
36
+ @log = Logger.new('/proc/self/fd/1')
37
+ @log.level = Logger::INFO
38
+ @log.formatter = proc do |severity, datetime, progname, msg|
39
+ "#{msg}\n"
40
+ end
41
+
34
42
  @application_files_importer = ApplicationFilesImporter.new
35
43
  @application_files_importer.import
36
44
  @application_files_importer.auto_reload if @is_development_environment
@@ -71,6 +79,7 @@ module RubyPitaya
71
79
  @bll = InstanceHolder.new
72
80
 
73
81
  @initializer_content = InitializerContent.new(@bll,
82
+ @log,
74
83
  @redis_connector.redis,
75
84
  @setup,
76
85
  @config)
@@ -87,6 +96,7 @@ module RubyPitaya
87
96
 
88
97
  def run_http
89
98
  HttpRoutes.set :bll, @bll
99
+ HttpRoutes.set :log, @log
90
100
  HttpRoutes.set :setup, @setup
91
101
  HttpRoutes.set :config, @config
92
102
  HttpRoutes.set :views, [Path::HTTP_VIEWS_PATH] + Path::Plugins::HTTP_VIEWS_PATHS
@@ -106,7 +116,7 @@ module RubyPitaya
106
116
  Signal.trap("SIGQUIT") { throw :sig_shutdown }
107
117
  Signal.trap("SIGTERM") { throw :sig_shutdown }
108
118
 
109
- puts "Server started!"
119
+ @log.info "Server started!"
110
120
  run_nats_connection
111
121
  end
112
122
 
@@ -121,7 +131,7 @@ module RubyPitaya
121
131
  return if @is_shutting_down
122
132
  @is_shutting_down = true
123
133
 
124
- puts "Server shutting down..."
134
+ @log.info "Server shutting down..."
125
135
 
126
136
  @etcd_connector.disconnect
127
137
  @database_connector.disconnect
@@ -152,22 +162,22 @@ module RubyPitaya
152
162
 
153
163
  handler_name, action_name = message_route.split('.')[1..-1]
154
164
 
155
- puts "request -> route: #{message_route}"
156
- puts " -> data: #{message_data}"
165
+ @log.info "request -> route: #{message_route}"
166
+ @log.info " -> data: #{message_data}"
157
167
 
158
168
  response = @handler_router.call(handler_name, action_name, @session,
159
169
  @postman, @redis_connector.redis,
160
- @setup, @config, @bll, params)
170
+ @setup, @config, @bll, @log, params)
161
171
 
162
172
  delta_time_seconds = Time.now.to_i - start_time_seconds
163
173
 
164
- puts "response [#{delta_time_seconds}s] -> #{response.to_json}"
174
+ @log.info "response [#{delta_time_seconds}s] -> #{response.to_json}"
165
175
 
166
176
  response
167
177
  end
168
178
  rescue Exception => error
169
- puts "ERROR: #{error}"
170
- puts error.backtrace
179
+ @log.info "ERROR: #{error}"
180
+ @log.info error.backtrace
171
181
  run_nats_connection
172
182
  end
173
183
  end
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.7.0'
2
+ VERSION = '2.8.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypitaya
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Prestes Cavalcanti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-30 00:00:00.000000000 Z
11
+ date: 2020-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg