rubypitaya 2.6.3 → 2.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) 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 +34 -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/prod/Dockerfile +5 -1
  14. data/lib/rubypitaya/app-template/kubernetes/README.md +22 -2
  15. data/lib/rubypitaya/app-template/kubernetes/gameplay/deployment-nginx.yaml +130 -0
  16. data/lib/rubypitaya/app-template/kubernetes/gameplay/gameplay-template.yaml +29 -0
  17. data/lib/rubypitaya/app-template/kubernetes/gameplay/nginx.conf +13 -0
  18. data/lib/rubypitaya/app-template/kubernetes/gameplay/service-nginx.yaml +928 -0
  19. data/lib/rubypitaya/app-template/kubernetes/role-rubypitaya.yaml +31 -0
  20. data/lib/rubypitaya/app-template/kubernetes/rolebinding-rubypitaya.yaml +13 -0
  21. data/lib/rubypitaya/app-template/kubernetes/service-etcd.yaml +1 -1
  22. data/lib/rubypitaya/app-template/kubernetes/service-nats.yaml +1 -1
  23. data/lib/rubypitaya/app-template/kubernetes/service-postgres.yaml +1 -1
  24. data/lib/rubypitaya/app-template/kubernetes/service-redis.yaml +1 -1
  25. data/lib/rubypitaya/core/http_routes.rb +7 -1
  26. data/lib/rubypitaya/core/initializer_content.rb +1 -1
  27. data/lib/rubypitaya/core/main.rb +2 -1
  28. data/lib/rubypitaya/version.rb +1 -1
  29. metadata +9 -4
  30. data/lib/rubypitaya/app-template/docker/prod/Makefile +0 -67
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b367c2b1b6a1bbd272c216dc53b07444bc76ee014126735d2e815299910dfea
4
- data.tar.gz: 626cbd30f338f766de59000a1a7b659d6086e7b64b80c9c6090c05c9e493f908
3
+ metadata.gz: 623c57d88899a89b5ff791d083b7f6025922f2b3a2c69d4d11ba2b7d328fb1c5
4
+ data.tar.gz: fae9b7a11220d84d71f3775d6daeabf24628dd2db9eb48a2cf0b235643c864f3
5
5
  SHA512:
6
- metadata.gz: e17f34d833d731125d1a1940b235f5966dba02b82a9b8688cd825bae0902816296bc39c0a8dc0c9be7a13368ca145cbc339b16634ae758b8475ce0c8392eed82
7
- data.tar.gz: cead4eea29f929c9cde46fa007967052bb735f83088359b59360fbd15402b9ae87c9ca84ded405ed3e4d1653ae11ee8a505a6f8ec5c3052beb7a0f9328658b60
6
+ metadata.gz: e3dd0f6775614ab1462fc2651582f9ad25850d52de90889b756879dd02bc0446f20564656b8d90bbb98d79a25a5da6bcb0c7dbcf220afd571a5643a6fa61d5b5
7
+ data.tar.gz: 7316e7f5846839f4c59ebf2607da8f032b10560c03ba80e19b4a551f528ef96587516b9d516c340b128ef443791642ad23299d3c4e7886a8a28b2d943825a840
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.6.3'
3
+ gem 'rubypitaya', '2.7.4'
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.6.3)
72
+ rubypitaya (2.7.4)
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.6.3)
109
+ rubypitaya (= 2.7.4)
110
110
 
111
111
  BUNDLED WITH
112
112
  1.17.2
@@ -1,3 +1,8 @@
1
+ IMAGE_TAG ?= latest
2
+ IMAGE_REGISTRY ?= [put-your-registry-here]
3
+ KUBE_NAMESPACE ?= [put-your-namespace-here]
4
+ KUBE_DEPLOYMENT_SERVER ?= rubypitaya
5
+
1
6
  ## Run ruby pitaya metagame project
2
7
  run:
3
8
  @docker-compose run --service-ports --rm rubypitaya bundle exec rubypitaya run
@@ -48,15 +53,15 @@ generate-gemfilelock:
48
53
 
49
54
  ## Build image to production environment
50
55
  prod-build-image:
51
- @docker build . -f docker/prod/Dockerfile -t [registry-address]:$(IMAGE_TAG)
56
+ @docker build . -f docker/prod/Dockerfile -t $(IMAGE_REGISTRY):$(IMAGE_TAG)
52
57
 
53
58
  ## Push prod image to gitlab
54
59
  prod-push-image:
55
- @docker push [registry-address]:$(IMAGE_TAG)
60
+ @docker push $(IMAGE_REGISTRY):$(IMAGE_TAG)
56
61
 
57
62
  ## Deploy prod image to kubernetes cluster
58
63
  prod-deploy-image:
59
- kubectl -n $(PROD_NAMESPACE) set image deployment rubypitaya rubypitaya=[registry-address]:$(IMAGE_TAG)
64
+ kubectl --context='$(KUBECONTEXT)' -n $(KUBE_NAMESPACE) set image deployment $(KUBE_DEPLOYMENT_SERVER) $(KUBE_DEPLOYMENT_SERVER)=$(IMAGE_REGISTRY):$(IMAGE_TAG)
60
65
 
61
66
  .DEFAULT_GOAL := show-help
62
67
 
@@ -98,6 +103,3 @@ show-help:
98
103
  } \
99
104
  printf "\n"; \
100
105
  }'
101
-
102
-
103
-
@@ -1,36 +1,39 @@
1
- class AppInitializer < RubyPitaya::InitializerBase
1
+ module MyApp
2
2
 
3
- # method: run
4
- # parameter: initializer_content
5
- # attributes:
6
- # - bll
7
- # - class: RubyPitaya::InstanceHolder
8
- # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/instance_holder.rb
9
- # - methods:
10
- # - add_instance(key, instance)
11
- # - add any instance to any key
12
- # - [](key)
13
- # - get instance by key
14
- # - redis
15
- # - link: https://github.com/redis/redis-rb/
16
- # - config
17
- # - class: RubyPitaya::Config
18
- # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
19
- # - methods:
20
- # - [](key)
21
- # - get config file by config path
22
- # - setup
23
- # - class: RubyPitaya::Setup
24
- # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/setup.rb
25
- # - methods:
26
- # - [](key)
27
- # - get config file by config path
3
+ class AppInitializer < RubyPitaya::InitializerBase
28
4
 
29
- def run(initializer_content)
30
- bll = initializer_content.bll
5
+ # method: run
6
+ # parameter: initializer_content
7
+ # attributes:
8
+ # - bll
9
+ # - class: RubyPitaya::InstanceHolder
10
+ # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/instance_holder.rb
11
+ # - methods:
12
+ # - add_instance(key, instance)
13
+ # - add any instance to any key
14
+ # - [](key)
15
+ # - get instance by key
16
+ # - redis
17
+ # - link: https://github.com/redis/redis-rb/
18
+ # - config
19
+ # - class: RubyPitaya::Config
20
+ # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
21
+ # - methods:
22
+ # - [](key)
23
+ # - get config file by config path
24
+ # - setup
25
+ # - class: RubyPitaya::Setup
26
+ # - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/setup.rb
27
+ # - methods:
28
+ # - [](key)
29
+ # - get config file by config path
31
30
 
32
- playerBll = PlayerBLL.new
31
+ def run(initializer_content)
32
+ bll = initializer_content.bll
33
33
 
34
- bll.add_instance(:player, playerBll)
34
+ playerBll = PlayerBLL.new
35
+
36
+ bll.add_instance(:player, playerBll)
37
+ end
35
38
  end
36
- end
39
+ end
@@ -1,11 +1,14 @@
1
- class PlayerBLL
1
+ module MyApp
2
+
3
+ class PlayerBLL
2
4
 
3
- def create_new_player(setup, config)
4
- name = config['initial_player']['name']
5
- gold = setup['initial_player.wallet.gold']
5
+ def create_new_player(setup, config)
6
+ name = config['initial_player']['name']
7
+ gold = setup['initial_player.wallet.gold']
6
8
 
7
- player = Player.new(name: name, gold: gold, user: User.new)
8
- player.save
9
- player
9
+ player = Player.new(name: name, gold: gold, user: User.new)
10
+ player.save
11
+ player
12
+ end
10
13
  end
11
14
  end
@@ -1,22 +1,25 @@
1
- class StatusCodes
1
+ module MyApp
2
+
3
+ class StatusCodes
2
4
 
3
- CODE_OK = RubyPitaya::StatusCodes::CODE_OK
5
+ CODE_OK = RubyPitaya::StatusCodes::CODE_OK
4
6
 
5
- ################
6
- ## Existent Codes
7
- ################
8
- ## Success codes
9
- #
10
- # RubyPitaya::StatusCodes::CODE_OK = 'RP-200'
11
- #
12
- #
13
- ## Error codes
14
- # RubyPitaya::StatusCodes::CODE_UNKNOWN = 'RP-000'
15
- # RubyPitaya::StatusCodes::CODE_HANDLER_NOT_FOUND = 'RP-001'
16
- # RubyPitaya::StatusCodes::CODE_ACTION_NOT_FOUND = 'RP-002'
17
- # RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED = 'RP-003'
18
- # RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR = 'RP-004'
19
- #
20
- # RubyPitaya::StatusCodes::Connector::CODE_UNKNOWN = 'PIT-000'
21
- ################
7
+ ################
8
+ ## Existent Codes
9
+ ################
10
+ ## Success codes
11
+ #
12
+ # RubyPitaya::StatusCodes::CODE_OK = 'RP-200'
13
+ #
14
+ #
15
+ ## Error codes
16
+ # RubyPitaya::StatusCodes::CODE_UNKNOWN = 'RP-000'
17
+ # RubyPitaya::StatusCodes::CODE_HANDLER_NOT_FOUND = 'RP-001'
18
+ # RubyPitaya::StatusCodes::CODE_ACTION_NOT_FOUND = 'RP-002'
19
+ # RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED = 'RP-003'
20
+ # RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR = 'RP-004'
21
+ #
22
+ # RubyPitaya::StatusCodes::Connector::CODE_UNKNOWN = 'PIT-000'
23
+ ################
24
+ end
22
25
  end
