rubypitaya 2.16.0 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubypitaya/app-template/Gemfile +1 -1
  3. data/lib/rubypitaya/app-template/Gemfile.lock +17 -24
  4. data/lib/rubypitaya/app-template/Makefile +1 -1
  5. data/lib/rubypitaya/app-template/app/bll/player_bll.rb +2 -2
  6. data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +1 -1
  7. data/lib/rubypitaya/app-template/docker-compose.yml +4 -0
  8. data/lib/rubypitaya/app-template/docker/dev/Dockerfile +15 -7
  9. data/lib/rubypitaya/app-template/docker/entrypoint.sh +2 -4
  10. data/lib/rubypitaya/app-template/docker/prod/Dockerfile +26 -18
  11. data/lib/rubypitaya/app-template/docker/wait_for.sh +184 -0
  12. data/lib/rubypitaya/app-template/helm/Chart.yaml +4 -0
  13. data/lib/rubypitaya/app-template/helm/templates/config-maps/nginx-config.yaml +9 -0
  14. data/lib/rubypitaya/app-template/helm/templates/deployments/connector.yaml +38 -0
  15. data/lib/rubypitaya/app-template/helm/templates/deployments/gameserver-nginx.yaml +40 -0
  16. data/lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml +71 -0
  17. data/lib/rubypitaya/app-template/helm/templates/role-bindings/rubypitaya.yaml +12 -0
  18. data/lib/rubypitaya/app-template/helm/templates/roles/rubypitaya.yaml +31 -0
  19. data/lib/rubypitaya/app-template/helm/templates/service-accounts/rubypitaya.yaml +4 -0
  20. data/lib/rubypitaya/app-template/helm/templates/services/connector.yaml +13 -0
  21. data/lib/rubypitaya/app-template/helm/templates/services/etcd.yaml +18 -0
  22. data/lib/rubypitaya/app-template/helm/templates/services/gameserver-nginx.yaml +20 -0
  23. data/lib/rubypitaya/app-template/helm/templates/services/gameserver.yaml +20 -0
  24. data/lib/rubypitaya/app-template/helm/templates/services/nats.yaml +13 -0
  25. data/lib/rubypitaya/app-template/helm/templates/services/redis.yaml +14 -0
  26. data/lib/rubypitaya/app-template/helm/templates/services/rubypitaya.yaml +13 -0
  27. data/lib/rubypitaya/app-template/helm/templates/statefulsets/etcd.yaml +28 -0
  28. data/lib/rubypitaya/app-template/helm/templates/statefulsets/nats.yaml +26 -0
  29. data/lib/rubypitaya/app-template/helm/templates/statefulsets/redis.yaml +26 -0
  30. data/lib/rubypitaya/app-template/helm/values.yaml +32 -0
  31. data/lib/rubypitaya/core/config.rb +12 -4
  32. data/lib/rubypitaya/core/config_core.rb +4 -21
  33. data/lib/rubypitaya/core/handler_base.rb +11 -0
  34. data/lib/rubypitaya/core/handler_router.rb +3 -11
  35. data/lib/rubypitaya/core/http_routes.rb +30 -0
  36. data/lib/rubypitaya/core/main.rb +8 -7
  37. data/lib/rubypitaya/core/parameters.rb +449 -138
  38. data/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb +2 -2
  39. data/lib/rubypitaya/version.rb +1 -1
  40. metadata +22 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4512ea6e0a637413e97896041d88fced36d78df993f3cce20dec3f666948588
4
- data.tar.gz: f670294a5072062f87f575ae499c53e196437a6b8fae5025b2b6adfbceba59b1
3
+ metadata.gz: a6dfc8681449f1ffcae12145b9fb3533f04d82aa42ed663ddac513d16eb57c79
4
+ data.tar.gz: 3176f5f30664abbd2f9464eedec8c7f004412d6d4c5391528f17ae35932cecb7
5
5
  SHA512:
6
- metadata.gz: 2caa669656cc57910c9cd09d992c802863a86c14ecfc3490a7b0944dd45bfb75b006eadf67bc407eef08fde8166c655d9252ff1743aca4587120efe0eb247ff6
7
- data.tar.gz: 148854a900d3aeeed771b31de1e8edbf294a70880836ad6fa18e8d7282a04ac1074f0c9e1962ff97958195aaf2895679ebbbff2dfd32f46c35496e0fe25e6d5d
6
+ metadata.gz: c2c31cbe23ea840ba2fb5c0dd59c29a3bdf204bd017d06aa772a3213bf0ce7b99536bafaa60494edb2e462176f3b001125a2c707ee7e387ad5d3cd0fc6aa64bc
7
+ data.tar.gz: 59cf7321c84bd05e5727a38236cbec7e6ee4d32f9b02c3ef7349a65e09a327885294de37eeb04e6f2740dbbf5d4c14d9cc93aeb593c2c4ae5cbbe53f0c4bde9a
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.16.0'
3
+ gem 'rubypitaya', '2.20.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.14.0'
@@ -1,21 +1,3 @@
1
- GIT
2
- remote: https://gitlab.com/LucianoPC/ruby-pitaya
3
- revision: 9c28f2a16f3140d24f019164a254155f524f2593
4
- branch: ruby2.7.2
5
- specs:
6
- rubypitaya (2.16.0)
7
- activerecord (= 6.1.3)
8
- etcdv3 (= 0.10.2)
9
- eventmachine (= 1.2.7)
10
- nats (= 0.11.0)
11
- ostruct (= 0.3.3)
12
- pg (= 1.2.3)
13
- protobuf (= 3.10.0)
14
- rake (= 13.0.3)
15
- redis (= 4.2.5)
16
- sinatra (= 2.1.0)
17
- sinatra-contrib (= 2.1.0)
18
-
19
1
  GEM
20
2
  remote: https://rubygems.org/
21
3
  specs:
@@ -68,14 +50,14 @@ GEM
68
50
  etcdv3 (0.10.2)
69
51
  grpc (~> 1.17)
70
52
  eventmachine (1.2.7)
71
- ffi (1.14.2)
72
- google-protobuf (3.15.3)
53
+ ffi (1.15.0)
54
+ google-protobuf (3.15.8)
73
55
  googleapis-common-protos-types (1.0.6)
74
56
  google-protobuf (~> 3.14)
75
- grpc (1.36.0)
76
- google-protobuf (~> 3.14)
57
+ grpc (1.37.0)
58
+ google-protobuf (~> 3.15)
77
59
  googleapis-common-protos-types (~> 1.0)
78
- i18n (1.8.9)
60
+ i18n (1.8.10)
79
61
  concurrent-ruby (~> 1.0)
80
62
  listen (3.4.1)
81
63
  rb-fsevent (~> 0.10, >= 0.10.3)
@@ -126,6 +108,17 @@ GEM
126
108
  rspec-support (~> 3.10.0)
127
109
  rspec-support (3.10.2)
128
110
  ruby2_keywords (0.0.4)
111
+ rubypitaya (2.20.0)
112
+ activerecord (= 6.1.3)
113
+ etcdv3 (= 0.10.2)
114
+ nats (= 0.11.0)
115
+ ostruct (= 0.3.3)
116
+ pg (= 1.2.3)
117
+ protobuf (= 3.10.0)
118
+ rake (= 13.0.3)
119
+ redis (= 4.2.5)
120
+ sinatra (= 2.1.0)
121
+ sinatra-contrib (= 2.1.0)
129
122
  sinatra (2.1.0)
130
123
  mustermann (~> 1.0)
131
124
  rack (~> 2.2)
@@ -155,7 +148,7 @@ DEPENDENCIES
155
148
  listen (= 3.4.1)
156
149
  pry (= 0.14.0)
157
150
  rspec (= 3.10.0)
158
- rubypitaya!
151
+ rubypitaya (= 2.19.1)
159
152
 
160
153
  BUNDLED WITH
161
154
  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
 
@@ -1,11 +1,11 @@
1
1
  class PlayerBLL
2
2
 
3
3
  def create_new_player(setup, config)
4
- name = config['initial_player']['name']
4
+ name = config['initial_player'][:name]
5
5
  gold = setup['initial_player.wallet.gold']
6
6
 
7
7
  player = Player.new(name: name, gold: gold, user: User.new)
8
- player.save
8
+ player.save!
9
9
  player
