rubypitaya 2.22.0 → 2.25.1

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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rubypitaya +4 -3
  3. data/lib/rubypitaya/app-template/Gemfile +1 -1
  4. data/lib/rubypitaya/app-template/Gemfile.lock +2 -2
  5. data/lib/rubypitaya/app-template/Makefile +2 -2
  6. data/lib/rubypitaya/app-template/app/app_initializer.rb +3 -0
  7. data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +4 -0
  8. data/lib/rubypitaya/app-template/{db/migration → app/migrations}/1606736477_create_player_migration.rb +0 -0
  9. data/lib/rubypitaya/app-template/app/setup/rubypitaya.yml +6 -0
  10. data/lib/rubypitaya/app-template/bin/console +2 -2
  11. data/lib/rubypitaya/app-template/docker-compose.yml +24 -0
  12. data/lib/rubypitaya/app-template/helm/templates/config-maps/nginx-config.yaml +2 -2
  13. data/lib/rubypitaya/app-template/helm/templates/deployments/gameserver-nginx.yaml +2 -2
  14. data/lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml +6 -6
  15. data/lib/rubypitaya/app-template/helm/templates/pods/gameserver.yaml +21 -0
  16. data/lib/rubypitaya/app-template/helm/templates/services/gameserver-nginx.yaml +2 -2
  17. data/lib/rubypitaya/app-template/helm/templates/services/gameserver.yaml +6 -13
  18. data/lib/rubypitaya/app-template/helm/values.yaml +2 -1
  19. data/lib/rubypitaya/core/{db/migration → app/migrations}/0000000001_create_user_migration.rb +0 -0
  20. data/lib/rubypitaya/core/application_files_importer.rb +3 -1
  21. data/lib/rubypitaya/core/handler_base.rb +2 -1
  22. data/lib/rubypitaya/core/handler_router.rb +4 -4
  23. data/lib/rubypitaya/core/helpers/setup_helper.rb +2 -2
  24. data/lib/rubypitaya/core/http_routes.rb +14 -0
  25. data/lib/rubypitaya/core/initializer_content.rb +3 -2
  26. data/lib/rubypitaya/core/main.rb +15 -2
  27. data/lib/rubypitaya/core/mongo_connector.rb +25 -0
  28. data/lib/rubypitaya/core/path.rb +3 -3
  29. data/lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb +26 -6
  30. data/lib/rubypitaya/version.rb +1 -1
  31. data/lib/rubypitaya.rb +15 -4
  32. metadata +6 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7529399c736434f01aee685406c3d2763e6ecd167fcf0b783aac93a2aef7c0e4
4
- data.tar.gz: 6eceae718f3027593dfd6d82a384b1c139a241e36decc0bc6d51553f59717567
3
+ metadata.gz: 55bc3adc9c4e44304aceddc76204d67e147be13409f34116fd43fad42ec7a1ec
4
+ data.tar.gz: 003b0bf7ad5d1e3f2917327e0db98344b35f388e4f924da92be7f8861891c307
5
5
  SHA512:
6
- metadata.gz: 4f41f11c539540593b5da84a986c7baa2209a6108f2fb3ddeca6b6577509d96732704609dd13000b8c9e2573ac9acd3d2f58b55c1ffe8c45ccdbc1e507d9ff50
7
- data.tar.gz: 3f1d834d5442848c9637491709ae0c7bff746e345e316afd13cec022d65a652591ea0a4ac01e42986132defd7feac209ebf934b782e4bf58274ffa21f670abb1
6
+ metadata.gz: b70ab8dad9c768b8d1cd6ba66472d539397db4898b83be9d2624f9af0df989f311cc91c28463d5d3ed4a3ee586c8b488232e89862e2d920a0912bf80c3d85e71
7
+ data.tar.gz: ccd0ec9c84bb26d06fd1f9394e38f3ec8be31097dafd2ba91d6370e323351398dc928b821b8d918af5ce78f6197b2e01b6881f2920bb966bc012ec90c9d30234
data/bin/rubypitaya CHANGED
@@ -67,9 +67,10 @@ def command_add_plugin(argv)
67
67
  exit(-1)
68
68
  end
69
69
 
70
- plugin_git_link = argv[1]
70
+ plugin_git_url = argv[1]
71
+ branch_name = argv[2] || ""
71
72
 
72
- plugin_name = RubyPitaya::RubyPitaya.add_plugin(plugin_git_link)
73
+ plugin_name = RubyPitaya::RubyPitaya.add_plugin(plugin_git_url, branch_name)
73
74
 
