Add docker dev version

Add env and docker files for development

Fix some random things related to rails upgrade
This commit is contained in:
Ari Timonen 2019-09-24 22:55:34 +03:00
parent 23b545779d
commit 11fcea3259
16 changed files with 508 additions and 402 deletions

26
.env.dev Normal file
View file

@ -0,0 +1,26 @@
RACK_ENV=development
RAILS_ENV=development
APP_SECRET=fe837ea72667ec3d8ecb94cfba1a1bba
DEPLOY_PATH=/var/www
PUMA_WORKERS=1
PUMA_MIN_THREADS=1
PUMA_MAX_THREADS=16
PUMA_PORT=4000
PUMA_TIMEOUT=30
MYSQL_HOST=db
MYSQL_DATABASE=ensl
MYSQL_USERNAME=ensl
MYSQL_PASSWORD=ensl
MYSQL_ROOT_PASSWORD=ensl
MYSQL_CONNECTION_POOL=8
NEW_RELIC_APP_NAME=ENSL
NEW_RELIC_LICENSE_KEY=
EXCEPTIONAL_API_KEY=
GOOGLE_API_KEY=
GOOGLE_CALENDAR_ID=

4
.gitignore vendored
View file

@ -12,6 +12,10 @@
*.rbc
*.sassc
# MySQL
db_data/
db_data*/
# OS X
.DS_Store

25
Dockerfile.dev Normal file
View file

@ -0,0 +1,25 @@
FROM ruby:2.2.10
ENV RAILS_ENV development
# Add 'web' user which will run the application
RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos ""
RUN apt-get update && apt-get -y upgrade \
&& apt-get -y install mysql-client libmysqlclient-dev memcached nodejs \
&& service memcached start
# Separate Gemfile ADD so that `bundle install` can be cached more effectively
ADD Gemfile Gemfile.lock /var/www/
RUN mkdir -p /var/bundle && chown -R web:web /var/bundle && chown -R web:web /var/www
RUN su -c "bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4" -s /bin/bash -l web
WORKDIR /var/www
USER web
RUN bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4
USER root
CMD ["/var/www/script/entry.sh"]

View file

@ -19,11 +19,14 @@ gem 'bluecloth', '~> 2.2.0'
gem 'newrelic_rpm', '~> 3.7.2.195'
gem 'will_paginate', '~> 3.0.5'
gem 'dynamic_form', '~> 1.1.4'
gem 'i18n_country_select', '~> 1.1.5'
gem 'i18n_country_select'
gem 'country_select'
gem 'active_link_to', '~> 1.0.2'
gem 'rmagick', '~> 2.13.4', require: false
gem 'test-unit', '~> 3.1.3'
gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby'
gem 'public_suffix', '~> 3.1.1'
gem 'active_record_union'
# Please install nodejs locally.
gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux'

View file

