rubypitaya 1.1.0

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 (44) hide show
  1. checksums.yaml +7 -0
  2. data/bin/rubypitaya +56 -0
  3. data/lib/rubypitaya/app-template/Gemfile +10 -0
  4. data/lib/rubypitaya/app-template/Gemfile.lock +83 -0
  5. data/lib/rubypitaya/app-template/Makefile +91 -0
  6. data/lib/rubypitaya/app-template/Rakefile +57 -0
  7. data/lib/rubypitaya/app-template/app/app_initializer.rb +23 -0
  8. data/lib/rubypitaya/app-template/app/bll/player_bll.rb +10 -0
  9. data/lib/rubypitaya/app-template/app/config/initial_player.json +3 -0
  10. data/lib/rubypitaya/app-template/app/constants/status_codes.rb +15 -0
  11. data/lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb +11 -0
  12. data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +79 -0
  13. data/lib/rubypitaya/app-template/app/models/player.rb +15 -0
  14. data/lib/rubypitaya/app-template/app/models/user.rb +4 -0
  15. data/lib/rubypitaya/app-template/bin/console +22 -0
  16. data/lib/rubypitaya/app-template/config/database.yml +22 -0
  17. data/lib/rubypitaya/app-template/db/migrate/001_create_user_migration.rb +12 -0
  18. data/lib/rubypitaya/app-template/db/migrate/002_create_player_migration.rb +14 -0
  19. data/lib/rubypitaya/app-template/docker/dev/Dockerfile +19 -0
  20. data/lib/rubypitaya/app-template/docker/entrypoint.sh +13 -0
  21. data/lib/rubypitaya/app-template/docker/prod/Dockerfile +32 -0
  22. data/lib/rubypitaya/app-template/docker/prod/Makefile +67 -0
  23. data/lib/rubypitaya/app-template/docker-compose.yml +75 -0
  24. data/lib/rubypitaya/core/application_files_importer.rb +13 -0
  25. data/lib/rubypitaya/core/config.rb +33 -0
  26. data/lib/rubypitaya/core/database_config.rb +50 -0
  27. data/lib/rubypitaya/core/database_connector.rb +22 -0
  28. data/lib/rubypitaya/core/etcd_connector.rb +75 -0
  29. data/lib/rubypitaya/core/handler_base.rb +26 -0
  30. data/lib/rubypitaya/core/handler_router.rb +71 -0
  31. data/lib/rubypitaya/core/initializer_base.rb +8 -0
  32. data/lib/rubypitaya/core/initializer_broadcast.rb +15 -0
  33. data/lib/rubypitaya/core/initializer_content.rb +12 -0
  34. data/lib/rubypitaya/core/instance_holder.rb +17 -0
  35. data/lib/rubypitaya/core/main.rb +121 -0
  36. data/lib/rubypitaya/core/nats_connector.rb +148 -0
  37. data/lib/rubypitaya/core/parameters.rb +245 -0
  38. data/lib/rubypitaya/core/path.rb +13 -0
  39. data/lib/rubypitaya/core/postman.rb +31 -0
  40. data/lib/rubypitaya/core/redis_connector.rb +26 -0
  41. data/lib/rubypitaya/core/session.rb +29 -0
  42. data/lib/rubypitaya/version.rb +4 -0
  43. data/lib/rubypitaya.rb +20 -0
  44. metadata +240 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 573d0dce81f6383ae631e5bcde6676f45d516ce7a38b51eefa4ebd922d229e4e