74
75
  puts "Plugin #{plugin_name} added!"
75
76
  end
@@ -94,7 +95,7 @@ def show_help_create_migration
94
95
  end
95
96
 
96
97
  def show_help_add_plugin
97
- puts 'Usage: $ rubypitaya add-plugin [plugin_git_link]'
98
+ puts 'Usage: $ rubypitaya add-plugin [plugin_git_link] [branch_name:optional]'
98
99
  puts ''
99
100
  end
100
101
 
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.22.0'
3
+ gem 'rubypitaya', '2.25.1'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.14.0'
@@ -111,7 +111,7 @@ GEM
111
111
  rspec-support (~> 3.10.0)
112
112
  rspec-support (3.10.2)
113
113
  ruby2_keywords (0.0.5)
114
- rubypitaya (2.22.0)
114
+ rubypitaya (2.25.1)
115
115
  activerecord (= 6.1.3)
116
116
  etcdv3 (= 0.10.2)
117
117
  mongo (= 2.15.0)
@@ -152,7 +152,7 @@ DEPENDENCIES
152
152
  listen (= 3.4.1)
153
153
  pry (= 0.14.0)
154
154
  rspec (= 3.10.0)
155
- rubypitaya (= 2.22.0)
155
+ rubypitaya (= 2.25.1)
156
156
 
157
157
  BUNDLED WITH
158
158
  2.1.4
@@ -49,9 +49,9 @@ update-dependencies:
49
49
  create-migration:
50
50
  @docker-compose run --service-ports --rm rubypitaya-commands bundle exec rubypitaya create-migration $(NAME)
51
51
 
52
- ## Add or update a plugim. GIT=[plugin-git-link]
52
+ ## Add or update a plugin. GIT=[plugin-http-git-link] BRANCH=[branch-name:optional]
53
53
  add-plugin:
54
- @docker-compose run --service-ports --rm rubypitaya-commands bundle exec rubypitaya add-plugin $(GIT)
54
+ @docker-compose run --service-ports --rm rubypitaya-commands bundle exec rubypitaya add-plugin $(GIT) $(BRANCH)
55
55
 
56
56
  ## + Database Commands
57
57
 
@@ -13,6 +13,9 @@ class AppInitializer < RubyPitaya::InitializerBase
13
13
  # - get instance by key
14
14
  # - redis
15
15
  # - link: https://github.com/redis/redis-rb/
16
+ # - mongo
17
+ # - class: Mongo::Client
18
+ # - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
16
19
  # - config
17
20
  # - class: RubyPitaya::Config
18
21
  # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
@@ -11,6 +11,10 @@ class PlayerHandler < RubyPitaya::HandlerBase
11
11
  # - @redis
12
12
  # - link: https://github.com/redis/redis-rb/
13
13
  #
14
+ # - @mongo
15
+ # - class: Mongo::Client
16
+ # - link: https://docs.mongodb.com/ruby-driver/current/tutorials/quick-start/
17
+ #
14
18
  # - @config
15
19
  # - info: Hash with config json files inside of 'app/config'
16
20
  # - example:
@@ -20,6 +20,12 @@ database:
20
20
  password: 'postgres'
21
21
  name: 'ruby_pitaya'
22
22
 
23
+ mongo:
24
+ url: mongo:27017
25
+ user: 'user'
26
+ pass: 'password'
27
+ database: admin
28
+
23
29
  http:
24
30
  auth:
25
31
  user: 'user'
@@ -15,7 +15,7 @@ ActiveSupport::LogSubscriber.colorize_logging = true
15
15
  # Loading core files
16
16
  Gem.find_files('rubypitaya/**/*.rb').each do |path|
17
17
  require path unless path.end_with?('spec.rb') ||
18
- path.include?('db/migration') ||
18
+ path.include?('app/migrations') ||
19
19
  path.include?('core/templates') ||
20
20
  path.include?('core/spec-helpers') ||
21
21
  path.include?('app-template')
@@ -28,7 +28,7 @@ app_folder_paths.each do |app_folder_path|
28
28
 
29
29
  Dir[app_files_path].each do |path|
30
30
  require path unless path.end_with?('spec.rb') ||
31
- path.include?('db/migration') ||
31
+ path.include?('app/migrations') ||
32
32
  path.include?('spec_helper.rb')
33
33
  end
34
34
  end
@@ -26,6 +26,28 @@ services:
26
26
  ports:
27
27
  - '9100:5432'
28
28
 
