rubypitaya 2.6.4 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubypitaya/app-template/Gemfile +1 -1
- data/lib/rubypitaya/app-template/Gemfile.lock +2 -2
- data/lib/rubypitaya/app-template/app/app_initializer.rb +34 -31
- data/lib/rubypitaya/app-template/app/bll/player_bll.rb +10 -7
- data/lib/rubypitaya/app-template/app/constants/status_codes.rb +22 -19
- data/lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb +1 -0
- data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +69 -66
- data/lib/rubypitaya/app-template/app/models/player.rb +13 -10
- data/lib/rubypitaya/app-template/config/routes.rb +1 -1
- data/lib/rubypitaya/app-template/db/migration/{0000000002_create_player_migration.rb → 1606736477_create_player_migration.rb} +0 -0
- data/lib/rubypitaya/app-template/docker/prod/Dockerfile +5 -1
- data/lib/rubypitaya/app-template/kubernetes/README.md +22 -2
- data/lib/rubypitaya/app-template/kubernetes/gameplay/deployment-nginx.yaml +130 -0
- data/lib/rubypitaya/app-template/kubernetes/gameplay/gameplay-template.yaml +29 -0
- data/lib/rubypitaya/app-template/kubernetes/gameplay/nginx.conf +13 -0
- data/lib/rubypitaya/app-template/kubernetes/gameplay/service-nginx.yaml +928 -0
- data/lib/rubypitaya/app-template/kubernetes/role-rubypitaya.yaml +31 -0
- data/lib/rubypitaya/app-template/kubernetes/rolebinding-rubypitaya.yaml +13 -0
- data/lib/rubypitaya/app-template/kubernetes/service-etcd.yaml +1 -1
- data/lib/rubypitaya/app-template/kubernetes/service-nats.yaml +1 -1
- data/lib/rubypitaya/app-template/kubernetes/service-postgres.yaml +1 -1
- data/lib/rubypitaya/app-template/kubernetes/service-redis.yaml +1 -1
- data/lib/rubypitaya/version.rb +1 -1
- metadata +9 -4
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87587b02594a88b88edbf8c1f834a088a375a159d8382aae4199529690d7adad
|
4
|
+
data.tar.gz: 56ba5c551c06c7cc36feaede56353adb522a917047fefc47788b7f49409c73b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b0512be9ad4f86ed742a49856fd814d2ad116c2895b89362e9bb623bcc1aa29019c08eb0ed42f16f6c28b3b1977c7ff8d2634c37574d17f9261a17af1b966c
|
7
|
+
data.tar.gz: 0a0b2173420b168a6326465da9272db42ad04b67c8b9573a38bde67b9d08d7811e69f1f5db549d9de64dfb5058736298f97276d3a7c6944c994bd9018689e1ae
|
@@ -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.
|
72
|
+
rubypitaya (2.7.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.
|
109
|
+
rubypitaya (= 2.7.0)
|
110
110
|
|
111
111
|
BUNDLED WITH
|
112
112
|
1.17.2
|
@@ -1,36 +1,39 @@
|
|
1
|
-
|
1
|
+
module MyApp
|
2
2
|
|
3
|
-
|
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
|
-
|
30
|
-
|
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
|
-
|
31
|
+
def run(initializer_content)
|
32
|
+
bll = initializer_content.bll
|
33
33
|
|
34
|
-
|
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
|
-
|
1
|
+
module MyApp
|
2
|
+
|
3
|
+
class PlayerBLL
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
def create_new_player(setup, config)
|
6
|
+
name = config['initial_player']['name']
|
7
|
+
gold = setup['initial_player.wallet.gold']
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
1
|
+
module MyApp
|
2
|
+
|
3
|
+
class StatusCodes
|
2
4
|
|
3
|
-
|
5
|
+
CODE_OK = RubyPitaya::StatusCodes::CODE_OK
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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,79 +1,82 @@
|
|
1
|
-
|
1
|
+
module MyApp
|
2
|
+
|
3
|
+
class PlayerHandler < RubyPitaya::HandlerBase
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
46
|
+
non_authenticated_actions :authenticate
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
+
def authenticate
|
49
|
+
user_id = @params[:userId]
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
player = Player.find_by_user_id(user_id)
|
52
|
+
player = @bll[:player].create_new_player(@setup, @config) if player.nil?
|
51
53
|
|
52
|
-
|
54
|
+
@session.uid = player.user_id
|
53
55
|
|
54
|
-
|
56
|
+
bind_session_response = @postman.bind_session(@session)
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
64
|
-
|
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
|
-
|
74
|
+
player = Player.find_by_user_id(user_id)
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
3
|
+
module MyApp
|
4
4
|
|
5
|
-
|
5
|
+
class Player < ActiveRecord::Base
|
6
6
|
|
7
|
-
|
7
|
+
belongs_to :user
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
File without changes
|
@@ -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
|
+
```
|
@@ -0,0 +1,130 @@
|
|
1
|
+
apiVersion: apps/v1
|
2
|
+
kind: Deployment
|
3
|
+
metadata:
|
4
|
+
name: gameplay-nginx
|
5
|
+
labels:
|
6
|
+
app: gameplay-nginx
|
7
|
+
spec:
|
8
|
+
replicas: 1
|
9
|
+
selector:
|
10
|
+
matchLabels:
|
11
|
+
app: gameplay-nginx
|
12
|
+
template:
|
13
|
+
metadata:
|
14
|
+
labels:
|
15
|
+
app: gameplay-nginx
|
16
|
+
spec:
|
17
|
+
containers:
|
18
|
+
- name: gameplay-nginx
|
19
|
+
image: nginx:1.18.0
|
20
|
+
ports:
|
21
|
+
- containerPort: 5000
|
22
|
+
name: "port-5000"
|
23
|
+
- containerPort: 5001
|
24
|
+
name: "port-5001"
|
25
|
+
- containerPort: 5002
|
26
|
+
name: "port-5002"
|
27
|
+
- containerPort: 5003
|
28
|
+
name: "port-5003"
|
29
|
+
- containerPort: 5004
|
30
|
+
name: "port-5004"
|
31
|
+
- containerPort: 5005
|
32
|
+
name: "port-5005"
|
33
|
+
- containerPort: 5006
|
34
|
+
name: "port-5006"
|
35
|
+
- containerPort: 5007
|
36
|
+
name: "port-5007"
|
37
|
+
- containerPort: 5008
|
38
|
+
name: "port-5008"
|
39
|
+
- containerPort: 5009
|
40
|
+
name: "port-5009"
|
41
|
+
- containerPort: 5010
|
42
|
+
name: "port-5010"
|
43
|
+
- containerPort: 5011
|
44
|
+
name: "port-5011"
|
45
|
+
- containerPort: 5012
|
46
|
+
name: "port-5012"
|
47
|
+
- containerPort: 5013
|
48
|
+
name: "port-5013"
|
49
|
+
- containerPort: 5014
|
50
|
+
name: "port-5014"
|
51
|
+
- containerPort: 5015
|
52
|
+
name: "port-5015"
|
53
|
+
- containerPort: 5016
|
54
|
+
name: "port-5016"
|
55
|
+
- containerPort: 5017
|
56
|
+
name: "port-5017"
|
57
|
+
- containerPort: 5018
|
58
|
+
name: "port-5018"
|
59
|
+
- containerPort: 5019
|
60
|
+
name: "port-5019"
|
61
|
+
- containerPort: 5020
|
62
|
+
name: "port-5020"
|
63
|
+
- containerPort: 5021
|
64
|
+
name: "port-5021"
|
65
|
+
- containerPort: 5022
|
66
|
+
name: "port-5022"
|
67
|
+
- containerPort: 5023
|
68
|
+
name: "port-5023"
|
69
|
+
- containerPort: 5024
|
70
|
+
name: "port-5024"
|
71
|
+
- containerPort: 5025
|
72
|
+
name: "port-5025"
|
73
|
+
- containerPort: 5026
|
74
|
+
name: "port-5026"
|
75
|
+
- containerPort: 5027
|
76
|
+
name: "port-5027"
|
77
|
+
- containerPort: 5028
|
78
|
+
name: "port-5028"
|
79
|
+
- containerPort: 5029
|
80
|
+
name: "port-5029"
|
81
|
+
- containerPort: 5030
|
82
|
+
name: "port-5030"
|
83
|
+
- containerPort: 5031
|
84
|
+
name: "port-5031"
|
85
|
+
- containerPort: 5032
|
86
|
+
name: "port-5032"
|
87
|
+
- containerPort: 5033
|
88
|
+
name: "port-5033"
|
89
|
+
- containerPort: 5034
|
90
|
+
name: "port-5034"
|
91
|
+
- containerPort: 5035
|
92
|
+
name: "port-5035"
|
93
|
+
- containerPort: 5036
|
94
|
+
name: "port-5036"
|
95
|
+
- containerPort: 5037
|
96
|
+
name: "port-5037"
|
97
|
+
- containerPort: 5038
|
98
|
+
name: "port-5038"
|
99
|
+
- containerPort: 5039
|
100
|
+
name: "port-5039"
|
101
|
+
- containerPort: 5040
|
102
|
+
name: "port-5040"
|
103
|
+
- containerPort: 5041
|
104
|
+
name: "port-5041"
|
105
|
+
- containerPort: 5042
|
106
|
+
name: "port-5042"
|
107
|
+
- containerPort: 5043
|
108
|
+
name: "port-5043"
|
109
|
+
- containerPort: 5044
|
110
|
+
name: "port-5044"
|
111
|
+
- containerPort: 5045
|
112
|
+
name: "port-5045"
|
113
|
+
- containerPort: 5046
|
114
|
+
name: "port-5046"
|
115
|
+
- containerPort: 5047
|
116
|
+
name: "port-5047"
|
117
|
+
- containerPort: 5048
|
118
|
+
name: "port-5048"
|
119
|
+
- containerPort: 5049
|
120
|
+
name: "port-5049"
|
121
|
+
- containerPort: 5050
|
122
|
+
name: "port-5050"
|
123
|
+
volumeMounts:
|
124
|
+
- name: nginx-config
|
125
|
+
mountPath: /etc/nginx/nginx.conf
|
126
|
+
subPath: nginx.conf
|
127
|
+
volumes:
|
128
|
+
- name: nginx-config
|
129
|
+
configMap:
|
130
|
+
name: nginxconf
|