rubypitaya 2.18.0 → 2.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubypitaya/app-template/Gemfile +1 -1
  3. data/lib/rubypitaya/app-template/Gemfile.lock +5 -5
  4. data/lib/rubypitaya/app-template/Makefile +1 -1
  5. data/lib/rubypitaya/app-template/docker-compose.yml +4 -0
  6. data/lib/rubypitaya/app-template/docker/dev/Dockerfile +10 -6
  7. data/lib/rubypitaya/app-template/docker/entrypoint.sh +2 -4
  8. data/lib/rubypitaya/app-template/docker/prod/Dockerfile +16 -7
  9. data/lib/rubypitaya/app-template/docker/wait_for.sh +184 -0
  10. data/lib/rubypitaya/app-template/helm/Chart.yaml +4 -0
  11. data/lib/rubypitaya/app-template/helm/templates/config-maps/nginx-config.yaml +9 -0
  12. data/lib/rubypitaya/app-template/helm/templates/deployments/connector.yaml +38 -0
  13. data/lib/rubypitaya/app-template/helm/templates/deployments/gameserver-nginx.yaml +40 -0
  14. data/lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml +71 -0
  15. data/lib/rubypitaya/app-template/helm/templates/role-bindings/rubypitaya.yaml +12 -0
  16. data/lib/rubypitaya/app-template/helm/templates/roles/rubypitaya.yaml +31 -0
  17. data/lib/rubypitaya/app-template/helm/templates/service-accounts/rubypitaya.yaml +4 -0
  18. data/lib/rubypitaya/app-template/helm/templates/services/connector.yaml +13 -0
  19. data/lib/rubypitaya/app-template/helm/templates/services/etcd.yaml +18 -0
  20. data/lib/rubypitaya/app-template/helm/templates/services/gameserver-nginx.yaml +20 -0
  21. data/lib/rubypitaya/app-template/helm/templates/services/gameserver.yaml +20 -0
  22. data/lib/rubypitaya/app-template/helm/templates/services/nats.yaml +13 -0
  23. data/lib/rubypitaya/app-template/helm/templates/services/redis.yaml +14 -0
  24. data/lib/rubypitaya/app-template/helm/templates/services/rubypitaya.yaml +13 -0
  25. data/lib/rubypitaya/app-template/helm/templates/statefulsets/etcd.yaml +28 -0
  26. data/lib/rubypitaya/app-template/helm/templates/statefulsets/nats.yaml +26 -0
  27. data/lib/rubypitaya/app-template/helm/templates/statefulsets/redis.yaml +26 -0
  28. data/lib/rubypitaya/app-template/helm/values.yaml +32 -0
  29. data/lib/rubypitaya/core/config.rb +5 -1
  30. data/lib/rubypitaya/core/handler_base.rb +11 -0
  31. data/lib/rubypitaya/core/handler_router.rb +3 -11
  32. data/lib/rubypitaya/core/http_routes.rb +30 -0
  33. data/lib/rubypitaya/core/main.rb +4 -3
  34. data/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb +2 -2
  35. data/lib/rubypitaya/version.rb +1 -1
  36. metadata +22 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38d15208a32190c01690735d3d8433bb0f8cc9b6f71a64f7897ba668c21e4e97
4
- data.tar.gz: 7396c21b202d611ea5945fd9838b68323b4751777d3e154b20b31557ee470b7a
3
+ metadata.gz: 29e44f8dac6ea62a79303ae177f79515dc38309175c0e30b54fd95c0a7a7237e
4
+ data.tar.gz: cd1a3663b60d5dbd62e521d7590560dad861f6eb857033001cef259ada067149
5
5
  SHA512:
6
- metadata.gz: 6b70755f160f42aa9a145bf55c0709bb82ec92f1f2105874127439bdc286ea124e7f2093cdae34a377d595bb54e21e75af244d34cbd9c30f8feac08849db7d9a
7
- data.tar.gz: 50df16ee2575fd5840b0af30cfa3aedb9a7e4b35d27291a3a484ac2233b09b41700618ef9a1d8b2223cc1dba3e0cc0d8c7fc42a168971e548bd0301e34b77e7d
6
+ metadata.gz: baee0fc660cb49a6f68ef705ea371b29e1f6dbb7da0db714d88d25ffc593fd8b94155a296ae8341454a9b79e33a3251a471b19256dd9c1bcf49ee84182692ea4
7
+ data.tar.gz: adf400ab74394136cfdfe99688368996f39ddc4cbd9f57671d386ea2fa7bbf1074927fdb4a51da9239b8998e546a8db2aacb73a16aea78ee682f474b3072039b
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.18.0'
3
+ gem 'rubypitaya', '2.19.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.14.0'
@@ -50,11 +50,11 @@ GEM
50
50
  etcdv3 (0.10.2)
51
51
  grpc (~> 1.17)
52
52
  eventmachine (1.2.7)