29
+ mongo:
30
+ image: mongo:5.0.0
31
+ restart: always
32
+ ports:
33
+ - 27017:27017
34
+ environment:
35
+ MONGO_INITDB_ROOT_USERNAME: user
36
+ MONGO_INITDB_ROOT_PASSWORD: password
37
+
38
+ mongo-express:
39
+ depends_on:
40
+ - 'mongo'
41
+ image: mongo-express:0.54.0
42
+ restart: always
43
+ ports:
44
+ - 8081:8081
45
+ environment:
46
+ ME_CONFIG_MONGODB_ADMINUSERNAME: user
47
+ ME_CONFIG_MONGODB_ADMINPASSWORD: password
48
+ ME_CONFIG_MONGODB_SERVER: 'mongo'
49
+ ME_CONFIG_MONGODB_PORT: '27017'
50
+
29
51
  connector:
30
52
  image: 'registry.gitlab.com/lucianopc/pitaya-connector:0.1.0'
31
53
  depends_on:
@@ -49,6 +71,8 @@ services:
49
71
  - 'nats'
50
72
  - 'etcd'
51
73
  - 'redis'
74
+ - 'mongo'
75
+ - 'mongo-express'
52
76
  - 'connector'
53
77
  build:
54
78
  context: '.'
@@ -4,6 +4,6 @@ metadata:
4
4
  name: nginx-config
5
5
  data:
6
6
  nginx.conf: "events {\n worker_connections 1024;\n}\n\nstream {\n server
7
- {\n listen {{ .Values.gameserver.port.first }}-{{ .Values.gameserver.port.last }};\n \n resolver kube-dns.kube-system.svc.cluster.local
8
- valid=5s;\n\n proxy_pass gameserver-$server_port.{{ .Values.namespace }}.svc.cluster.local:$server_port;\n
7
+ {\n listen {{ .Values.gameserver.externalport.first }}-{{ .Values.gameserver.externalport.last }};\n \n resolver kube-dns.kube-system.svc.cluster.local
8
+ valid=5s;\n\n proxy_pass gameserver-$server_port.gameserver.{{ .Values.namespace }}.svc.cluster.local:{{ .Values.gameserver.gameport }};\n
9
9
  \ }\n}\n"
@@ -21,8 +21,8 @@ spec:
21
21
  - name: gameserver-nginx
22
22
  image: nginx:1.18.0
23
23
  ports:
24
- {{- $initialValue := int .Values.gameserver.port.first }}
25
- {{- $finalValue := add .Values.gameserver.port.last 1 }}
24
+ {{- $initialValue := int .Values.gameserver.externalport.first }}
25
+ {{- $finalValue := add .Values.gameserver.externalport.last 1 }}
26
26
  {{- $finalValue = int $finalValue }}
27
27
  {{- range untilStep $initialValue $finalValue 1 }}
28
28
  {{- $port := . }}
@@ -19,7 +19,7 @@ spec:
19
19
  spec:
20
20
  containers:
21
21
  - name: rubypitaya
22
- image: {{ .Values.rubypitaya.image.repository }}:{{ .Values.rubypitaya.image.tag }}
22
+ image: "{{ .Values.rubypitaya.image.repository }}:{{ .Values.rubypitaya.image.tag }}"
23
23
  command: ["bundle", "exec", "rubypitaya", "run"]
24
24
  ports:
25
25
  - containerPort: 4567
@@ -48,19 +48,19 @@ spec:
48
48
  - name: RUBYPITAYA_HTTP_AUTH_USER
49
49
  value: {{ .Values.http.auth.user | quote }}
50
50
  - name: RUBYPITAYA_HTTP_AUTH_PASS
51
- value: {{ .Values.http.auth.password | quote }}
51
+ value: {{ .Values.http.auth.pass | quote }}
52
52
  - name: MATCHMAKING_CURRENTROOMBLL
53
53
  value: kubernetes
54
54
  - name: MATCHMAKING_ROOMBLL_KUBERNETES_NAMESPACE
55
55
  value: {{ .Values.namespace }}
56
56
  - name: MATCHMAKING_ROOMBLL_KUBERNETES_CONTAINERIMAGE
57
- value: {{ .Values.gameserver.image.repository }}:{{ .Values.gameserver.image.tag }}
57
+ value: "{{ .Values.gameserver.image.repository }}:{{ .Values.gameserver.image.tag }}"
58
58
  - name: MATCHMAKING_ROOMBLL_KUBERNETES_INITIALPORT