4
+ data.tar.gz: 1b163c885db0a3a532edfd21d07cd9058f7003f2ad44dd40e90429f1311c337e
5
+ SHA512:
6
+ metadata.gz: b5a39ccf4533c32c285c1e31f0db14131c3a255639693e4c343b4d2f8cd2fda9f4be5d000c7b68a0a7b78fbb9a80d32e26a23792a3e88dbaab27efefd7ceb55c
7
+ data.tar.gz: bc1c57916f513bac17a22e8b3ad720d725d93fd9369111b6bcb0fd18175063c7a69e84e90cf1aaab474ad215c0658102c10c7355ce075783fa85c53302e98035
data/bin/rubypitaya ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubypitaya'
4
+
5
+ COMMANDS = ['run', 'create']
6
+
7
+ def main
8
+ if ARGV.size == 0 || !COMMANDS.include?(ARGV[0])
9
+ show_help()
10
+ exit(-1)
11
+ end
12
+
13
+ command = ARGV[0]
14
+
15
+ if command == 'run'
16
+ command_run(ARGV)
17
+ end
18
+
19
+ if command == 'create'
20
+ command_create(ARGV)
21
+ end
22
+ end
23
+
24
+ def command_run(argv)
25
+ puts 'Starting server...'
26
+ RubyPitaya::RubyPitaya.run_server
27
+ end
28
+
29
+ def command_create(argv)
30
+ if argv.size <= 1
31
+ show_help_create()
32
+ exit(-1)
33
+ end
34
+
35
+ project_name = argv[1]
36
+ folder_path = Dir.pwd
37
+
38
+ RubyPitaya::RubyPitaya.create_project(project_name, folder_path)
39
+
40
+ puts "Project #{project_name} created!"
41
+ end
42
+
43
+ def show_help
44
+ puts 'Usage: $ rubypitaya [COMMAND]'
45
+ puts 'COMMAND:'
46
+ puts ' run: - Run server'
47
+ puts ' create: - Create project'
48
+ puts ''
49
+ end
50
+
51
+ def show_help_create
52
+ puts 'Usage: $ rubypitaya create [project_name]'
53
+ puts ''
54
+ end
55
+
56
+ main
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rubypitaya', '1.1.0'
4
+
5
+ group :development do
6
+ gem 'pry', '0.12.2'
7
+ gem 'bundler', '1.17.2'
8
+ gem 'rake', '10.0'
9
+ gem 'rspec', '3.8.0'
10
+ end
@@ -0,0 +1,83 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activemodel (6.0.2)
5
+ activesupport (= 6.0.2)
6
+ activerecord (6.0.2)
7
+ activemodel (= 6.0.2)
8
+ activesupport (= 6.0.2)
9
+ activesupport (6.0.2)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 0.7, < 2)
12
+ minitest (~> 5.1)
13
+ tzinfo (~> 1.1)
14
+ zeitwerk (~> 2.2)
15
+ coderay (1.1.2)
16
+ concurrent-ruby (1.1.6)
17
+ diff-lcs (1.3)
18
+ etcdv3 (0.10.2)
19
+ grpc (~> 1.17)
20
+ eventmachine (1.2.7)
21
+ google-protobuf (3.11.4)
22
+ googleapis-common-protos-types (1.0.5)
23
+ google-protobuf (~> 3.11)
24
+ grpc (1.28.0)
25
+ google-protobuf (~> 3.11)
26
+ googleapis-common-protos-types (~> 1.0)
27
+ i18n (1.8.2)
28
+ concurrent-ruby (~> 1.0)
29
+ method_source (0.9.2)
30
+ middleware (0.1.0)
31
+ minitest (5.14.0)
32
+ nats (0.11.0)
33
+ eventmachine (~> 1.2, >= 1.2)
34
+ pg (0.21.0)
35
+ protobuf (3.10.0)
36
+ activesupport (>= 3.2)
37
+ middleware
38
+ thor
39
+ thread_safe
40
+ pry (0.12.2)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.9.0)
43
+ rake (10.0.0)
44
+ redis (4.1.3)
45
+ rspec (3.8.0)
46
+ rspec-core (~> 3.8.0)
47
+ rspec-expectations (~> 3.8.0)
48
+ rspec-mocks (~> 3.8.0)
49
+ rspec-core (3.8.2)
50
+ rspec-support (~> 3.8.0)
51
+ rspec-expectations (3.8.6)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.8.0)
54
+ rspec-mocks (3.8.2)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-support (3.8.3)
58
+ rubypitaya (1.1.0)
59
+ activerecord (= 6.0.2)
60
+ etcdv3 (= 0.10.2)
61
+ eventmachine (= 1.2.7)
62
+ nats (= 0.11.0)
63
+ pg (= 0.21.0)
64
+ protobuf (= 3.10.0)
65
+ redis (= 4.1.3)
66
+ thor (1.0.1)
67
+ thread_safe (0.3.6)
68
+ tzinfo (1.2.7)
69
+ thread_safe (~> 0.1)
70
+ zeitwerk (2.3.0)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ bundler (= 1.17.2)
77
+ pry (= 0.12.2)
78
+ rake (= 10.0)
79
+ rspec (= 3.8.0)
80
+ rubypitaya (= 1.0.6)
81
+
82
+ BUNDLED WITH
83
+ 1.17.2
@@ -0,0 +1,91 @@
1
+ ## Run ruby pitaya metagame project
2
+ run:
3
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rubypitaya run
4
+
5
+ ## Build project
6
+ build:
7
+ @docker-compose build
8
+
9
+ ## Kill all containers
10
+ kill:
11
+ @docker rm -f $$(docker-compose ps -aq)
12
+
13
+ ## Run tests
14
+ test:
15
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rspec
16
+
17
+ ## Run ruby irb console
18
+ console:
19
+ @docker-compose run --service-ports --rm rubypitaya bundle exec ruby ./bin/console
20
+
21
+ ## Run bash on container
22
+ bash:
23
+ @docker-compose run --service-ports --rm rubypitaya bash
24
+
25
+ ## Create database
26
+ db-create:
27
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:create
28
+
29
+ ## Run migrations to database
30
+ db-migrate:
31
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:migrate
32
+
33
+ ## Drop database
34
+ db-drop:
35
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:drop
36
+
37
+ ## Reset database
38
+ db-reset:
39
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
40
+
41
+ ## Generate Gemfile.lock
42
+ generate-gemfilelock:
43
+ @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.6.6 bundle install
44
+
45
+ ## Build image to production environment
46
+ prod-build-image:
47
+ @docker build . -f docker/prod/Dockerfile -t registry.gitlab.com/lucianopc/ruby-pitaya-app:latest
48
+
49
+ .DEFAULT_GOAL := show-help
50
+
51
+ .PHONY: show-help
52
+ show-help:
53
+ @echo "$$(tput bold)Commands:$$(tput sgr0)"
54
+ @echo
55
+ @sed -n -e "/^## / { \
56
+ h; \
57
+ s/.*//; \
58
+ :doc" \
59
+ -e "H; \
60
+ n; \
61
+ s/^## //; \
62
+ t doc" \
63
+ -e "s/:.*//; \
64
+ G; \
65
+ s/\\n## /---/; \
66
+ s/\\n/ /g; \
67
+ p; \
68
+ }" ${MAKEFILE_LIST} \
69
+ | LC_ALL='C' sort --ignore-case \
70
+ | awk -F '---' \
71
+ -v ncol=$$(tput cols) \
72
+ -v indent=22 \
73
+ -v col_on="$$(tput setaf 6)" \
74
+ -v col_off="$$(tput sgr0)" \
75
+ '{ \
76
+ printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
77
+ n = split($$2, words, " "); \
78
+ line_length = ncol - indent; \
79
+ for (i = 1; i <= n; i++) { \
80
+ line_length -= length(words[i]) + 1; \
81
+ if (line_length <= 0) { \
82
+ line_length = ncol - indent - length(words[i]) - 1; \
83
+ printf "\n%*s ", -indent, " "; \
84
+ } \
85
+ printf "%s ", words[i]; \
86
+ } \
87
+ printf "\n"; \
88
+ }'
89
+
90
+
91
+
@@ -0,0 +1,57 @@
1
+ require 'active_record'
2
+
3
+ require 'rubypitaya/core/path'
4
+ require 'rubypitaya/core/database_config'
5
+
6
+
7
+ namespace :db do
8
+
9
+ desc 'Create the database'
10
+ task :create do
11
+ environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
12
+ database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
13
+ connection_data = database_config.connection_data_without_database
14
+
15
+ ActiveRecord::Base.establish_connection(connection_data)
16
+ ActiveRecord::Base.connection.create_database(database_config.database_name)
17
+ ActiveRecord::Base.connection.close
18
+
19
+ puts 'Database created.'
20
+ end
21
+
22
+ desc 'Migrate the database'
23
+ task :migrate do
24
+ environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
25
+ database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
26
+ connection_data = database_config.connection_data
27
+ migrations_path = RubyPitaya::Path::MIGRATIONS_FOLDER_PATH
28
+
29
+ ActiveRecord::Base.establish_connection(connection_data)
30
+ ActiveRecord::Migrator.migrations_paths = [migrations_path]
31
+ ActiveRecord::Tasks::DatabaseTasks.migrate
32
+ ActiveRecord::Base.connection.close
33
+ puts 'Database migrated.'
34
+ end
35
+
36
+ desc 'Drop the database'
37
+ task :drop do
38
+ environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
39
+ database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
40
+ connection_data = database_config.connection_data_without_database
41
+
42
+ ActiveRecord::Base.establish_connection(connection_data)
43
+ ActiveRecord::Base.connection.drop_database(database_config.database_name)
44
+ ActiveRecord::Base.connection.close
45
+
46
+ puts 'Database deleted.'
47
+ end
48
+
49
+ desc 'Reset the database'
50
+ task :reset do
51
+ Rake::Task['db:drop'].invoke
52
+ Rake::Task['db:create'].invoke
53
+ Rake::Task['db:migrate'].invoke
54
+
55
+ puts 'Database reset finish.'
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ class AppInitializer < RubyPitaya::InitializerBase
2
+
3
+ # method: run
4
+ # parameter: initializer_content
5
+ # attributes:
6
+ # - bll
7
+ # - class: InstanceHolder
8
+ # - methods:
9
+ # - add_instance(key, instance)
10
+ # - add any instance to any key
11
+ # - [](key)
12
+ # - get instance by key
13
+ # - redis
14
+ # - link: https://github.com/redis/redis-rb/
15
+
16
+ def run(initializer_content)
17
+ bll = initializer_content.bll
18
+
19
+ playerBll = PlayerBLL.new
20
+
21
+ bll.add_instance(:player, playerBll)
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ class PlayerBLL
2
+
3
+ def create_new_player(config)
4
+ name = config['initial_player']['name']
5
+
6
+ player = Player.new(name: name, user: User.new)
7
+ player.save
8
+ player
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "Guest"
3
+ }
@@ -0,0 +1,15 @@
1
+ class StatusCodes
2
+ # Success codes
3
+ CODE_OK = 'RP-200'
4
+
5
+ # Error codes
6
+ CODE_UNKNOWN = 'RP-000'
7
+ CODE_HANDLER_NOT_FOUNDED = 'RP-001'
8
+ CODE_ACTION_NOT_FOUNDED = 'RP-002'
9
+ CODE_NOT_AUTHENTICATED = 'RP-003'
10
+ CODE_AUTHENTICATION_ERROR = 'RP-004'
11
+
12
+ class Connector
13
+ CODE_UNKNOWN = 'PIT-000'
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class HelloWorldHandler < RubyPitaya::HandlerBase
2
+
3
+ non_authenticated_actions :sayHello
4
+
5
+ def sayHello
6
+ response = {
7
+ code: 'RP-200',
8
+ msg: 'Hello!'
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,79 @@
1
+ class PlayerHandler < RubyPitaya::HandlerBase
2
+
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)`
43
+
44
+ non_authenticated_actions :authenticate
45
+
46
+ def authenticate
47
+ user_id = @params[:userId]
48
+
49
+ player = Player.find_by_user_id(user_id)
50
+ player = @bll[:player].create_new_player(@config) if player.nil?
51
+
52
+ @session.uid = player.user_id
53
+
54
+ bind_session_response = @postman.bind_session(@session)
55
+
56
+ unless bind_session_response.dig(:error, :code).nil?
57
+ return response = {
58
+ code: StatusCodes::CODE_AUTHENTICATION_ERROR,
59
+ msg: 'Error to authenticate',
60
+ }
61
+ end
62
+
63
+ response = {
64
+ code: StatusCodes::CODE_OK,
65
+ player: player.to_hash,
66
+ }
67
+ end
68
+
69
+ def getInfo
70
+ user_id = @session.uid
71
+
72
+ player = Player.find_by_user_id(user_id)
73
+
74
+ response = {
75
+ code: StatusCodes::CODE_OK,
76
+ player: player.to_hash,
77
+ }
78
+ end
79
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_record'
2
+
3
+ class Player < ActiveRecord::Base
4
+
5
+ belongs_to :user
6
+
7
+ validates_presence_of :name, :user
8
+
9
+ def to_hash
10
+ {
11
+ name: name,
12
+ userId: user_id,
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ require 'active_record'
2
+
3
+ class User < ActiveRecord::Base
4
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'active_record'
5
+
6
+ require 'rubypitaya'
7
+ require 'rubypitaya/core/database_config'
8
+
9
+ environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
10
+ database_config = DatabaseConfig.new(environment_name, Path::DATABASE_CONFIG_PATH)
11
+ ActiveRecord::Base.establish_connection(database_config.connection_data)
12
+ ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
13
+ ActiveSupport::LogSubscriber.colorize_logging = true
14
+
15
+ Gem.find_files('rubypitaya/**/*.rb').each do |path|
16
+ require path unless path.end_with?('spec.rb') || path.include?('db/migrate')
17
+ end
18
+
19
+ require 'irb'
20
+ IRB.start(__FILE__)
21
+
22
+ ActiveRecord::Base.connection.close
@@ -0,0 +1,22 @@
1
+ default: &default
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ pool: <%= ENV['RUBYPITAYA_MAX_THREADS'] { 5 } %>
5
+ host: <%= ENV['DATABASE_HOST'] %>
6
+ user: <%= ENV['DATABASE_USER'] %>
7
+ password: <%= ENV['DATABASE_PASSWORD'] %>
8
+
9
+ development:
10
+ <<: *default
11
+ database: <%= "#{ENV['DATABASE_NAME']}_development" %>
12
+
13
+ test:
14
+ <<: *default
15
+ database: <%= "#{ENV['DATABASE_NAME']}_test" %>
16
+
17
+ production:
18
+ <<: *default
19
+ database: <%= "#{ENV['DATABASE_NAME']}_production" %>
20
+ # username: rails_project
21
+ # password: <%= ENV['RAILS_PROJECT_DATABASE_PASSWORD'] %>
22
+
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+
3
+ class CreateUserMigration < ActiveRecord::Migration[5.1]
4
+
5
+ enable_extension 'pgcrypto'
6
+
7
+ def change
8
+ create_table :users, id: :uuid do |t|
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_record'
2
+
3
+ class CreatePlayerMigration < ActiveRecord::Migration[5.1]
4
+
5
+ enable_extension 'pgcrypto'
6
+
7
+ def change
8
+ create_table :players, id: :uuid do |t|
9
+ t.belongs_to :user, type: :uuid
10
+ t.string :name, null: false
11
+ t.timestamps null: false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ FROM ruby:2.6.6
2
+
3
+ RUN apt update
4
+ RUN apt install -y git vim docker.io postgresql-client --no-install-recommends
5
+
6
+ WORKDIR /app/rubypitaya/
7
+
8
+ COPY Gemfile Gemfile.lock ./
9
+
10
+ RUN bundle install
11
+
12
+ COPY . .
13
+
14
+ ENV LANG=C.UTF-8
15
+ ENV LC_ALL=C.UTF-8
16
+
17
+ ENTRYPOINT ["./docker/entrypoint.sh"]
18
+
19
+ CMD ["bundle", "exec", "rubypitaya"]
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+
3
+ cmd="$@"
4
+
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
10
+
11
+ echo "=> Postgres is ready"
12
+
13
+ exec $cmd
@@ -0,0 +1,32 @@
1
+ FROM ruby:2.6.6 as builder
2
+
3
+ WORKDIR /app/rubypitaya/
4
+
5
+ COPY Gemfile Gemfile.lock ./
6
+
7
+ RUN bundle install
8
+
9
+ COPY . .
10
+
11
+ FROM ruby:2.6.6-slim
12
+
13
+ RUN apt update && apt install -y docker.io postgresql-client --no-install-recommends
14
+ RUN rm -rf /var/lib/apt/lists/*
15
+
16
+ COPY --from=builder /usr/local/etc /usr/local/etc
17
+ COPY --from=builder /usr/local/bundle /usr/local/bundle
18
+ COPY --from=builder /usr/local/bin/ruby /usr/local/bin/ruby
19
+ COPY --from=builder /usr/local/lib/ruby/gems/2.6.0 /usr/local/lib/ruby/gems/2.6.0
20
+
21
+ COPY --from=builder /app/rubypitaya /app/rubypitaya
22
+
23
+ WORKDIR /app/rubypitaya/
24
+
25
+ RUN rm -rf vendor/
26
+
27
+ ENV LANG=C.UTF-8
28
+ ENV LC_ALL=C.UTF-8
29
+
30
+ ENTRYPOINT ["./docker/entrypoint.sh"]
31
+
32
+ CMD ["bundle", "exec", "rubypitaya"]
@@ -0,0 +1,67 @@
1
+ ## Run ruby pitaya metagame project
2
+ run:
3
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rubypitaya
4
+
5
+ ## Update docker images
6
+ update:
7
+ @docker-compose pull
8
+
9
+ ## Create database
10
+ db-create:
11
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:create
12
+
13
+ ## Run migrations to database
14
+ db-migrate:
15
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:migrate
16
+
17
+ ## Drop database
18
+ db-drop:
19
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:drop
20
+
21
+ ## Reset database
22
+ db-reset:
23
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
24
+
25
+ .DEFAULT_GOAL := show-help
26
+
27
+ .PHONY: show-help
28
+ show-help:
29
+ @echo "$$(tput bold)Commands:$$(tput sgr0)"
30
+ @echo
31
+ @sed -n -e "/^## / { \
32
+ h; \
33
+ s/.*//; \
34
+ :doc" \
35
+ -e "H; \
36
+ n; \
37
+ s/^## //; \
38
+ t doc" \
39
+ -e "s/:.*//; \
40
+ G; \
41
+ s/\\n## /---/; \
42
+ s/\\n/ /g; \
43
+ p; \
44
+ }" ${MAKEFILE_LIST} \
45
+ | LC_ALL='C' sort --ignore-case \
46
+ | awk -F '---' \
47
+ -v ncol=$$(tput cols) \
48
+ -v indent=19 \
49
+ -v col_on="$$(tput setaf 6)" \
50
+ -v col_off="$$(tput sgr0)" \
51
+ '{ \
52
+ printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
53
+ n = split($$2, words, " "); \
54
+ line_length = ncol - indent; \
55
+ for (i = 1; i <= n; i++) { \
56
+ line_length -= length(words[i]) + 1; \
57
+ if (line_length <= 0) { \
58
+ line_length = ncol - indent - length(words[i]) - 1; \
59
+ printf "\n%*s ", -indent, " "; \
60
+ } \
61
+ printf "%s ", words[i]; \
62
+ } \
63
+ printf "\n"; \
64
+ }'
65
+
66
+
67
+