rubypitaya 2.6.4 → 2.7.5

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubypitaya/app-template/Gemfile +1 -1
  3. data/lib/rubypitaya/app-template/Gemfile.lock +2 -2
  4. data/lib/rubypitaya/app-template/Makefile +8 -6
  5. data/lib/rubypitaya/app-template/app/app_initializer.rb +41 -31
  6. data/lib/rubypitaya/app-template/app/bll/player_bll.rb +10 -7
  7. data/lib/rubypitaya/app-template/app/constants/status_codes.rb +22 -19
  8. data/lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb +1 -0
  9. data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +69 -66
  10. data/lib/rubypitaya/app-template/app/models/player.rb +13 -10
  11. data/lib/rubypitaya/app-template/config/routes.rb +1 -1
  12. data/lib/rubypitaya/app-template/db/migration/{0000000002_create_player_migration.rb → 1606736477_create_player_migration.rb} +0 -0
  13. data/lib/rubypitaya/app-template/docker-compose.yml +1 -0
  14. data/lib/rubypitaya/app-template/docker/dev/Dockerfile +1 -1
  15. data/lib/rubypitaya/app-template/docker/prod/Dockerfile +5 -1
  16. data/lib/rubypitaya/app-template/kubernetes/README.md +22 -2
  17. data/lib/rubypitaya/app-template/kubernetes/gameplay/deployment-nginx.yaml +130 -0
  18. data/lib/rubypitaya/app-template/kubernetes/gameplay/gameplay-template.yaml +29 -0
  19. data/lib/rubypitaya/app-template/kubernetes/gameplay/nginx.conf +13 -0
  20. data/lib/rubypitaya/app-template/kubernetes/gameplay/service-nginx.yaml +928 -0
  21. data/lib/rubypitaya/app-template/kubernetes/role-rubypitaya.yaml +31 -0
  22. data/lib/rubypitaya/app-template/kubernetes/rolebinding-rubypitaya.yaml +13 -0
  23. data/lib/rubypitaya/app-template/kubernetes/service-etcd.yaml +1 -1
  24. data/lib/rubypitaya/app-template/kubernetes/service-nats.yaml +1 -1
  25. data/lib/rubypitaya/app-template/kubernetes/service-postgres.yaml +1 -1
  26. data/lib/rubypitaya/app-template/kubernetes/service-redis.yaml +1 -1
  27. data/lib/rubypitaya/core/handler_base.rb +2 -1
  28. data/lib/rubypitaya/core/handler_router.rb +2 -1
  29. data/lib/rubypitaya/core/http_routes.rb +1 -1
  30. data/lib/rubypitaya/core/initializer_content.rb +3 -2
  31. data/lib/rubypitaya/core/main.rb +18 -8
  32. data/lib/rubypitaya/version.rb +1 -1
  33. metadata +9 -4
  34. data/lib/rubypitaya/app-template/docker/prod/Makefile +0 -67
@@ -0,0 +1,31 @@
1
+ kind: Role
2
+ apiVersion: apps/v1
3
+ metadata:
4
+ namespace: default
5
+ name: rubypitaya
6
+ rules:
7
+ - apiGroups:
8
+ - ""
9
+ resources:
10
+ - services
11
+ - pods
12
+ verbs:
13
+ - get
14
+ - list
15
+ - watch
16
+ - create
17
+ - update
18
+ - patch
19
+ - delete
20
+ - apiGroups:
21
+ - apps
22
+ resources:
23
+ - deployments
24
+ verbs:
25
+ - get
26
+ - list
27
+ - watch
28
+ - create
29
+ - update
30
+ - patch
31
+ - delete
@@ -0,0 +1,13 @@
1
+ kind: RoleBinding
2
+ apiVersion: apps/v1
3
+ metadata:
4
+ name: rubypitaya
5
+ namespace: default
6
+ subjects:
7
+ - kind: ServiceAccount
8
+ name: rubypitaya
9
+ namespace: default
10
+ roleRef:
11
+ apiGroup: apps
12
+ kind: Role
13
+ name: rubypitaya
@@ -14,4 +14,4 @@ spec:
14
14
  port: 2380
15
15
  targetPort: 2380
16
16
  name: etcd-2380
17
- type: LoadBalancer
17
+ type: ClusterIP
@@ -9,4 +9,4 @@ spec:
9
9
  - protocol: TCP
10
10
  port: 4222
11
11
  targetPort: 4222
12
- type: LoadBalancer
12
+ type: ClusterIP
@@ -9,4 +9,4 @@ spec:
9
9
  - protocol: TCP
10
10
  port: 5432
11
11
  targetPort: 5432