53
- ffi (1.14.2)
54
- google-protobuf (3.15.3-x86_64-linux)
53
+ ffi (1.15.0)
54
+ google-protobuf (3.15.5)
55
55
  googleapis-common-protos-types (1.0.6)
56
56
  google-protobuf (~> 3.14)
57
- grpc (1.36.0-x86_64-linux)
57
+ grpc (1.36.0)
58
58
  google-protobuf (~> 3.14)
59
59
  googleapis-common-protos-types (~> 1.0)
60
60
  i18n (1.8.9)
@@ -108,7 +108,7 @@ GEM
108
108
  rspec-support (~> 3.10.0)
109
109
  rspec-support (3.10.2)
110
110
  ruby2_keywords (0.0.4)
111
- rubypitaya (2.18.0)
111
+ rubypitaya (2.19.0)
112
112
  activerecord (= 6.1.3)
113
113
  etcdv3 (= 0.10.2)
114
114
  eventmachine (= 1.2.7)
@@ -149,7 +149,7 @@ DEPENDENCIES
149
149
  listen (= 3.4.1)
150
150
  pry (= 0.14.0)
151
151
  rspec (= 3.10.0)
152
- rubypitaya (= 2.18.0)
152
+ rubypitaya (= 2.19.0)
153
153
 
154
154
  BUNDLED WITH
155
155
  2.1.4
@@ -41,7 +41,7 @@ test-cucumber:
41
41
  ## Update gems dependencies on Gemfile.lock
42
42
  update-dependencies:
43
43
  @rm -f Gemfile.lock
44
- @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.7.2 bundle install
44
+ @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.7.2-slim bundle install
45
45
 
46
46
  ## + Improve metagame
47
47
 
@@ -69,9 +69,13 @@ services:
69
69
  ETCD_LEASE_SECONDS: '60'
70
70
  REDIS_URL: 'redis://redis:6379'
71
71
  DATABASE_HOST: 'db'
72
+ DATABASE_PORT: 5432
72
73
  DATABASE_USER: 'postgres'
73
74
  DATABASE_PASSWORD: 'postgres'
74
75
  DATABASE_NAME: 'ruby_pitaya'
76
+ HTTP_AUTH_ENABLED: 'false'
77
+ HTTP_AUTH_USER: 'user'
78
+ HTTP_AUTH_PASS: 'pass'
75
79
 
76
80
  rubypitaya-console:
77
81
  <<: *rubypitaya
@@ -1,19 +1,23 @@
1
- FROM ruby:2.7.2
1
+ FROM ruby:2.7.2-slim
2
2
 
3
3
  ENV LANG=C.UTF-8
4
4
  ENV LC_ALL=C.UTF-8
5
5
 
6
6
  RUN apt update && \
7
7
  apt install -y --no-install-recommends \