@ -1,6 +1,6 @@
GIT
remote: git://github.com/koraktor/steam-condenser-ruby.git
revision: 6bc46e5638f984765f198ad5ae4dbe38ef9341f9
remote: https://github.com/koraktor/steam-condenser-ruby.git
revision: 2cb441f0518a0b8d20a017dfcc42783ae878311a
specs:
steam-condenser (1.3.11)
multi_json (~> 1.6)
@ -22,8 +22,11 @@ GEM
activesupport (= 4.1.16)
builder (~> 3.1)
erubis (~> 2.7.0)
active_link_to (1.0.2)
active_link_to (1.0.5)
actionpack
addressable
active_record_union (1.3.0)
activerecord (>= 4.0)
activemodel (4.1.16)
activesupport (= 4.1.16)
builder (~> 3.1)
@ -37,15 +40,17 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
annotate (2.6.3)
activerecord (>= 2.3.0)
rake (>= 0.8.7)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
annotate (2.6.10)
activerecord (>= 3.2, <= 4.3)
rake (~> 10.4)
arel (5.0.1.20140414130214)
bbcoder (1.0.1)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
binding_of_caller (0.7.3)
debug_inspector (>= 0.0.1)
bluecloth (2.2.0)
bourbon (3.1.8)
@ -59,13 +64,13 @@ GEM
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
capistrano-bundler (1.1.2)
capistrano (~> 3.0)
capistrano-bundler (1.1.4)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-rails (1.1.1)
capistrano-rails (1.4.0)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-rbenv (2.0.2)
capistrano-rbenv (2.0.4)
capistrano (~> 3.1)
sshkit (~> 1.3)
capybara (2.4.4)
@ -79,26 +84,33 @@ GEM
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
childprocess (0.5.6)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
cliver (0.3.2)
codeclimate-test-reporter (0.3.0)
simplecov (>= 0.7.1, < 1.0.0)
coderay (1.1.0)
coderay (1.1.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.9.1.1)
columnize (0.8.9)
coffee-script-source (1.12.2)
columnize (0.9.0)
concurrent-ruby (1.1.5)
dalli (2.7.1)
countries (3.0.0)
i18n_data (~> 0.8.0)
sixarm_ruby_unaccent (~> 1.1)
unicode_utils (~> 1.4)
country_select (4.0.0)
countries (~> 3.0)
sort_alphabetical (~> 1.0)
dalli (2.7.10)
database_cleaner (1.2.0)
debug_inspector (0.0.2)
debug_inspector (0.0.3)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
diff-lcs (1.3)
dotenv (0.10.0)
dotenv-rails (0.10.0)
dotenv (= 0.10.0)
@ -106,74 +118,75 @@ GEM
erubis (2.7.0)
exceptional (2.0.33)
rack
execjs (2.6.0)
execjs (2.7.0)
factory_girl (4.4.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.4.1)
factory_girl (~> 4.4.0)
railties (>= 3.0.0)
faraday (0.9.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
ffi (1.11.1)
font-awesome-sass (4.1.0)
sass (~> 3.2)
haml (4.0.5)
haml (4.0.7)
tilt
i18n (0.9.5)
concurrent-ruby (~> 1.0)
i18n-country-translations (1.2.2)
i18n (~> 0.5)
railties (>= 3.0)
i18n_country_select (1.1.5)
i18n-country-translations (1.3.0)
i18n (~> 0.9.3)
railties (~> 4.0)
i18n_country_select (1.1.7)
i18n (~> 0.5)
i18n-country-translations (~> 1.0, >= 1.0.3)
unicode_utils (~> 1.0, >= 1.0.0)
i18n_data (0.8.0)
jquery-rails (2.0.3)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.8.3)
json (1.8.6)
libv8 (3.16.14.19)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.8.2)
mime-types (3.2.2)
method_source (0.9.2)
mime-types (3.3)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
mini_mime (1.0.1)
mini_portile (0.6.2)
mime-types-data (3.2019.0904)
mini_mime (1.0.2)
mini_portile2 (2.1.0)
minitest (5.11.3)
multi_json (1.13.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
mysql2 (0.3.21)
neat (1.6.0)
bourbon (>= 3.1)
sass (>= 3.3)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.0)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-ssh (5.2.0)
newrelic_rpm (3.7.2.195)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
oj (2.5.5)
poltergeist (1.6.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
power_assert (0.2.4)
protected_attributes (1.1.3)
power_assert (1.1.5)
protected_attributes (1.1.4)
activemodel (>= 4.0.1, < 5.0)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
pry-byebug (1.3.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (1.3.3)
byebug (~> 2.7)
pry (~> 0.9.12)
puma (2.11.1)
pry (~> 0.10)
public_suffix (3.1.1)
puma (2.11.3)
rack (>= 1.1, < 2.0)
quiet_assets (1.0.2)
quiet_assets (1.0.3)
railties (>= 3.1, < 5.0)
rack (1.5.5)
rack-test (0.6.3)
@ -188,14 +201,17 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.16)
sprockets-rails (~> 2.0)
rails_autolink (1.1.5)
rails_autolink (1.1.6)
rails (> 3.1)
railties (4.1.16)
actionpack (= 4.1.16)
activesupport (= 4.1.16)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.2)
rake (10.5.0)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
ref (2.0.0)
rmagick (2.13.4)
rspec-core (3.3.2)
@ -215,16 +231,20 @@ GEM
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
rubyzip (1.1.7)
sanitize (2.1.0)
rubyzip (1.2.4)
sanitize (2.1.1)
nokogiri (>= 1.4.4)
sass (3.4.16)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
tilt (>= 1.1, < 3)
selenium-webdriver (2.47.1)
childprocess (~> 0.5)
multi_json (~> 1.0)
@ -234,7 +254,9 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
slop (3.5.0)
sixarm_ruby_unaccent (1.2.0)
sort_alphabetical (1.1.0)
unicode_utils (>= 1.2.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
@ -242,36 +264,32 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sshkit (1.4.0)
sshkit (1.20.0)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
term-ansicolor
term-ansicolor (1.3.0)
tins (~> 1.0)
test-unit (3.1.3)
test-unit (3.1.9)
power_assert
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
thor (0.20.3)
thread_safe (0.3.6)
tilt (1.4.1)
timecop (0.7.1)
tins (1.1.0)
tinymce-rails (3.5.9)
tilt (2.0.9)
timecop (0.7.4)
tinymce-rails (3.5.11.1)
railties (>= 3.1.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (2.5.0)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicode_utils (1.4.0)
websocket (1.2.2)
websocket-driver (0.5.4)
websocket (1.2.8)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
websocket-extensions (0.1.4)
will_paginate (3.0.12)
xpath (2.0.0)
xpath (2.1.0)
nokogiri (~> 1.3)
PLATFORMS
@ -279,6 +297,7 @@ PLATFORMS
DEPENDENCIES
active_link_to (~> 1.0.2)
active_record_union
annotate (~> 2.6.2)
bbcoder (~> 1.0.1)
better_errors (~> 1.1.0)
@ -293,6 +312,7 @@ DEPENDENCIES
carrierwave (~> 0.10.0)
codeclimate-test-reporter (~> 0.3.0)
coffee-rails (~> 4.0.0)
country_select
dalli (~> 2.7.0)
database_cleaner (~> 1.2.0)
dotenv-rails (~> 0.10.0)
@ -302,7 +322,7 @@ DEPENDENCIES
faraday (~> 0.9.0)
font-awesome-sass (~> 4.1.0.0)
haml (~> 4.0.5)
i18n_country_select (~> 1.1.5)
i18n_country_select
jquery-rails (~> 2.0.2)
mysql2 (~> 0.3.18)
neat (~> 1.6.0)
@ -312,6 +332,7 @@ DEPENDENCIES
poltergeist (~> 1.6.0)
protected_attributes (~> 1.1.3)
pry-byebug (~> 1.3.2)
public_suffix (~> 3.1.1)
puma (~> 2.11.1)
quiet_assets (~> 1.0.2)
rails (~> 4.1.16)

View file

@ -2,7 +2,7 @@ class TeamsController < ApplicationController
before_filter :get_team, only: [:show, :edit, :update, :destroy, :recover]
def index
@teams = Team.non_empty_teams.search(params[:search]).paginate(per_page: 80, page: params[:page]).ordered
@teams = Team.search(params[:search]).paginate(per_page: 80, page: params[:page]).ordered
end
def show
@ -15,7 +15,7 @@ class TeamsController < ApplicationController
raise AccessError unless @team.can_create? cuser
end
def replace_teamer
def replace_teamer
redirect_to_back
end

View file

@ -48,7 +48,7 @@ class Team < ActiveRecord::Base
belongs_to :founder, :class_name => "User"
has_many :active_teamers, -> { where("rank >= ?", Teamer::RANK_MEMBER) }
has_many :teamers, :dependent => :destroy
has_many :teamers, :dependent => :destroy, :counter_cache => true
has_many :leaders, -> { where("rank = ?", Teamer::RANK_LEADER) }, :class_name => "Teamer"
has_many :contesters, :dependent => :destroy
has_many :contests, -> { where("contesters.active", true) }, :through => :contesters

View file

@ -138,13 +138,8 @@ class User < ActiveRecord::Base
end
def country_s
I18nCountrySelect::Countries::COUNTRY_CODES.each do |code|
if code == country
return I18n.t(code, :scope => :countries, :default => 'missing')
end
end
country
country_object = ISO3166::Country[country]
country_object.translations[I18n.locale.to_s] || country_object.name
end
def realname
@ -211,15 +206,15 @@ class User < ActiveRecord::Base
end
def new_messages
received_personal_messages.unread_by(self) + received_team_messages.unread_by(self)
received_personal_messages.unread_by(self).union(received_team_messages.unread_by(self))
end
def received_messages
received_personal_messages + received_team_messages
received_personal_messages.union(received_team_messages)
end
def sent_messages
sent_personal_messages + sent_team_messages
sent_personal_messages.union(sent_team_messages)
end
def upcoming_matches

View file

@ -14,7 +14,7 @@
<td><%= flag team.country %></td>
<td><%= namelink team %></td>
<td><%= h team.irc if team.irc %></td>
<td><%= h team.teamers_num %></td>
<td><%= h team.teamers.count %></td>
<% if cuser and cuser.admin? %>
<td class="actions">
<%= link_to edit_team_path(team) do %>

View file

@ -22,8 +22,8 @@
<%= link_to messages_path do %>
Messages <%= icon 'envelope' %>
<% end %>
<% if c = cuser.new_messages.count > 0 %>
(<%= cuser.new_messages.count %>)
<% if c = cuser.new_messages.num > 0 %>
(<%= cuser.new_messages.num %>)
<% end %>
</li>
<li>

View file

@ -1,7 +1,7 @@
base: &db
adapter: mysql2
encoding: utf8
host: localhost
host: <%= ENV['MYSQL_HOST'] %>
database: <%= ENV['MYSQL_DATABASE'] %>
username: <%= ENV['MYSQL_USERNAME'] %>
password: <%= ENV['MYSQL_PASSWORD'] %>

View file

@ -1,25 +1,25 @@
require "dotenv"
Dotenv.load
Dotenv.load('.env.dev')
base_path = (ENV['DEPLOY_PATH'] || Dir.pwd)
current_path = "#{base_path}/current"
shared_path = "#{base_path}/shared"
stderr_path = "#{shared_path}/log/puma.stderr.log"
stdout_path = "#{shared_path}/log/puma.stdout.log"
#current_path = "#{base_path}/current"
#shared_path = "#{base_path}/shared"
stderr_path = "#{base_path}/log/puma.stderr.log"
stdout_path = "#{base_path}/log/puma.stdout.log"
tag 'ENSL'
preload_app!
daemonize true
directory current_path
pidfile "#{shared_path}/tmp/pids/puma.pid"
state_path "#{shared_path}/tmp/pids/puma.state"
daemonize false
directory base_path
pidfile "#{base_path}/tmp/pids/puma.pid"
state_path "#{base_path}/tmp/pids/puma.state"
stdout_redirect stdout_path, stderr_path
environment ENV['RACK_ENV'] || 'production'
rackup DefaultRackup
bind "unix://#{shared_path}/tmp/sockets/puma.sock"
bind "unix://#{base_path}/tmp/sockets/puma.sock"
port Integer(ENV['PUMA_PORT'] || 4000)
worker_timeout Integer(ENV['PUMA_TIMEOUT'] || 30)

View file

@ -0,0 +1,5 @@
class AddTeamersCountToTeams < ActiveRecord::Migration
def change
add_column :teams, :teamers_count, :integer
end
end

File diff suppressed because it is too large Load diff

34
docker-compose.dev.yml Normal file
View file

@ -0,0 +1,34 @@
version: "3"
services:
web:
build:
context: ./
dockerfile: Dockerfile.dev
args:
buildno: 1
volumes:
- ".:/var/www/"
ports:
- "4000:4000"
links:
- db
- memcached
# - redis
db:
command: mysqld_safe --skip-grant-tables
image: mariadb:latest
volumes:
- "./db_data:/var/lib/mysql"
- "./ext/mysql.conf.d:/etc/mysql/conf.d"
environment:
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_USERNAME
- MYSQL_PASSWORD
- MYSQL_ROOT_PASSWORD
- MYSQL_ROOT_HOST
memcached:
image: memcached:latest
#redis:
# image: redis

8
script/entry.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
cd /var/www
chown -R web:web /var/www
su -c "bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4" -s /bin/bash -l web
su -c "cd /var/www && source .env.dev && bundle exec puma -C config/puma.rb" -s /bin/bash -l web
bash