From 461bbdb3ec3d0b2db642c67883792bc28ea43c2c Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 10 Feb 2015 15:44:46 +0100 Subject: [PATCH] dockerize faye and counters --- .gitignore | 2 +- Models.dia | Bin 4435 -> 5005 bytes .../application_controller.js.coffee | 1 + app/controllers/dashboard_controller.rb | 6 +- app/models/list.rb | 8 + config/routes.rb | 2 +- drb_counter/Dockerfile | 28 +++ drb_counter/Gemfile | 4 + drb_counter/Gemfile.lock | 196 ++++++++++++++++++ drb_counter/couchdb_design.yml | 8 + {bin => drb_counter}/drb_counter.rb | 50 +++-- faye/Dockerfile | 29 +++ faye/Gemfile | 5 + faye/Gemfile.lock | 51 +++++ fig.yml | 24 ++- 15 files changed, 388 insertions(+), 26 deletions(-) create mode 100644 drb_counter/Dockerfile create mode 100644 drb_counter/Gemfile create mode 100644 drb_counter/Gemfile.lock create mode 100644 drb_counter/couchdb_design.yml rename {bin => drb_counter}/drb_counter.rb (61%) create mode 100644 faye/Dockerfile create mode 100644 faye/Gemfile create mode 100644 faye/Gemfile.lock diff --git a/.gitignore b/.gitignore index 13e841c4..2f615afe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ # git config --global core.excludesfile ~/.gitignore_global # Ignore bundler config -/.bundle +.bundle # Ignore the default SQLite database. /db/*.sqlite3 diff --git a/Models.dia b/Models.dia index c29c1de751178305663ae06561e9c273b8e265af..ec9c700cda2a7033aed6d8c6ad3982a57ca150f3 100644 GIT binary patch literal 5005 zcmZ{lbx;(Jw#OG1Swxyex*L%O$)#bJSYkms1r(%NIt3(ET3TuWK}x!N>5y(|knR$Y z>+jCIdGqd_cfK>9Ip_R&&YbU|kH!J~6PUmQ6C<~EkU$Z zHiE)1QyV)~Mb(NSAyzx+z^5yVz+22jzp?jE6-lZ~A;r7hm5ek&YgZ>L#t-LR^k-Ji zud5{CtS7jem%9(SERki4+25jhv#>*wN!9Y0PTLmlM7W~3TTRJ4Dk8Qn z&(Q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8D z-A%d&i(%-?oXmzM9G^Q;Yn!0BJ8As)@0x7LR>Gd!$~ANkt}%lYAf>>jm1)q50hJ7u~3iz|RYZ|GsIwy;x& z%vVJ}iw$Bhzy9|H4TRO|o#Get_td0{9@=f`O|a0ci9xqj|CFGG%fRmJK=4UHUI*qb zAKwkS+Pwc7rbrPx7Is=kHu{P@7cg5rd+r+u&e%ol;B#=;*!!`7J$UQdDyx;J3WVLt z)BO4NqZ&)zZYp1j|3!*cLFxaD!dEIrfkN?L%+3=AXD-7Ur-oOruXvqu_o%S1Nm|J~ zUI3V9oz=<G9>BHco1dDt=&z5m&jB{&#pB3GZ-? z7QjPwMelw#>K{*pho`*~F#TP@dVppq$$zPFzt^uG^qN!OJN3F+=a{)id{yzP_)qXi z!)i%(!)hxqlcB5F^adi9$1hW}zz^|yG-w>@Df$=`vXKY~7dN&D168ouguAXMzN8Z} zXOaE7T1n^ptFkfrBPA$O{>O2m9+0RHp>pxJqd$m5!fWR+TD5Q-p1JUR`ee87q3K+u z79ii8N#K2=(zu(cg9Z-DejS8$P`47MrRN7f0@@+)Rs3 zpvr$;`MNR`$P5Vj^eTeC>M=_+c!fstM*BX-I-~VeQ9+4&xJmV zR1>tOtC+W-e3$M7Feo`+3S;WW6&BLh^FrrUAM76AI6B_VHhj_C7C^NlcFO+G4!%i@ zDk1p%wrR~Qr9=CE%)<^o3n)EZ*6&4w(Y_Y)#*aHuitJ{?5f!D(-p0*e$)*`Q6iGZH zm{EQaLARdfUO~Jdw_DycrilNV>+NyZKTNL6(ia?RdO5e-?J`f_`?8K)PfK MN~rN@47@_|KLEd+fB*mh diff --git a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee index 5cd1df0e..1eb15657 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -21,6 +21,7 @@ App.ApplicationController = Ember.Controller.extend @set 'notice', '' ).observes('currentPath') events: + notify: (notification) -> @set 'notice', notification.message list_helped: -> @set 'list.needs_help', false list_needs_help: -> @set 'list.needs_help', true # incoming from other users list_is_paid: -> @set 'list.needs_payment', false diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index ff2aee60..0d82ea3c 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,4 +1,4 @@ - class DashboardController < ApplicationController +class DashboardController < ApplicationController layout 'theme1' before_action :allow_all_origins, only: :error_report @@ -13,6 +13,10 @@ render nothing: true end + def scan + + end + def close_window render layout: false end diff --git a/app/models/list.rb b/app/models/list.rb index 007a5dd0..5cb85323 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -52,6 +52,14 @@ class List } }], reduce_function: '_sum' + view :active_users_view, type: :custom, map_function: %[function(doc){ + if(doc.ruby_class == 'List' && doc.state == 'active'){ + doc.user_ids && doc.user_ids.forEach(function(uid){ + emit([doc.supplier_id, uid], 1); + }) + } + }], reduce_function: '_sum' + view :for_user_view, type: :custom, map_function: %|function(doc){ if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){ doc.user_ids.forEach(function(uid){ diff --git a/config/routes.rb b/config/routes.rb index a698dfc3..42af8b1f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,7 +87,7 @@ Qwaiter::Application.routes.draw do #get '/bars-restaurants' => 'dashboard#bars_restaurants', as: :bars_restaurants #get '/clients' => 'dashboard#clients' #get '/contact' => 'dashboard#contact' - get '/s' => redirect('/scan'), as: :scan + get '/s' => 'dashboard#scan', as: :scan # DEVELOPMENT ONLY get '/qr' => 'dashboard#qr' diff --git a/drb_counter/Dockerfile b/drb_counter/Dockerfile new file mode 100644 index 00000000..aa7a6537 --- /dev/null +++ b/drb_counter/Dockerfile @@ -0,0 +1,28 @@ +FROM ruby:2.2.0 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +RUN mkdir -p /usr/src/app + +WORKDIR /usr/src/app + +# Test +#RUN apt-get update && apt-get install -y qt5-default libqt5webkit5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Standard +#RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* +#RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Specific +#RUN apt-get update && apt-get install -y dos2unix --no-install-recommends && rm -rf /var/lib/apt/lists/* + +COPY Gemfile /usr/src/app/ +COPY Gemfile.lock /usr/src/app/ +#COPY vendor/cache /usr/src/app/vendor/cache +#RUN bundle install --local +RUN rm -rf /usr/src/app/.bundle +RUN bundle install + +COPY . /usr/src/app + +EXPOSE 9022 +CMD ["ruby", "drb_counter.rb"] diff --git a/drb_counter/Gemfile b/drb_counter/Gemfile new file mode 100644 index 00000000..0ef2abef --- /dev/null +++ b/drb_counter/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem "couchrest" +gem "pry" diff --git a/drb_counter/Gemfile.lock b/drb_counter/Gemfile.lock new file mode 100644 index 00000000..3cd7ec73 --- /dev/null +++ b/drb_counter/Gemfile.lock @@ -0,0 +1,196 @@ +GEM + remote: https://rubygems.org/ + specs: + coderay (1.1.0) + couchrest (1.2.0) + mime-types (~> 1.15) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + multi_json (~> 1.0) + rest-client (~> 1.6.1) + method_source (0.8.2) + mime-types (1.25.1) + multi_json (1.10.1) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rdoc (4.2.0) + rest-client (1.6.8) + mime-types (~> 1.16) + rdoc (>= 2.4.2) + slop (3.6.0) + +PLATFORMS + ruby + +DEPENDENCIES + couchrest + pry diff --git a/drb_counter/couchdb_design.yml b/drb_counter/couchdb_design.yml new file mode 100644 index 00000000..7bb546a2 --- /dev/null +++ b/drb_counter/couchdb_design.yml @@ -0,0 +1,8 @@ +views: + by_supplier_id_and_state: + map: | + function(doc) { + if(doc.ruby_class && doc.ruby_class == 'Order') emit([doc['supplier_id'], doc['state']], 1); + } + reduce: _sum +language: "javascript" diff --git a/bin/drb_counter.rb b/drb_counter/drb_counter.rb similarity index 61% rename from bin/drb_counter.rb rename to drb_counter/drb_counter.rb index 6225babd..84edb967 100755 --- a/bin/drb_counter.rb +++ b/drb_counter/drb_counter.rb @@ -1,6 +1,8 @@ #!/usr/bin/env ruby # Make drb server require 'rubygems' +require 'drb' +require 'pry' #require File.expand_path('../lib/in_memory_q_counter', File.dirname(__FILE__)) # This is a non thread safe replacement for the # couchbase counter mechanism since every test needs @@ -16,14 +18,18 @@ class InMemoryQCounter end def get(key, options = {}) - store[key] + value = store[key] + debug "Get key #{key} (#{value})" + value end def set(key, value) + debug "Set key #{key} to #{value}" store[key] = value end def incr(key, options = {}) + debug "Increment key #{key}" # store[key] ||= options[:initial].to_i # store[key] += 1 if store[key] @@ -34,6 +40,7 @@ class InMemoryQCounter end def decr(key, options = {}) + debug "Decrement key #{key}" # store[key] ||= options[:initial].to_i # store[key] -= 1 if store[key] @@ -44,22 +51,45 @@ class InMemoryQCounter end def flush + debug "Flushing store" store.clear end + def debug(message) + puts message + end + def reload_stats! require 'yaml' require 'couchrest' require 'pry' - binding.pry - couch_settings_path = File.join(ENV['MOZO_PATH'], 'config/couchdb.yml') + couch_settings_path = 'config/couchdb.yml' puts "Couch settings path: #{couch_settings_path}" puts "Environment: #{environment.inspect}" couch_settings = YAML.load_file(couch_settings_path)[environment] database = couch_settings['database'] db = CouchRest.database(database) - view_result = db.view("_design/order/_view/by_supplier_id_and_state", reduce: true, group_level: 2) + design_doc = "_design/order_counter" + view_path = File.join design_doc, "_view/by_supplier_id_and_state" + tries = 0 + begin + view_result = db.view(view_path, reduce: true, group: true, group_level: 2) + rescue RestClient::ResourceNotFound => e + puts "Database view #{view_path} not found" + design_doc_path = File.expand_path('../couchdb_design.yml', __FILE__) + doc = YAML.load_file design_doc_path + doc['_id'] = design_doc + db.save_doc(doc) + if tries < 3 + tries += 1 + retry + else + raise e + end + # view not available, initialize as zero + end counts = view_result ? view_result['rows'] : nil + puts "Initialize with: #{counts.to_yaml}" if counts counts.each do |count_spec| supplier_id, order_state = count_spec['key'] @@ -70,17 +100,11 @@ class InMemoryQCounter end end end - rescue RestClient::ResourceNotFound - # view not available, initialize as zero rescue => e raise e end end -require 'drb' -require 'daemons' drb_port = 9022 -Daemons.run_proc('DRBcounter', dir_mode: :normal, dir: File.expand_path("#{File.dirname(__FILE__)}/../tmp/pids")) do - environment = (%w[production staging development test] & ARGV).first - DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: true, environment: environment) - DRb.thread.join -end +environment = (%w[production staging development test] & ARGV).first || 'development' +DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: true, environment: environment) +DRb.thread.join diff --git a/faye/Dockerfile b/faye/Dockerfile new file mode 100644 index 00000000..f2b3dcbf --- /dev/null +++ b/faye/Dockerfile @@ -0,0 +1,29 @@ +FROM ruby:2.2.0 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +RUN mkdir -p /usr/src/app + +WORKDIR /usr/src/app +RUN apt-get update +# Test +#RUN apt-get update && apt-get install -y qt5-default libqt5webkit5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Standard +#RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/* +#RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/* +# Specific +#RUN apt-get update && apt-get install -y dos2unix --no-install-recommends && rm -rf /var/lib/apt/lists/* + +COPY Gemfile /usr/src/app/ +COPY Gemfile.lock /usr/src/app/ +#COPY vendor/cache /usr/src/app/vendor/cache +#RUN bundle install --local +RUN rm -rf /usr/src/app/.bundle +RUN bundle install + +COPY . /usr/src/app +ENV FAYE_PORT=9296 +EXPOSE $FAYE_PORT +CMD thin start -R config.ru -p $FAYE_PORT + diff --git a/faye/Gemfile b/faye/Gemfile new file mode 100644 index 00000000..9be00b22 --- /dev/null +++ b/faye/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem "faye" +gem "thin" +gem "pry" diff --git a/faye/Gemfile.lock b/faye/Gemfile.lock new file mode 100644 index 00000000..23235c76 --- /dev/null +++ b/faye/Gemfile.lock @@ -0,0 +1,51 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.3.7) + coderay (1.1.0) + cookiejar (0.3.2) + daemons (1.1.9) + em-http-request (1.1.2) + addressable (>= 2.3.4) + cookiejar + em-socksify (>= 0.3) + eventmachine (>= 1.0.3) + http_parser.rb (>= 0.6.0) + em-socksify (0.3.0) + eventmachine (>= 1.0.0.beta.4) + eventmachine (1.0.7) + faye (1.1.0) + cookiejar (>= 0.3.0) + em-http-request (>= 0.3.0) + eventmachine (>= 0.12.0) + faye-websocket (>= 0.9.1) + multi_json (>= 1.0.0) + rack (>= 1.0.0) + websocket-driver (>= 0.5.1) + faye-websocket (0.9.2) + eventmachine (>= 0.12.0) + websocket-driver (>= 0.5.1) + http_parser.rb (0.6.0) + method_source (0.8.2) + multi_json (1.10.1) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + rack (1.6.0) + slop (3.6.0) + thin (1.6.3) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0) + rack (~> 1.0) + websocket-driver (0.5.1) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.1) + +PLATFORMS + ruby + +DEPENDENCIES + faye + pry + thin diff --git a/fig.yml b/fig.yml index 463e1fca..9291cff5 100644 --- a/fig.yml +++ b/fig.yml @@ -6,14 +6,18 @@ db: - 5984 net: host counters: - image: ruby:2.2 -web: - build: . - #command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb - command: rails s + build: drb_counter + net: host volumes: - - .:/usr/src/app - ports: - - "3000:3000" - #links: - # #- db + - config:/usr/src/app/config +faye: + build: faye + net: host +#web: + #build: . + #command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb + #command: rails s + #volumes: + #- .:/usr/src/app + #ports: + #- "3000:3000"