@@ -1,4 +1,5 @@
1
1
  module MyApp
2
+
2
3
  class HelloWorldHandler < RubyPitaya::HandlerBase
3
4
 
4
5
  non_authenticated_actions :sayHello
@@ -1,79 +1,82 @@
1
- class PlayerHandler < RubyPitaya::HandlerBase
1
+ module MyApp
2
+
3
+ class PlayerHandler < RubyPitaya::HandlerBase
2
4
 
3
- # class: HandlerBase
4
- # attributes:
5
- # - @bll
6
- # - class: InstanceHolder
7
- # - methods:
8
- # - [](key)
9
- # - info: get bll by key
10
- #
11
- # - @redis
12
- # - link: https://github.com/redis/redis-rb/
13
- #
14
- # - @config
15
- # - info: Hash with config json files inside of 'app/config'
16
- # - example:
17
- # Given you have the following file "app/config/initial_player.json"
18
- # And this json content is {'name': 'Guest'}
19
- # And you can get the initial player name
20
- # Then you can run the following code: @config['initial_player']['name']
21
- #
22
- # - @params
23
- # - info: Special hash with the request parameters
24
- # - link: https://api.rubyonrails.org/classes/ActionController/Parameters.html
25
- #
26
- # - @session
27
- # - attributes:
28
- # - id :: session id
29
- # - uid :: user id
30
- # - data :: session data
31
- # - metadata :: session data
32
- # - frontend_id :: connector server id
33
- #
34
- # - @postman
35
- # - info: Send messages to server and clients
36
- # - methods:
37
- # - bind_session(session)
38
- # - info:
39
- # Send a session to connector, you can use to set the userId
40
- # of the session, for example you can set an userId on
41
- # @session, like `@session.uid = '123'`, and then you can
42
- # bind this session with `@postman.bind_session(@session)`
5
+ # class: HandlerBase
6
+ # attributes:
7
+ # - @bll
8
+ # - class: InstanceHolder
9
+ # - methods:
10
+ # - [](key)
11
+ # - info: get bll by key
12
+ #
13
+ # - @redis
14
+ # - link: https://github.com/redis/redis-rb/
15
+ #
16
+ # - @config
17
+ # - info: Hash with config json files inside of 'app/config'
18
+ # - example:
19
+ # Given you have the following file "app/config/initial_player.json"
20
+ # And this json content is {'name': 'Guest'}
21
+ # And you can get the initial player name
22
+ # Then you can run the following code: @config['initial_player']['name']
23
+ #
24
+ # - @params
25
+ # - info: Special hash with the request parameters
26
+ # - link: https://api.rubyonrails.org/classes/ActionController/Parameters.html
27
+ #
28
+ # - @session
29
+ # - attributes:
30
+ # - id :: session id
31
+ # - uid :: user id
32
+ # - data :: session data
33
+ # - metadata :: session data
34
+ # - frontend_id :: connector server id
35
+ #
36
+ # - @postman
37
+ # - info: Send messages to server and clients
38
+ # - methods:
39
+ # - bind_session(session)
40
+ # - info:
41
+ # Send a session to connector, you can use to set the userId
42
+ # of the session, for example you can set an userId on
43
+ # @session, like `@session.uid = '123'`, and then you can
44
+ # bind this session with `@postman.bind_session(@session)`
43
45
 
44
- non_authenticated_actions :authenticate
46
+ non_authenticated_actions :authenticate
45
47
 
46
- def authenticate
47
- user_id = @params[:userId]
48
+ def authenticate
49
+ user_id = @params[:userId]
48
50
 
49
- player = Player.find_by_user_id(user_id)
50
- player = @bll[:player].create_new_player(@setup, @config) if player.nil?
51
+ player = Player.find_by_user_id(user_id)
52
+ player = @bll[:player].create_new_player(@setup, @config) if player.nil?
51
53
 
52
- @session.uid = player.user_id
54
+ @session.uid = player.user_id
53
55
 