12
- type: LoadBalancer
12
+ type: ClusterIP
@@ -10,4 +10,4 @@ spec:
10
10
  port: 6379
11
11
  targetPort: 6379
12
12
  name: redis
13
- type: LoadBalancer
13
+ type: ClusterIP
@@ -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,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.6.4'
2
+ VERSION = '2.7.5'
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.6.4
4
+ version: 2.7.5
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-28 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -235,16 +235,21 @@ files:
235
235
  - "./lib/rubypitaya/app-template/bin/console"
236
236
  - "./lib/rubypitaya/app-template/config/database.yml"
237
237
  - "./lib/rubypitaya/app-template/config/routes.rb"
238
- - "./lib/rubypitaya/app-template/db/migration/0000000002_create_player_migration.rb"
238
+ - "./lib/rubypitaya/app-template/db/migration/1606736477_create_player_migration.rb"
239
239
  - "./lib/rubypitaya/app-template/docker-compose.yml"
240
240
  - "./lib/rubypitaya/app-template/docker/dev/Dockerfile"
241
241
  - "./lib/rubypitaya/app-template/docker/entrypoint.sh"
242
242
  - "./lib/rubypitaya/app-template/docker/prod/Dockerfile"
243
- - "./lib/rubypitaya/app-template/docker/prod/Makefile"
244
243
  - "./lib/rubypitaya/app-template/kubernetes/README.md"
245
244
  - "./lib/rubypitaya/app-template/kubernetes/deployment-connector.yaml"
246
245
  - "./lib/rubypitaya/app-template/kubernetes/deployment-rubypitaya.yaml"
246
+ - "./lib/rubypitaya/app-template/kubernetes/gameplay/deployment-nginx.yaml"
247
+ - "./lib/rubypitaya/app-template/kubernetes/gameplay/gameplay-template.yaml"
248
+ - "./lib/rubypitaya/app-template/kubernetes/gameplay/nginx.conf"
249
+ - "./lib/rubypitaya/app-template/kubernetes/gameplay/service-nginx.yaml"
247
250
  - "./lib/rubypitaya/app-template/kubernetes/persistent-volume.yaml"
251
+ - "./lib/rubypitaya/app-template/kubernetes/role-rubypitaya.yaml"
252
+ - "./lib/rubypitaya/app-template/kubernetes/rolebinding-rubypitaya.yaml"
248
253
  - "./lib/rubypitaya/app-template/kubernetes/service-connector.yaml"
249
254
  - "./lib/rubypitaya/app-template/kubernetes/service-etcd.yaml"
250
255
  - "./lib/rubypitaya/app-template/kubernetes/service-nats.yaml"
@@ -1,67 +0,0 @@
1
- ## Run ruby pitaya metagame project
2
- run:
3
- @docker-compose run --service-ports --rm rubypitaya bundle exec rubypitaya
4
-
5
- ## Update docker images
6
- update:
7
- @docker-compose pull
8
-
9
- ## Create database
10
- db-create:
11
- @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:create
12
-
13
- ## Run migrations to database
14
- db-migrate:
15
- @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:migrate
16
-
17
- ## Drop database
18
- db-drop:
19
- @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:drop
20
-
21
- ## Reset database
22
- db-reset:
23
- @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
24
-
25
- .DEFAULT_GOAL := show-help
26
-
27
- .PHONY: show-help
28
- show-help:
29
- @echo "$$(tput bold)Commands:$$(tput sgr0)"
30
- @echo
31
- @sed -n -e "/^## / { \
32
- h; \
33
- s/.*//; \
34
- :doc" \
35
- -e "H; \
36
- n; \
37
- s/^## //; \
38
- t doc" \
39
- -e "s/:.*//; \
40
- G; \
41
- s/\\n## /---/; \
42
- s/\\n/ /g; \
43
- p; \
44
- }" ${MAKEFILE_LIST} \
45
- | LC_ALL='C' sort --ignore-case \
46
- | awk -F '---' \
47
- -v ncol=$$(tput cols) \
48
- -v indent=19 \
49
- -v col_on="$$(tput setaf 6)" \
50
- -v col_off="$$(tput sgr0)" \
51
- '{ \
52
- printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
53
- n = split($$2, words, " "); \
54
- line_length = ncol - indent; \
55
- for (i = 1; i <= n; i++) { \
56
- line_length -= length(words[i]) + 1; \
57
- if (line_length <= 0) { \
58
- line_length = ncol - indent - length(words[i]) - 1; \
59
- printf "\n%*s ", -indent, " "; \
60
- } \
61
- printf "%s ", words[i]; \
62
- } \
63
- printf "\n"; \
64
- }'
65
-
66
-
67
-