59
- value: {{ .Values.gameserver.port.first | quote }}
59
+ value: {{ .Values.gameserver.externalport.first | quote }}
60
60
  - name: MATCHMAKING_ROOMBLL_KUBERNETES_FINALPORT
61
- value: {{ .Values.gameserver.port.last | quote }}
61
+ value: {{ .Values.gameserver.externalport.last | quote }}
62
62
  - name: MATCHMAKING_ROOMBLL_KUBERNETES_SERVICEHOST
63
- value: {{ .Values.gameserver.servicehost }}
63
+ value: {{ .Values.gameserver.servicehost | quote }}
64
64
  imagePullSecrets:
65
65
  - name: gitlab-registry
66
66
  serviceAccount: rubypitaya
@@ -0,0 +1,21 @@
1
+ apiVersion: v1
2
+ kind: Pod
3
+ metadata:
4
+ name: gameserver-{{ .Values.gameserver.port }}
5
+ labels:
6
+ app: rubypitaya
7
+ component: gameserver
8
+ spec:
9
+ hostname: gameserver-{{ .Values.gameserver.port }}
10
+ subdomain: gameserver
11
+ containers:
12
+ - name: gameserver-{{ .Values.gameserver.port }}
13
+ image: {{ .Values.gameserver.image.repository }}:{{ .Values.connector.image.tag }}
14
+ ports:
15
+ - containerPort: {{ .Values.gameserver.gameport }}
16
+ name: gameserver
17
+ env:
18
+ - name: ROOM_ID
19
+ value: {{ .Values.gameserver.roomid }}
20
+ - name: PORT
21
+ value: {{ .Values.gameserver.gameport }}
@@ -7,8 +7,8 @@ spec:
7
7
  app: gameserver
8
8
  component: gameserver-nginx
9
9
  ports:
10
- {{- $initialValue := int .Values.gameserver.port.first }}
11
- {{- $finalValue := add .Values.gameserver.port.last 1 }}
10
+ {{- $initialValue := int .Values.gameserver.externalport.first }}
11
+ {{- $finalValue := add .Values.gameserver.externalport.last 1 }}
12
12
  {{- $finalValue = int $finalValue }}
13
13
  {{- range untilStep $initialValue $finalValue 1 }}
14
14
  {{- $port := . }}
@@ -1,20 +1,13 @@
1
- {{- $initialValue := int .Values.gameserver.port.first }}
2
- {{- $finalValue := add .Values.gameserver.port.last 1 }}
3
- {{- $finalValue = int $finalValue }}
4
- {{- range untilStep $initialValue $finalValue 1 }}
5
- {{- $port := . }}
6
1
  apiVersion: v1
7
2
  kind: Service
8
3
  metadata:
9
- name: gameserver-{{ $port }}
4
+ name: gameserver
10
5
  spec:
11
6
  selector:
12
- app: gameserver
13
- component: gameserver-{{ $port }}
7
+ app: rubypitaya
8
+ component: gameserver
14
9
  ports:
15
10
  - protocol: TCP
16
- port: {{ $port }}
17
- targetPort: {{ $port }}
18
- type: ClusterIP
19
- ---
20
- {{- end }}
11
+ port: {{ .Values.gameserver.gameport }}
12
+ targetPort: {{ .Values.gameserver.gameport }}
13
+ type: ClusterIP
@@ -30,7 +30,8 @@ gameserver:
30
30
  image:
31
31
  repository: [gameserver-repository-link]
32
32
  tag: latest
33
- port:
33
+ externalport:
34
34
  first: 5000
35
35
  last: 5099
36
+ gameport: 3250
36
37
  servicehost: [gameserver-service-url]
@@ -10,7 +10,9 @@ module RubyPitaya
10
10
  app_folder_paths.each do |app_folder_path|
11
11
  app_files_path = "#{app_folder_path}/**/*.rb"
12
12
 
13
- Gem.find_files(app_files_path).each { |path| require path }
13
+ Gem.find_files(app_files_path).each do |path|
14
+ require path unless path.include?('app/migrations')
15
+ end
14
16
  end
15
17
  end
16
18
 
@@ -17,10 +17,11 @@ module RubyPitaya
17
17
  @postman = nil
18
18
  end
19
19
 
20
- def set_attributes(bll, log, redis, setup, config, params, session, postman)
20
+ def set_attributes(bll, log, redis, mongo, setup, config, params, session, postman)
21
21
  @bll = bll
22
22
  @log = log
23
23
  @redis = redis
24
+ @mongo = mongo
24
25
  @setup = setup