54
- bind_session_response = @postman.bind_session(@session)
56
+ bind_session_response = @postman.bind_session(@session)
55
57
 
56
- unless bind_session_response.dig(:error, :code).nil?
57
- return response = {
58
- code: RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR,
59
- msg: 'Error to authenticate',
58
+ unless bind_session_response.dig(:error, :code).nil?
59
+ return response = {
60
+ code: RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR,
61
+ msg: 'Error to authenticate',
62
+ }
63
+ end
64
+
65
+ response = {
66
+ code: StatusCodes::CODE_OK,
67
+ data: player.to_hash,
60
68
  }
61
69
  end
62
70
 
63
- response = {
64
- code: StatusCodes::CODE_OK,
65
- data: player.to_hash,
66
- }
67
- end
68
-
69
- def getInfo
70
- user_id = @session.uid
71
+ def getInfo
72
+ user_id = @session.uid
71
73
 
72
- player = Player.find_by_user_id(user_id)
74
+ player = Player.find_by_user_id(user_id)
73
75
 
74
- response = {
75
- code: StatusCodes::CODE_OK,
76
- data: player.to_hash,
77
- }
76
+ response = {
77
+ code: StatusCodes::CODE_OK,
78
+ data: player.to_hash,
79
+ }
80
+ end
78
81
  end
79
- end
82
+ end
@@ -1,16 +1,19 @@
1
1
  require 'active_record'
2
2
 
3
- class Player < ActiveRecord::Base
3
+ module MyApp
4
4
 
5
- belongs_to :user
5
+ class Player < ActiveRecord::Base
6
6
 
7
- validates_presence_of :name, :gold, :user
7
+ belongs_to :user
8
8
 
9
- def to_hash
10
- {
11
- name: name,
12
- gold: gold,
13
- userId: user_id,
14
- }
9
+ validates_presence_of :name, :gold, :user
10
+
11
+ def to_hash
12
+ {
13
+ name: name,
14
+ gold: gold,
15
+ userId: user_id,
16
+ }
17
+ end
15
18
  end
16
- end
19
+ end
@@ -1,6 +1,6 @@
1
1
  class Routes < RubyPitaya::RoutesBase
2
2
 
3
- # class: RoutesBase
3
+ # class: RoutesBase
4
4
  # methods:
5
5
  # - match('new_handler_name', to: 'ClassHandler')
6
6
  # - Defines a new name to handler
@@ -10,9 +10,13 @@ COPY . .
10
10
 
11
11
  FROM ruby:2.6.6-slim
12
12
 
13
- RUN apt update && apt install -y postgresql-client --no-install-recommends
13
+ RUN apt update && apt install -y postgresql-client curl python3 bash vim --no-install-recommends
14
14
  RUN rm -rf /var/lib/apt/lists/*
15
15
 
16
+ RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
17
+ RUN chmod +x ./kubectl
18
+ RUN mv ./kubectl /usr/local/bin
19
+
16
20
  COPY --from=builder /usr/local/etc /usr/local/etc
17
21
  COPY --from=builder /usr/local/bundle /usr/local/bundle
18
22
  COPY --from=builder /usr/local/bin/ruby /usr/local/bin/ruby
@@ -4,12 +4,14 @@ Kubernetes Configuration
4
4
  Set namespace
5
5
  -------------
6
6
 
7
- Open files "deployment-*.yaml" and set the correct namespace on links
7
+ Open files "deployment-*.yaml", "role-rubypitaya.yaml" and "rolebinding-rubypitaya.yaml" and set the correct namespace on fields and links
8
8
 
9
9
 
10
10
  Apply sequence
11
11
  --------------
12
12
 
13
+ If you already has a postgres don't apply the postgres files and change the
14
+ deployment-rubypitaya.yaml postgres env vars.
13
15
  Run the following command on the listed files.
14
16
  But remember to put your namespace and your KUBECONFIG env var if you need.
15
17
 
@@ -57,4 +59,22 @@ $ kubectl apply -f [file-path]
57
59
  ```
58
60
 
59
61
  deployment-rubypitaya.yaml
60
- service-rubypitaya.yaml
62
+ service-rubypitaya.yaml
63
+
64
+
65
+ Setup nginx for gameserver
66
+ --------------------------
67
+
68
+ Run the following command to create configmap with nginx.conf file.
69
+ But remember to put your namespace and your KUBECONFIG env var if you need.
70
+
71
+ ```sh
72
+ $ kubectl create configmap nginx-config --from-file=./gameplay/nginx.conf
73
+ ```
74
+
75
+ Create the deployments and services for nginx:
76
+
77
+ ```sh
78
+ $ kubectl apply -f ./gameplay/deployment-nginx.yaml
79
+ $ kubectl apply -f ./gameplay/service-nginx.yaml
80
+ ```