10
10
  end
11
11
  end
@@ -17,7 +17,7 @@ class PlayerHandler < RubyPitaya::HandlerBase
17
17
  # Given you have the following file "app/config/initial_player.json"
18
18
  # And this json content is {'name': 'Guest'}
19
19
  # And you can get the initial player name
20
- # Then you can run the following code: @config['initial_player']['name']
20
+ # Then you can run the following code: @config['initial_player'][:name]
21
21
  #
22
22
  # - @params
23
23
  # - info: Special hash with the request parameters
@@ -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,27 @@
1
- FROM ruby:2.7.2
1
+ FROM ruby:2.7.2-slim
2
2
 
3
- RUN apt update
4
- RUN apt install -y git vim postgresql-client docker.io --no-install-recommends
3
+ ENV LANG=C.UTF-8
4
+ ENV LC_ALL=C.UTF-8
5
+
6
+ RUN apt update && \
7
+ apt install -y --no-install-recommends \
8
+ git \
9
+ netcat \
10
+ libpq-dev \
11
+ build-essential \
12
+ && rm -rf /var/lib/apt/lists/*
5
13
 
6
14
  WORKDIR /app/rubypitaya/
7
15
 
8
16
  COPY Gemfile Gemfile.lock ./
9
17
 
10
- RUN bundle install
18
+ RUN bundle config --global jobs 4 && \
19
+ bundle config --global set clean 'true' \
20
+ bundle config --global git.allow_insecure true && \
21
+ bundle install
11
22
 
12
23
  COPY . .
13
24
 
14
- ENV LANG=C.UTF-8
15
- ENV LC_ALL=C.UTF-8
16
-
17
25
  ENTRYPOINT ["./docker/entrypoint.sh"]
18
26
 
19
27
  CMD ["bundle", "exec", "rubypitaya", "run"]
@@ -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,36 +1,44 @@
1
- FROM ruby:2.7.2 as builder
1
+ FROM ruby:2.7.2-slim as builder
2
2
 
3
- WORKDIR /app/rubypitaya/
3
+ RUN apt update && \
4
+ apt install -y --no-install-recommends \
5
+ curl \
6
+ libpq-dev \
7
+ build-essential \
8
+ && rm -rf /var/lib/apt/lists/*
4
9
 
5
10
  COPY Gemfile Gemfile.lock ./
6
11
 
7
- ENV BUNDLER_WITHOUT development test
8
- RUN bundle install
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" && \
16
+ bundle install
9
17
 
10
- COPY . .
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
11
19
 
12
20
  FROM ruby:2.7.2-slim
13
21
 
14
- RUN apt update && apt install -y postgresql-client curl python3 bash vim --no-install-recommends
15
- RUN rm -rf /var/lib/apt/lists/*
22
+ ENV LANG=C.UTF-8
23
+ ENV LC_ALL=C.UTF-8
16
24
 
17
- 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 chmod +x ./kubectl
19
- RUN mv ./kubectl /usr/local/bin
25
+ RUN apt update && \
26
+ apt install -y --no-install-recommends \
27
+ netcat \
28
+ libpq5 \
29
+ && rm -rf /var/lib/apt/lists/*
20
30
 
21
- COPY --from=builder /usr/local/etc /usr/local/etc
22
31
  COPY --from=builder /usr/local/bundle /usr/local/bundle
23
- COPY --from=builder /usr/local/bin/ruby /usr/local/bin/ruby
24
- COPY --from=builder /usr/local/lib/ruby/gems/2.7.0 /usr/local/lib/ruby/gems/2.7.0
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
25
35
 
26
- COPY --from=builder /app/rubypitaya /app/rubypitaya
36
+ # COPY --from=builder /kubectl /usr/local/bin/kubectl
37
+ # RUN chmod +x /usr/local/bin/kubectl
27
38
 
28
39
  WORKDIR /app/rubypitaya/
29
40
 
30
- RUN rm -rf vendor/
31
-
32
- ENV LANG=C.UTF-8
33
- ENV LC_ALL=C.UTF-8
41
+ COPY . .
34
42
 
35
43
  ENTRYPOINT ["./docker/entrypoint.sh"]
36
44
 
@@ -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"