25
26
  @config = config
26
27
  @params = params
@@ -54,8 +54,8 @@ module RubyPitaya
54
54
  @handler_name_map = @handler_name_map.to_h
55
55
  end
56
56
 
57
- def call(handler_name, action_name, session, postman, redis, setup, config,
58
- bll, log, params)
57
+ def call(handler_name, action_name, session, postman, redis, mongo, setup,
58
+ config, bll, log, params)
59
59
  unless @handler_name_map.include?(handler_name)
60
60
  return {
61
61
  code: StatusCodes::CODE_HANDLER_NOT_FOUND,
@@ -72,11 +72,11 @@ module RubyPitaya
72
72
  handler = @handler_name_map[handler_name]
73
73
 
74
74
  if !handler.class.authenticated_action_name?(action_name)
75
- handler.set_attributes(bll, log, redis, setup, config, params, session, postman)
75
+ handler.set_attributes(bll, log, redis, mongo, setup, config, params, session, postman)
76
76
  handler.send(action_name)
77
77
  else
78
78
  if session.authenticated?
79
- handler.set_attributes(bll, log, redis, setup, config, params, session, postman)
79
+ handler.set_attributes(bll, log, redis, mongo, setup, config, params, session, postman)
80
80
  handler.send(action_name)
81
81
  else
82
82
  return {
@@ -18,7 +18,7 @@ ActiveRecord::Migration.maintain_test_schema!
18
18
  # Loading core files
19
19
  Gem.find_files('rubypitaya/**/*.rb').each do |path|
20
20
  require path unless path.end_with?('spec.rb') ||
21
- path.include?('db/migration') ||
21
+ path.include?('app/migrations') ||
22
22
  path.include?('core/templates') ||
23
23
  path.include?('core/spec-helpers') ||
24
24
  path.include?('app-template')
@@ -31,6 +31,6 @@ app_folder_paths.each do |app_folder_path|
31
31
 
32
32
  Dir[app_files_path].each do |path|
33
33
  require path unless path.end_with?('spec.rb') ||
34
- path.include?('db/migration')
34
+ path.include?('app/migrations')
35
35
  end
36
36
  end
@@ -10,6 +10,10 @@ module RubyPitaya
10
10
  register ::Sinatra::Reloader
11
11
  end
12
12
 
13
+ configure do
14
+ set :show_exceptions, false
15
+ end
16
+
13
17
  helpers do
14
18
  def find_template(views, name, engine, &block)
15
19
  views.each { |v| super(v, name, engine, &block) }
@@ -20,8 +24,13 @@ module RubyPitaya
20
24
  content_type :json
21
25
 
22
26
  @bll = settings.bll
27
+ @log = settings.log
28
+ @mongo = settings.mongo
23
29
  @setup = settings.setup
30
+ @redis = settings.redis
24
31
  @config = settings.config
32
+ @session = nil
33
+ @postman = nil
25
34
 
26
35
  return error_unauthorized unless authorized?(request)
27
36
 
@@ -33,6 +42,11 @@ module RubyPitaya
33
42
  end
34
43
 
35
44
  @params = Parameters.new(@params)
45
+ @params.permit!
46
+ end
47
+
48
+ after do
49
+ ActiveRecord::Base.clear_active_connections!
36
50
  end
37
51
 
38
52
  private
@@ -2,11 +2,12 @@ module RubyPitaya
2
2
 
3
3
  class InitializerContent
4
4
 
5
- attr_reader :bll, :log, :redis, :setup, :config
5
+ attr_reader :bll, :log, :redis, :mongo, :setup, :config
6
6
 
7
- def initialize(bll, log, redis, setup, config)
7
+ def initialize(bll, log, redis, mongo, setup, config)
8
8
  @bll = bll
9
9
  @log = log
10
+ @mongo = mongo
10
11
  @redis = redis
11
12
  @setup = setup
12
13
  @config = config
@@ -16,8 +16,9 @@ require 'rubypitaya/core/handler_router'
16
16
  require 'rubypitaya/core/etcd_connector'
17
17
  require 'rubypitaya/core/nats_connector'
18
18
  require 'rubypitaya/core/database_config'
19
- require 'rubypitaya/core/redis_connector'
20
19
  require 'rubypitaya/core/instance_holder'
20
+ require 'rubypitaya/core/mongo_connector'
21
+ require 'rubypitaya/core/redis_connector'
21
22
  require 'rubypitaya/core/database_connector'
22
23
  require 'rubypitaya/core/initializer_content'
23
24
  require 'rubypitaya/core/initializer_broadcast'
@@ -71,6 +72,14 @@ module RubyPitaya
71
72
  @database_connector = DatabaseConnector.new(@database_config)
72
73
  @database_connector.connect
73
74
 
75
+ @mongo_address = @setup['rubypitaya.mongo.url']
76
+ @mongo_user = @setup['rubypitaya.mongo.user']
77
+ @mongo_password = @setup['rubypitaya.mongo.pass']
78
+ @mongo_database_name = @setup['rubypitaya.mongo.database']
79
+ @mongo_connector = MongoConnector.new(@mongo_address, @mongo_user,
80
+ @mongo_password, @mongo_database_name)
81
+ @mongo_connector.connect
82
+
74
83
  @session = Session.new
75
84
  @postman = Postman.new(@nats_connector)
76
85
  @config = Config.new
@@ -81,6 +90,7 @@ module RubyPitaya
81
90
  @initializer_content = InitializerContent.new(@bll,
82
91
  @log,
83
92
  @redis_connector.redis,
93
+ @mongo_connector.mongo,
84
94
  @setup,
85
95
  @config)
86
96
  @initializer_broadcast = InitializerBroadcast.new
@@ -97,6 +107,8 @@ module RubyPitaya
97
107
  def run_http
98
108
  HttpRoutes.set :bll, @bll
99
109
  HttpRoutes.set :log, @log
110
+ HttpRoutes.set :redis, @redis_connector.redis
111
+ HttpRoutes.set :mongo, @mongo_connector.mongo
100
112
  HttpRoutes.set :setup, @setup
101
113
  HttpRoutes.set :config, @config
102
114
  HttpRoutes.set :views, [Path::HTTP_VIEWS_PATH] + Path::Plugins::HTTP_VIEWS_PATHS
@@ -172,7 +184,8 @@ module RubyPitaya
172
184
 
173
185
  response = @handler_router.call(handler_name, action_name, @session,
174
186
  @postman, @redis_connector.redis,
175
- @setup, @config, @bll, @log, params)
187
+ @mongo_connector.mongo, @setup, @config,
188
+ @bll, @log, params)
176
189
 
177
190
  delta_time_seconds = ((Time.now.to_f - start_time_seconds) * 1000).round(2)
178
191
 
@@ -0,0 +1,25 @@
1
+ require 'mongo'
2
+
3
+ module RubyPitaya
4
+
5
+ class MongoConnector
6
+
7
+ def initialize(mongo_address, mongo_user, mongo_password, mongo_database_name)
8
+ @mongo_address = mongo_address
9
+ @mongo_user = mongo_user
10
+ @mongo_password = mongo_password
11
+ @mongo_database_name = mongo_database_name
12
+ end
13
+
14
+ def connect
15
+ @mongo_client = Mongo::Client.new([@mongo_address],
16
+ user: @mongo_user,
17
+ password: @mongo_password,
18
+ database: @mongo_database_name)
19
+ end
20
+
21
+ def mongo
22
+ @mongo_client
23
+ end
24
+ end
25
+ end
@@ -8,7 +8,7 @@ module RubyPitaya
8
8
  HANDLERS_FOLDER_PATH = File.join(Dir.pwd, 'app/handlers/')
9
9
  APP_CONFIG_FOLDER_PATH = File.join(Dir.pwd, 'app/config/')
10
10
  APP_SETUP_FOLDER_PATH = File.join(Dir.pwd, 'app/setup/')
11
- MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'db/migration/')
11
+ MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'app/migrations/')
12
12
  PLUGINS_FOLDER_PATH = File.join(Dir.pwd, 'plugins/')