8
- docker.io \
9
- postgresql-client \
8
+ netcat \
9
+ libpq-dev \
10
+ build-essential \
10
11
  && rm -rf /var/lib/apt/lists/*
11
12
 
12
- COPY Gemfile Gemfile.lock ./
13
+ WORKDIR /app/rubypitaya/
13
14
 
14
- RUN bundle install
15
+ COPY Gemfile Gemfile.lock ./
15
16
 
16
- WORKDIR /app/rubypitaya/
17
+ RUN bundle config --global jobs 4 && \
18
+ bundle config --global set clean 'true' \
19
+ bundle config --global git.allow_insecure true && \
20
+ bundle install
17
21
 
18
22
  COPY . .
19
23
 
@@ -3,10 +3,8 @@
3
3
  cmd="$@"
4
4
 
5
5
  echo "=> Waiting for postgres"
6
- until PGPASSWORD=$DATABASE_PASSWORD psql -h "$DATABASE_HOST" -U "$DATABASE_USER" -c '\q' > /dev/null 2>&1; do
7
- echo "=> Waiting for Postgres..."
8
- sleep 1
9
- done
6
+
7
+ ./docker/wait_for.sh $DATABASE_HOST:$DATABASE_PORT
10
8
 
11
9
  echo "=> Postgres is ready"
12
10
 
@@ -1,16 +1,21 @@
1
- FROM ruby:2.7.2 as builder
1
+ FROM ruby:2.7.2-slim as builder
2
2
 
3
3
  RUN apt update && \
4
4
  apt install -y --no-install-recommends \
5
5
  curl \
6
+ libpq-dev \
7
+ build-essential \
6
8
  && rm -rf /var/lib/apt/lists/*
7
9
 
8
10
  COPY Gemfile Gemfile.lock ./
9
11
 
10
- RUN bundle config --local without "development test" && \
12
+ RUN bundle config --global jobs 4 && \
13
+ bundle config --global set clean 'true' \
14
+ bundle config --global git.allow_insecure true && \
15
+ bundle config --global without "development test" && \
11
16
  bundle install
12
17
 
13
- 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
18
+ # 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
14
19
 
15
20
  FROM ruby:2.7.2-slim
16
21
 
@@ -19,13 +24,17 @@ ENV LC_ALL=C.UTF-8
19
24
 
20
25
  RUN apt update && \
21
26
  apt install -y --no-install-recommends \
22
- postgresql-client \
27
+ netcat \
28
+ libpq5 \
23
29
  && rm -rf /var/lib/apt/lists/*
24
30
 
25
31
  COPY --from=builder /usr/local/bundle /usr/local/bundle
26
- COPY --from=builder /kubectl /usr/local/bin/kubectl
27
-
28
- RUN chmod +x /usr/local/bin/kubectl
32
+ RUN rm -rf /usr/local/bundle/cache
33
+ RUN rm -rf /usr/local/bundle/build_info
34
+ RUN rm -rf /usr/local/bundle/doc
35
+
36
+ # COPY --from=builder /kubectl /usr/local/bin/kubectl
37
+ # RUN chmod +x /usr/local/bin/kubectl
29
38
 
30
39
  WORKDIR /app/rubypitaya/
31
40
 
@@ -0,0 +1,184 @@
1
+ #!/bin/sh
2
+
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (c) 2017 Eficode Oy
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
26
+ TIMEOUT=15
27
+ QUIET=0
28
+ # The protocol to make the request with, either "tcp" or "http"
29
+ PROTOCOL="tcp"
30
+
31
+ echoerr() {
32
+ if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
33
+ }
34
+
35
+ usage() {
36
+ exitcode="$1"
37
+ cat << USAGE >&2
38
+ Usage:
39
+ $cmdname host:port|url [-t timeout] [-- command args]
40
+ -q | --quiet Do not output any status messages
41
+ -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
42
+ -- COMMAND ARGS Execute command with args after the test finishes
43
+ USAGE
44
+ exit "$exitcode"
45
+ }
46
+
47
+ wait_for() {
48
+ case "$PROTOCOL" in
49
+ tcp)
50
+ if ! command -v nc >/dev/null; then
51
+ echoerr 'nc command is missing!'
52
+ exit 1
53
+ fi
54
+ ;;
55
+ wget)
56
+ if ! command -v wget >/dev/null; then
57
+ echoerr 'nc command is missing!'
58
+ exit 1
59
+ fi
60
+ ;;
61
+ esac
62
+
63
+ while :; do
64
+ case "$PROTOCOL" in
65
+ tcp)
66
+ nc -z "$HOST" "$PORT" > /dev/null 2>&1
67
+ ;;
68
+ http)
69
+ wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
70
+ ;;
71
+ *)
72
+ echoerr "Unknown protocol '$PROTOCOL'"
73
+ exit 1
74
+ ;;
75
+ esac
76
+
77
+ result=$?
78
+
79
+ if [ $result -eq 0 ] ; then
80
+ if [ $# -gt 7 ] ; then
81
+ for result in $(seq $(($# - 7))); do
82
+ result=$1
83
+ shift
84
+ set -- "$@" "$result"
85
+ done
86
+
87
+ TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
88
+ shift 7
89
+ exec "$@"
90
+ fi
91
+ exit 0
92
+ fi
93
+
94
+ if [ "$TIMEOUT" -le 0 ]; then
95
+ break
96
+ fi
97
+ TIMEOUT=$((TIMEOUT - 1))
98
+
99
+ sleep 1
100
+ done
101
+ echo "Operation timed out" >&2
102
+ exit 1
103
+ }
104
+
105
+ while :; do
106
+ case "$1" in
107
+ http://*|https://*)
108
+ HOST="$1"
109
+ PROTOCOL="http"
110
+ shift 1
111
+ ;;
112
+ *:* )
113
+ HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
114
+ PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
115
+ shift 1
116
+ ;;
117
+ -q | --quiet)
118
+ QUIET=1
119
+ shift 1
120
+ ;;
121
+ -q-*)
122
+ QUIET=0
123
+ echoerr "Unknown option: $1"
124
+ usage 1
125
+ ;;
126
+ -q*)
127
+ QUIET=1
128
+ result=$1
129
+ shift 1
130
+ set -- -"${result#-q}" "$@"
131
+ ;;
132
+ -t | --timeout)
133
+ TIMEOUT="$2"
134
+ shift 2
135
+ ;;
136
+ -t*)
137
+ TIMEOUT="${1#-t}"
138
+ shift 1
139
+ ;;
140
+ --timeout=*)
141
+ TIMEOUT="${1#*=}"
142
+ shift 1
143
+ ;;
144
+ --)
145
+ shift
146
+ break
147
+ ;;
148
+ --help)
149
+ usage 0
150
+ ;;
151
+ -*)
152
+ QUIET=0
153
+ echoerr "Unknown option: $1"
154
+ usage 1
155
+ ;;
156
+ *)
157
+ QUIET=0
158
+ echoerr "Unknown argument: $1"
159
+ usage 1
160
+ ;;
161
+ esac
162
+ done
163
+
164
+ if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
165
+ echoerr "Error: invalid timeout '$TIMEOUT'"
166
+ usage 3
167
+ fi
168
+
169
+ case "$PROTOCOL" in
170
+ tcp)
171
+ if [ "$HOST" = "" -o "$PORT" = "" ]; then
172
+ echoerr "Error: you need to provide a host and port to test."
173
+ usage 2
174
+ fi
175
+ ;;
176
+ http)
177
+ if [ "$HOST" = "" ]; then
178
+ echoerr "Error: you need to provide a host to test."
179
+ usage 2
180
+ fi
181
+ ;;
182
+ esac
183
+
184
+ wait_for "$@"
@@ -0,0 +1,4 @@
1
+ apiVersion: v1
2
+ description: [Game Name]
3
+ name: [game-name]
4
+ version: 0.0.1
@@ -0,0 +1,9 @@
1
+ apiVersion: v1
2
+ kind: ConfigMap
3
+ metadata:
4
+ name: nginx-config
5
+ data:
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
9
+ \ }\n}\n"
@@ -0,0 +1,38 @@
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: connector
5
+ labels:
6
+ app: {{ .Values.app }}
7
+ component: connector
8
+ spec:
9
+ replicas: 1
10
+ selector:
11
+ matchLabels:
12
+ app: {{ .Values.app }}
13
+ component: connector
14
+ template:
15
+ metadata:
16
+ labels:
17
+ app: {{ .Values.app }}
18
+ component: connector
19
+ spec:
20
+ containers:
21
+ - name: connector
22
+ image: {{ .Values.connector.image.repository }}:{{ .Values.connector.image.tag }}
23
+ ports:
24
+ - containerPort: 3250
25
+ name: connector
26
+ env:
27
+ - name: PITAYA_CLUSTER_RPC_SERVER_NATS_CONNECT
28
+ value: "nats://nats.{{ .Values.namespace }}.svc.cluster.local:4222"
29
+ - name: PITAYA_CLUSTER_RPC_CLIENT_NATS_CONNECT
30
+ value: "nats://nats.{{ .Values.namespace }}.svc.cluster.local:4222"
31
+ - name: PITAYA_CLUSTER_RPC_CLIENT_NATS_REQUESTTIMEOUT
32
+ value: "10s"
33
+ - name: PITAYA_CLUSTER_SD_ETCD_ENDPOINTS
34
+ value: "etcd.{{ .Values.namespace }}.svc.cluster.local:2379"
35
+ - name: PITAYA_CLUSTER_SD_ETCD_PREFIX
36
+ value: "rubypitaya/"
37
+ - name: SERVER_ROUTES
38
+ value: "rubypitaya"
@@ -0,0 +1,40 @@
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: gameserver-nginx
5
+ labels:
6
+ app: gameserver
7
+ component: gameserver-nginx
8
+ spec:
9
+ replicas: 10
10
+ selector:
11
+ matchLabels:
12
+ app: gameserver
13
+ component: gameserver-nginx
14
+ template:
15
+ metadata:
16
+ labels:
17
+ app: gameserver
18
+ component: gameserver-nginx
19
+ spec:
20
+ containers:
21
+ - name: gameserver-nginx
22
+ image: nginx:1.18.0
23
+ ports:
24
+ {{- $initialValue := int .Values.gameserver.port.first }}
25
+ {{- $finalValue := add .Values.gameserver.port.last 1 }}
26
+ {{- $finalValue = int $finalValue }}
27
+ {{- range untilStep $initialValue $finalValue 1 }}
28
+ {{- $port := . }}
29
+ - name: port-{{ $port }}
30
+ containerPort: {{ $port }}
31
+ protocol: TCP
32
+ {{- end }}
33
+ volumeMounts:
34
+ - name: nginx-config
35
+ mountPath: /etc/nginx/nginx.conf
36
+ subPath: nginx.conf
37
+ volumes:
38
+ - name: nginx-config
39
+ configMap:
40
+ name: nginx-config
@@ -0,0 +1,71 @@
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: rubypitaya
5
+ labels:
6
+ app: {{ .Values.app }}
7
+ component: rubypitaya
8
+ spec:
9
+ replicas: 1
10
+ selector:
11
+ matchLabels:
12
+ app: {{ .Values.app }}
13
+ component: rubypitaya
14
+ template:
15
+ metadata:
16
+ labels:
17
+ app: {{ .Values.app }}
18
+ component: rubypitaya
19
+ spec:
20
+ containers:
21
+ - name: rubypitaya
22
+ image: {{ .Values.rubypitaya.image.repository }}:{{ .Values.rubypitaya.image.tag }}
23
+ command: ["bundle", "exec", "rubypitaya", "run"]
24
+ ports:
25
+ - containerPort: 4567
26
+ name: rubypitaya
27
+ env:
28
+ - name: SERVER_NAME
29
+ value: "rubypitaya"
30
+ - name: RUBYPITAYA_ENV
31
+ value: "production"
32
+ - name: NATS_URL
33
+ value: "nats://nats.{{ .Values.namespace }}.svc.cluster.local:4222"
34
+ - name: ETCD_URL
35
+ value: "http://etcd.{{ .Values.namespace }}.svc.cluster.local:2379"
36
+ - name: ETCD_PREFIX
37
+ value: "rubypitaya/"
38
+ - name: ETCD_LEASE_SECONDS
39
+ value: "60"
40
+ - name: REDIS_URL
41
+ value: "redis://redis.{{ .Values.namespace }}.svc.cluster.local:6379"
42
+ - name: DATABASE_NAME
43
+ value: {{ .Values.database.name | quote }}
44
+ - name: DATABASE_HOST
45
+ value: {{ .Values.database.host | quote }}
46
+ - name: DATABASE_USER
47
+ value: {{ .Values.database.user | quote }}
48
+ - name: DATABASE_PASSWORD
49
+ value: {{ .Values.database.password | quote }}
50
+ - name: HTTP_AUTH_ENABLED
51
+ value: {{ .Values.http.enabled | quote }}
52
+ - name: HTTP_AUTH_USER
53
+ value: {{ .Values.http.user | quote }}
54
+ - name: HTTP_AUTH_PASS
55
+ value: {{ .Values.http.password | quote }}
56
+ - name: MATCHMAKING_CURRENTROOMBLL
57
+ value: kubernetes
58
+ - name: MATCHMAKING_ROOMBLL_KUBERNETES_NAMESPACE
59
+ value: {{ .Values.namespace }}
60
+ - name: MATCHMAKING_ROOMBLL_KUBERNETES_CONTAINERIMAGE
61
+ value: {{ .Values.gameserver.image.repository }}:{{ .Values.gameserver.image.tag }}
62
+ - name: MATCHMAKING_ROOMBLL_KUBERNETES_INITIALPORT
63
+ value: {{ .Values.gameserver.port.first | quote }}
64
+ - name: MATCHMAKING_ROOMBLL_KUBERNETES_FINALPORT
65
+ value: {{ .Values.gameserver.port.last | quote }}
66
+ - name: MATCHMAKING_ROOMBLL_KUBERNETES_SERVICEHOST
67
+ value: {{ .Values.gameserver.servicehost }}
68
+ imagePullSecrets:
69
+ - name: gitlab-registry
70
+ serviceAccount: rubypitaya
71
+ serviceAccountName: rubypitaya
@@ -0,0 +1,12 @@
1
+ apiVersion: rbac.authorization.k8s.io/v1
2
+ kind: RoleBinding
3
+ metadata:
4
+ name: rubypitaya
5
+ roleRef:
6
+ apiGroup: rbac.authorization.k8s.io
7
+ kind: Role
8
+ name: rubypitaya
9
+ subjects:
10
+ - kind: ServiceAccount
11
+ name: rubypitaya
12
+ namespace: {{ .Values.namespace }}
@@ -0,0 +1,31 @@
1
+ apiVersion: rbac.authorization.k8s.io/v1
2
+ kind: Role
3
+ metadata:
4
+ name: rubypitaya
5
+ rules:
6
+ - apiGroups:
7
+ - ""
8
+ resources:
9
+ - services
10
+ - pods
11
+ verbs:
12
+ - get
13
+ - list
14
+ - watch
15
+ - create
16
+ - update
17
+ - patch
18
+ - delete
19
+ - apiGroups:
20
+ - apps
21
+ - extensions
22
+ resources:
23
+ - deployments
24
+ verbs:
25
+ - get
26
+ - list
27
+ - watch
28
+ - create
29
+ - update
30
+ - patch
31
+ - delete
@@ -0,0 +1,4 @@
1
+ apiVersion: v1
2
+ kind: ServiceAccount
3
+ metadata:
4
+ name: rubypitaya
@@ -0,0 +1,13 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: connector
5
+ spec:
6
+ selector:
7
+ app: {{ .Values.app }}
8
+ component: connector
9
+ ports:
10
+ - protocol: TCP
11
+ port: 3250
12
+ targetPort: 3250
13
+ type: LoadBalancer
@@ -0,0 +1,18 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: etcd
5
+ spec:
6
+ selector:
7
+ app: {{ .Values.app }}
8
+ component: etcd
9
+ ports:
10
+ - protocol: TCP
11
+ port: 2379
12
+ targetPort: 2379
13
+ name: etcd-2379
14
+ - protocol: TCP
15
+ port: 2380
16
+ targetPort: 2380
17
+ name: etcd-2380
18
+ type: ClusterIP
@@ -0,0 +1,20 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: gameserver-nginx
5
+ spec:
6
+ selector:
7
+ app: gameserver
8
+ component: gameserver-nginx
9
+ ports:
10
+ {{- $initialValue := int .Values.gameserver.port.first }}
11
+ {{- $finalValue := add .Values.gameserver.port.last 1 }}
12
+ {{- $finalValue = int $finalValue }}
13
+ {{- range untilStep $initialValue $finalValue 1 }}
14
+ {{- $port := . }}
15
+ - name: port-{{ $port }}
16
+ port: {{ $port }}
17
+ targetPort: {{ $port }}
18
+ protocol: TCP
19
+ {{- end }}
20
+ type: LoadBalancer
@@ -0,0 +1,20 @@
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
+ apiVersion: v1
7
+ kind: Service
8
+ metadata:
9
+ name: gameserver-{{ $port }}
10
+ spec:
11
+ selector:
12
+ app: gameserver
13
+ component: gameserver-{{ $port }}
14
+ ports:
15
+ - protocol: TCP
16
+ port: {{ $port }}
17
+ targetPort: {{ $port }}
18
+ type: ClusterIP
19
+ ---
20
+ {{- end }}
@@ -0,0 +1,13 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: nats
5
+ spec:
6
+ selector:
7
+ app: {{ .Values.app }}
8
+ component: nats
9
+ ports:
10
+ - protocol: TCP
11
+ port: 4222
12
+ targetPort: 4222
13
+ type: ClusterIP
@@ -0,0 +1,14 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: redis
5
+ spec:
6
+ selector:
7
+ app: {{ .Values.app }}
8
+ component: redis
9
+ ports:
10
+ - protocol: TCP
11
+ port: 6379
12
+ targetPort: 6379
13
+ name: redis
14
+ type: ClusterIP
@@ -0,0 +1,13 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: rubypitaya
5
+ spec:
6
+ selector:
7
+ app: {{ .Values.app }}
8
+ component: rubypitaya
9
+ ports:
10
+ - protocol: TCP
11
+ port: 80
12
+ targetPort: 4567
13
+ type: LoadBalancer
@@ -0,0 +1,28 @@
1
+ apiVersion: apps/v1
2
+ kind: StatefulSet
3
+ metadata:
4
+ name: etcd
5
+ labels:
6
+ app: {{ .Values.app }}
7
+ component: etcd
8
+ spec:
9
+ serviceName: "etcd"
10
+ replicas: 1
11
+ selector:
12
+ matchLabels:
13
+ app: {{ .Values.app }}
14
+ component: etcd
15
+ template:
16
+ metadata:
17
+ labels:
18
+ app: {{ .Values.app }}
19
+ component: etcd
20
+ spec:
21
+ containers:
22
+ - name: etcd
23
+ image: appcelerator/etcd:3.0.15
24
+ ports:
25
+ - containerPort: 2379
26
+ name: etcd-2379
27
+ - containerPort: 2380
28
+ name: etcd-2380
@@ -0,0 +1,26 @@
1
+ apiVersion: apps/v1
2
+ kind: StatefulSet
3
+ metadata:
4
+ name: nats
5
+ labels:
6
+ app: {{ .Values.app }}
7
+ component: nats
8
+ spec:
9
+ serviceName: "nats"
10
+ replicas: 1
11
+ selector:
12
+ matchLabels:
13
+ app: {{ .Values.app }}
14
+ component: nats
15
+ template:
16
+ metadata:
17
+ labels:
18
+ app: {{ .Values.app }}
19
+ component: nats
20
+ spec:
21
+ containers:
22
+ - name: nats
23
+ image: nats:2.1.4
24
+ ports:
25
+ - containerPort: 4222
26
+ name: nats
@@ -0,0 +1,26 @@
1
+ apiVersion: apps/v1
2
+ kind: StatefulSet
3
+ metadata:
4
+ name: redis
5
+ labels:
6
+ app: {{ .Values.app }}
7
+ component: redis
8
+ spec:
9
+ serviceName: "redis"
10
+ replicas: 1
11
+ selector:
12
+ matchLabels:
13
+ app: {{ .Values.app }}
14
+ component: redis
15
+ template:
16
+ metadata:
17
+ labels:
18
+ app: {{ .Values.app }}
19
+ component: redis
20
+ spec:
21
+ containers:
22
+ - name: redis
23
+ image: redis:6.0.5-alpine
24
+ ports:
25
+ - containerPort: 6379
26
+ name: redis
@@ -0,0 +1,32 @@
1
+ app: [app-name]
2
+ namespace: [kubernetes-namespace]
3
+
4
+ connector:
5
+ image:
6
+ repository: registry.gitlab.com/lucianopc/pitaya-connector
7
+ tag: 0.2.0
8
+
9
+ rubypitaya:
10
+ image:
11
+ repository: [metagame-repository-link]
12
+ tag: latest
13
+
14
+ database:
15
+ name: [database-name]
16
+ host: [database-host]
17
+ user: [database-user]
18
+ password: [database-password]
19
+
20
+ http:
21
+ enabled: false
22
+ user: user
23
+ password: pass
24
+
25
+ gameserver:
26
+ image:
27
+ repository: [gameserver-repository-link]
28
+ tag: latest
29
+ port:
30
+ first: 5000
31
+ last: 5099
32
+ servicehost: [gameserver-service-url]
@@ -10,6 +10,7 @@ module RubyPitaya
10
10
  @has_config_core_override = false
11
11
 
12
12
  @result_cache = {}
13
+ @temp = {result: {}}
13
14
  end
14
15
 
15
16
  def [](key)
@@ -22,7 +23,10 @@ module RubyPitaya
22
23
  result = @config_core[key]
23
24
  end
24
25
 
25
- @result_cache[key] = result.deep_symbolize_keys
26
+ @temp[:result] = result
27
+ @temp.deep_symbolize_keys!
28
+
29
+ @result_cache[key] = @temp[:result]
26
30
 
27
31
  result
28
32
  end
@@ -17,6 +17,17 @@ module RubyPitaya
17
17
  @postman = nil
18
18
  end
19
19
 
20
+ def set_attributes(bll, log, redis, setup, config, params, session, postman)
21
+ @bll = bll
22
+ @log = log
23
+ @redis = redis
24
+ @setup = setup
25
+ @config = config
26
+ @params = params
27
+ @session = session
28
+ @postman = postman
29
+ end
30
+
20
31
  def self.non_authenticated_actions(*action_names)
21
32
  self.non_authenticated_routes = action_names.map(&:to_s)
22
33
  end
@@ -62,8 +62,7 @@ module RubyPitaya
62
62
  msg: "Handler #{handler_name} not founded"
63
63
  }
64
64
  end
65
-
66
- unless @handler_name_map[handler_name].methods.include?(action_name.to_sym)
65
+ unless @handler_name_map[handler_name].public_methods(false).include?(action_name.to_sym)
67
66
  return {
68
67
  code: StatusCodes::CODE_ACTION_NOT_FOUND,
69
68
  msg: "Handler #{handler_name} action #{action_name} not founded"
@@ -72,19 +71,12 @@ module RubyPitaya
72
71
 
73
72
  handler = @handler_name_map[handler_name]
74
73
 
75
- handler.bll = bll
76
- handler.log = log
77
- handler.redis = redis
78
- handler.setup = setup
79
- handler.config = config
80
- handler.params = params
81
- handler.session = session
82
- handler.postman = postman
83
-
84
74
  if !handler.class.authenticated_action_name?(action_name)
75
+ handler.set_attributes(bll, log, redis, setup, config, params, session, postman)
85
76
  handler.send(action_name)
86
77
  else
87
78
  if session.authenticated?
79
+ handler.set_attributes(bll, log, redis, setup, config, params, session, postman)
88
80
  handler.send(action_name)
89
81
  else
90
82
  return {
@@ -19,10 +19,14 @@ module RubyPitaya
19
19
  before do
20
20
  content_type :json
21
21
 
22
+ return error_unauthorized unless authorized?(request)
23
+
22
24
  @bll = settings.bll
23
25
  @setup = settings.setup
24
26
  @config = settings.config
25
27
 
28
+ @config.clear_cache
29
+
26
30
  if request.content_type == 'application/json'
27
31
  request_body = request.body.read
28
32
  @params.merge!(JSON.parse(request_body)) if !request_body.blank?
@@ -30,5 +34,31 @@ module RubyPitaya
30
34
 
31
35
  @params = Parameters.new(@params)
32
36
  end
37
+
38
+ private
39
+
40
+ def error_unauthorized
41
+ return halt(401, 'Unauthorized')
42
+ end
43
+
44
+ def authorized?(request)
45
+ return true unless http_auth_enabled?
46
+
47
+ auth_token = request.env['HTTP_AUTHORIZATION']
48
+ return auth_token == get_http_auth
49
+ end
50
+
51
+ def http_auth_enabled?
52
+ return ENV.fetch("HTTP_AUTH_ENABLED") { 'false' } == 'true'
53
+ end
54
+
55
+ def get_http_auth
56
+ user = ENV.fetch("HTTP_AUTH_USER") { '' }
57
+ pass = ENV.fetch("HTTP_AUTH_PASS") { '' }
58
+
59
+ auth_token = ::Base64.strict_encode64("#{user}:#{pass}")
60
+
61
+ return "Basic #{auth_token}"
62
+ end
33
63
  end
34
64
  end
@@ -152,15 +152,16 @@ module RubyPitaya
152
152
  session_id = request[:session][:id]
153
153
  session_uid = request[:session].fetch(:uid, '')
154
154
  session_data = request[:session][:data]
155
- session_data = JSON.parse(session_data) if session_data.class == String
155
+ session_data = JSON.parse(session_data, symbolize_names: true) if session_data.class == String
156
156
  frontend_id = request[:frontendID]
157
157
  metadata = request[:metadata]
158
- metadata = JSON.parse(metadata) if metadata.class == String
158
+ metadata = JSON.parse(metadata, symbolize_names: true) if metadata.class == String
159
159
 
160
160
  @session.update(session_id, session_uid, session_data, metadata,
161
161
  frontend_id)
162
162
 
163
- handler_name, action_name = message_route.split('.')[1..-1]
163
+ # TODO: Validate if handler and action names are not nil
164
+ handler_name, action_name = message_route.scan(/\A\w+\.(\w+)\.(\w+)\z/)[0]
164
165
 
165
166
  @log.info "request -> route: #{message_route}"
166
167
  @log.info " -> data: #{message_data}"
@@ -15,7 +15,7 @@ module RubyPitaya
15
15
  end
16
16
 
17
17
  def config_mock=(value)
18
- @config_mock = value
18
+ @config_mock = value.deep_symbolize_keys.stringify_keys
19
19
  end
20
20
 
21
21
  def config_core_override=(value)
@@ -24,7 +24,7 @@ module RubyPitaya
24
24
  def add(key, value)
25
25
  keys = key.split('.')
26
26
  add_hash = undig(*keys, value)
27
- @config_mock = merge_recursively(@config_mock, add_hash)
27
+ @config_mock = merge_recursively(@config_mock, add_hash).deep_symbolize_keys.stringify_keys
28
28
  end
29
29
 
30
30
  private
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.18.0'
2
+ VERSION = '2.19.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.18.0
4
+ version: 2.19.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: 2021-03-07 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 6.1.3
153
- - !ruby/object:Gem::Dependency
154
- name: eventmachine
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - '='
158
- - !ruby/object:Gem::Version
159
- version: 1.2.7
160
- type: :runtime
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - '='
165
- - !ruby/object:Gem::Version
166
- version: 1.2.7
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: pry
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -269,11 +255,31 @@ files:
269
255
  - "./lib/rubypitaya/app-template/docker/dev/Dockerfile"
270
256
  - "./lib/rubypitaya/app-template/docker/entrypoint.sh"
271
257
  - "./lib/rubypitaya/app-template/docker/prod/Dockerfile"
258
+ - "./lib/rubypitaya/app-template/docker/wait_for.sh"
272
259
  - "./lib/rubypitaya/app-template/features/hello_world.feature"
273
260
  - "./lib/rubypitaya/app-template/features/player.feature"
274
261
  - "./lib/rubypitaya/app-template/features/step_definitions/application_steps.rb"
275
262
  - "./lib/rubypitaya/app-template/features/step_definitions/rubypitaya_steps.rb"
276
263
  - "./lib/rubypitaya/app-template/features/support/env.rb"
264
+ - "./lib/rubypitaya/app-template/helm/Chart.yaml"
265
+ - "./lib/rubypitaya/app-template/helm/templates/config-maps/nginx-config.yaml"
266
+ - "./lib/rubypitaya/app-template/helm/templates/deployments/connector.yaml"
267
+ - "./lib/rubypitaya/app-template/helm/templates/deployments/gameserver-nginx.yaml"
268
+ - "./lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml"
269
+ - "./lib/rubypitaya/app-template/helm/templates/role-bindings/rubypitaya.yaml"
270
+ - "./lib/rubypitaya/app-template/helm/templates/roles/rubypitaya.yaml"
271
+ - "./lib/rubypitaya/app-template/helm/templates/service-accounts/rubypitaya.yaml"
272
+ - "./lib/rubypitaya/app-template/helm/templates/services/connector.yaml"
273
+ - "./lib/rubypitaya/app-template/helm/templates/services/etcd.yaml"
274
+ - "./lib/rubypitaya/app-template/helm/templates/services/gameserver-nginx.yaml"
275
+ - "./lib/rubypitaya/app-template/helm/templates/services/gameserver.yaml"
276
+ - "./lib/rubypitaya/app-template/helm/templates/services/nats.yaml"
277
+ - "./lib/rubypitaya/app-template/helm/templates/services/redis.yaml"
278
+ - "./lib/rubypitaya/app-template/helm/templates/services/rubypitaya.yaml"
279
+ - "./lib/rubypitaya/app-template/helm/templates/statefulsets/etcd.yaml"
280
+ - "./lib/rubypitaya/app-template/helm/templates/statefulsets/nats.yaml"
281
+ - "./lib/rubypitaya/app-template/helm/templates/statefulsets/redis.yaml"
282
+ - "./lib/rubypitaya/app-template/helm/values.yaml"
277
283
  - "./lib/rubypitaya/app-template/kubernetes/README.md"
278
284
  - "./lib/rubypitaya/app-template/kubernetes/deployment-connector.yaml"
279
285
  - "./lib/rubypitaya/app-template/kubernetes/deployment-rubypitaya.yaml"