13
13
 
14
14
  ROUTES_FILE_PATH = File.join(Dir.pwd, 'config/routes.rb')
@@ -18,7 +18,7 @@ module RubyPitaya
18
18
 
19
19
  class Core
20
20
  APP_FOLDER_PATH = File.join(__dir__, 'app/')
21
- MIGRATIONS_FOLDER_PATH = File.join(__dir__, 'db/migration/')
21
+ MIGRATIONS_FOLDER_PATH = File.join(__dir__, 'app/migrations/')
22
22
  end
23
23
 
24
24
  class Plugins
@@ -26,7 +26,7 @@ module RubyPitaya
26
26
  HANDLERS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/handlers'))
27
27
  APP_CONFIG_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/config/'))
28
28
  APP_SETUP_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/setup/'))
29
- MIGRATIONS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/db/migration'))
29
+ MIGRATIONS_FOLDER_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/migrations/'))
30
30
  HTTP_VIEWS_PATHS = Dir.glob(File.join(Dir.pwd, 'plugins/*/app/http/views'))
31
31
  end
32
32
  end
@@ -22,6 +22,7 @@ module RubyPitaya
22
22
  @@response = {}
23
23
 
24
24
  initialize_redis
25
+ initialize_mongo
25
26
 
26
27
  @@handler_router ||= HandlerRouter.new()
27
28
 
@@ -29,6 +30,7 @@ module RubyPitaya
29
30
  @@initializer_content = InitializerContent.new(@@bll,
30
31
  @@log,
31
32
  @@redis_connector.redis,
33
+ @@mongo_connector.mongo,
32
34
  @@setup,
33
35
  @@config)
34
36
  @@initializer_broadcast = InitializerBroadcast.new
@@ -40,7 +42,8 @@ module RubyPitaya
40
42
 
41
43
  @@response = @@handler_router.call(handler_name, action_name, @@session,
42
44
  @@postman, @@redis_connector.redis,
43
- @@setup, @@config, @@bll, @@log, params)
45
+ @@mongo_connector.mongo, @@setup,
46
+ @@config, @@bll, @@log, params)
44
47
  end
45
48
 
46
49
  def response
@@ -71,23 +74,23 @@ module RubyPitaya
71
74
  @@setup.add(*keys, value)
72
75
  end
73
76
 
74
- def get_bll
77
+ def bll
75
78
  @@bll
76
79
  end
77
80
 
78
- def get_log
81
+ def log
79
82
  @@log
80
83
  end
81
84
 
82
- def get_session
85
+ def session
83
86
  @@session
84
87
  end
85
88
 
86
- def get_postman
89
+ def postman
87
90
  @@postman
88
91
  end
89
92
 
90
- def get_redis
93
+ def redis
91
94
  @@redis_connector.redis
92
95
  end
93
96
 
@@ -105,5 +108,22 @@ module RubyPitaya
105
108
 
106
109
  @@redis_connector.redis.flushall
107
110
  end
111
+
112
+ def initialize_mongo
113
+ @@mongo_connector ||= nil
114
+
115
+ if @@mongo_connector.nil?
116
+ @@core_setup ||= Setup.new
117
+ mongo_address = @@core_setup['rubypitaya.mongo.url']
118
+ mongo_user = @@core_setup['rubypitaya.mongo.user']
119
+ mongo_password = @@core_setup['rubypitaya.mongo.pass']
120
+ mongo_database_name = @@core_setup['rubypitaya.mongo.database']
121
+ @@mongo_connector = MongoConnector.new(mongo_address, mongo_user,
122
+ mongo_password, mongo_database_name)
123
+ @@mongo_connector.connect
124
+ end
125
+
126
+ @@mongo_connector.mongo.collections.map(&:drop)
127
+ end
108
128
  end
109
129
  end
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.22.0'
2
+ VERSION = '2.25.1'
3
3
  end
data/lib/rubypitaya.rb CHANGED
@@ -38,18 +38,29 @@ module RubyPitaya
38
38
  migration_file_name
39
39
  end
40
40
 
41
- def self.add_plugin(plugin_git_link)
41
+ def self.add_plugin(plugin_git_url, branch_name)
42
42
  Dir.mkdir(Path::PLUGINS_FOLDER_PATH) unless File.exists?(Path::PLUGINS_FOLDER_PATH)
43
43
 
44
- plugin_name = plugin_git_link.scan(/.+\/(.+)\.git/).flatten.first
44
+ plugin_name = plugin_git_url.scan(/.+\/(.+)\.git/).flatten.first
45
45
  plugin_folder_path = File.join(Path::PLUGINS_FOLDER_PATH, plugin_name)
46
46
  plugin_git_path = File.join(plugin_folder_path, '.git/')
47
47
 
48
+ branch_command = ""
49
+ branch_command = "--branch #{branch_name}" unless branch_name.blank?
50
+
48
51
  FileUtils.rm_rf(plugin_folder_path) if File.exists?(plugin_folder_path)
49
- `git -C #{Path::PLUGINS_FOLDER_PATH} clone #{plugin_git_link}`
52
+ puts "git -C #{Path::PLUGINS_FOLDER_PATH} clone --depth 1 #{branch_command} #{plugin_git_url}"
53
+ `git -C #{Path::PLUGINS_FOLDER_PATH} clone --depth 1 #{branch_command} #{plugin_git_url}`
50
54
  FileUtils.rm_rf(plugin_git_path)
51
55
 
52
- plugin_migrations_path = File.join(plugin_folder_path, 'db/migration/')
56
+ Dir.entries(plugin_folder_path).each do |entry|
57
+ entry_path = File.join(plugin_folder_path, entry)
58
+ FileUtils.rm_rf(entry_path) unless entry == 'app' ||
59
+ entry == '.' ||
60
+ entry == '..'
61
+ end
62
+
63
+ plugin_migrations_path = File.join(plugin_folder_path, 'app/migrations/')
53
64
  plugin_migrations_files = Dir[File.join(plugin_migrations_path, '*')]
54
65
  base_migration_timestamp = Time.now.utc.to_i
55
66
 
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.22.0
4
+ version: 2.25.1
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: 2021-07-19 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -258,12 +258,12 @@ files:
258
258
  - "./lib/rubypitaya/app-template/app/handlers/player_handler.rb"
259
259
  - "./lib/rubypitaya/app-template/app/http/hello_world_http.rb"
260
260
  - "./lib/rubypitaya/app-template/app/http/views/hello_world.erb"
261
+ - "./lib/rubypitaya/app-template/app/migrations/1606736477_create_player_migration.rb"
261
262
  - "./lib/rubypitaya/app-template/app/models/player.rb"
262
263
  - "./lib/rubypitaya/app-template/app/models/user.rb"
263
264
  - "./lib/rubypitaya/app-template/app/setup/rubypitaya.yml"
264
265
  - "./lib/rubypitaya/app-template/bin/console"
265
266
  - "./lib/rubypitaya/app-template/config/routes.rb"
266
- - "./lib/rubypitaya/app-template/db/migration/1606736477_create_player_migration.rb"
267
267
  - "./lib/rubypitaya/app-template/docker-compose.yml"
268
268
  - "./lib/rubypitaya/app-template/docker/dev/Dockerfile"
269
269
  - "./lib/rubypitaya/app-template/docker/entrypoint.sh"
@@ -279,6 +279,7 @@ files:
279
279
  - "./lib/rubypitaya/app-template/helm/templates/deployments/connector.yaml"
280
280
  - "./lib/rubypitaya/app-template/helm/templates/deployments/gameserver-nginx.yaml"
281
281
  - "./lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml"
282
+ - "./lib/rubypitaya/app-template/helm/templates/pods/gameserver.yaml"
282
283
  - "./lib/rubypitaya/app-template/helm/templates/role-bindings/rubypitaya.yaml"
283
284
  - "./lib/rubypitaya/app-template/helm/templates/roles/rubypitaya.yaml"
284
285
  - "./lib/rubypitaya/app-template/helm/templates/service-accounts/rubypitaya.yaml"
@@ -316,13 +317,13 @@ files:
316
317
  - "./lib/rubypitaya/app-template/spec/hello_world_handler_spec.rb"
317
318
  - "./lib/rubypitaya/app-template/spec/player_handler_spec.rb"
318
319
  - "./lib/rubypitaya/app-template/spec/spec_helper.rb"
320
+ - "./lib/rubypitaya/core/app/migrations/0000000001_create_user_migration.rb"
319
321
  - "./lib/rubypitaya/core/app/models/user.rb"
320
322
  - "./lib/rubypitaya/core/application_files_importer.rb"
321
323
  - "./lib/rubypitaya/core/config.rb"
322
324
  - "./lib/rubypitaya/core/config_core.rb"
323
325
  - "./lib/rubypitaya/core/database_config.rb"
324
326
  - "./lib/rubypitaya/core/database_connector.rb"
325
- - "./lib/rubypitaya/core/db/migration/0000000001_create_user_migration.rb"
326
327
  - "./lib/rubypitaya/core/etcd_connector.rb"
327
328
  - "./lib/rubypitaya/core/handler_base.rb"
328
329
  - "./lib/rubypitaya/core/handler_router.rb"
@@ -333,6 +334,7 @@ files:
333
334
  - "./lib/rubypitaya/core/initializer_content.rb"
334
335
  - "./lib/rubypitaya/core/instance_holder.rb"
335
336
  - "./lib/rubypitaya/core/main.rb"
337
+ - "./lib/rubypitaya/core/mongo_connector.rb"
336
338
  - "./lib/rubypitaya/core/nats_connector.rb"
337
339
  - "./lib/rubypitaya/core/parameters.rb"
338
340
  - "./lib/rubypitaya/core/path.rb"