Rails 5.2 업데이트 시 문제점 정리

Rails 5.2 업데이트 시 문제점 정리

개인 프로젝트로 관리중인 rails web serverruby version 을 올리는 김에 같이 업데이트를 하려고 합니다.

기존 버전은 rails 5.0.3 이었고, 이번에 rails 5.2.0 으로 올리고 만난 에러들을 기록하려고 글을 씁니다.

Update

먼저 Gemfile.lock 을 지우고 과감하게 update 룰 합니다.

rm Gemfile.lock
bundle update

Gemfile 을 열어보면 rails 5.2를 확인할 수 있습니다.

업데이트가 안되었다면, 강제로 rails 만 업데이트 해줍니다.

bundle update rails -v 5.2.0

내가 만난 문제들


“Rack::Cors” String 문제

업데이트가 잘 되었으면 console 을 실행합니다.

rails c

output

$ rails c
/Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:37:in `build': undefined method `new' for "Rack::Cors":String
Did you mean?  next (NoMethodError)
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `block in build'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `inject'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/stack.rb:101:in `build'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:510:in `block in app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:506:in `synchronize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:506:in `app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `instance_exec'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `call'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:60:in `run_initializers'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application.rb:361:in `initialize!'
    from /Users/ktg/privates/my_projects/config/environment.rb:5:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from -e:1:in `<main>'

위의 에러가 났습니다.

이 에러는 application.rb 내부의 Rack::Cors 문제입니다. 아래 링크에 해결책이 자세히 나와있습니다.

ruby – Error when running Rails application – Stack Overflow

raise_in_transactional_callbacks 문제

/Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/railtie.rb:124:in `block (3 levels) in <class:Railtie>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/railtie.rb:123:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/railtie.rb:123:in `block (2 levels) in <class:Railtie>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `instance_eval'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/base.rb:328:in `<module:ActiveRecord>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/base.rb:27:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:247:in `block in load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:653:in `new_constants_in'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:247:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/privates/my_projects/app/models/application_record.rb:1:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `block in load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:653:in `new_constants_in'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:467:in `load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:365:in `block in require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `block in load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:13:in `loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:348:in `require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:193:in `const_missing'
    from /Users/ktg/privates/my_projects/app/models/user.rb:1:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:468:in `block in load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:653:in `new_constants_in'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:467:in `load_file'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:365:in `block in require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `block in load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies/interlock.rb:13:in `loading'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:37:in `load_interlock'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:348:in `require_or_load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:193:in `const_missing'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:283:in `const_get'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:283:in `block in constantize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:281:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:281:in `inject'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/inflector/methods.rb:281:in `constantize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:574:in `get'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:605:in `constantize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise.rb:316:in `get'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:83:in `to'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:78:in `modules'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:95:in `routes'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:162:in `default_used_route'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/mapping.rb:72:in `initialize'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise.rb:346:in `new'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise.rb:346:in `add_mapping'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:243:in `block in devise_for'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:242:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/devise-4.4.3/lib/devise/rails/routes.rb:242:in `devise_for'
    from /Users/ktg/privates/my_projects/config/routes.rb:8:in `block in <top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:414:in `draw'
    from /Users/ktg/privates/my_projects/config/routes.rb:1:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `block in load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:277:in `load'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:57:in `block in load_paths'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:57:in `each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:57:in `load_paths'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:20:in `reload!'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:43:in `block in updater'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/file_update_checker.rb:83:in `execute'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:44:in `updater'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/routes_reloader.rb:33:in `execute_if_updated'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application/finisher.rb:130:in `block in <module:Finisher>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `instance_exec'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `call'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/initializable.rb:60:in `run_initializers'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/application.rb:361:in `initialize!'
    from /Users/ktg/privates/my_projects/config/environment.rb:5:in `<top (required)>'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from /Users/ktg/.rvm/rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from -e:1:in `<main>'

application.rb에 있는 하단 내용을 삭제 합니다.

config.active_record.raise_in_transactional_callbacks = true

하단 내용 참고

https://stackoverflow.com/questions/37464966/what-causes-deprecation-warning-activerecordbase-raise-in-transactional-callb

Coffeescript Error

이제 레일즈 서버를 실행하고 접속해봅니다.

$ rails s
$ curl localhost:3000

Output

=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
[32087] Puma starting in cluster mode...
[32087] * Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
[32087] * Min threads: 5, max threads: 5
[32087] * Environment: development
[32087] * Process workers: 2
[32087] * Preloading application
[32087] * Listening on tcp://0.0.0.0:3000
[32087] Use Ctrl-C to stop
[32087] - Worker 0 (pid: 32090) booted, phase: 0
[32087] - Worker 1 (pid: 32091) booted, phase: 0
Started GET "/" for 127.0.0.1 at 2018-05-29 23:37:10 +0900
   (0.4ms)  SET  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
   (0.3ms)  SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
Processing by MainController#index as HTML
Completed 401 Unauthorized in 14ms (ActiveRecord: 0.0ms)


Started GET "/login" for 127.0.0.1 at 2018-05-29 23:37:10 +0900
Processing by Devise::SessionsController#new as HTML
  Rendering devise/sessions/new.html.erb within layouts/application
  Rendered devise/shared/_links.html.erb (1.0ms)
  Rendered devise/sessions/new.html.erb within layouts/application (16.6ms)
Completed 500 Internal Server Error in 6804ms (ActiveRecord: 1.4ms)



LoadError (cannot load such file -- coffee_script):

app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___3099409563303512009_70257788966240'

NameError: uninitialized constant Mime::HTML
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:58:in `acceptable_content_type?'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:36:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:38:in `call_app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `block in tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:28:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/request_id.rb:27:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:127:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:524:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/configuration.rb:225:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:632:in `handle_request'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:446:in `process_client'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:306:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Started GET "/assets/css/main.min.css" for 127.0.0.1 at 2018-05-29 23:37:18 +0900

ActionController::RoutingError (No route matches [GET] "/assets/css/main.min.css"):

actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
rack-cors (1.0.2) lib/rack/cors.rb:97:in `call'
railties (5.2.0) lib/rails/engine.rb:524:in `call'
puma (3.11.4) lib/puma/configuration.rb:225:in `call'
puma (3.11.4) lib/puma/server.rb:632:in `handle_request'
puma (3.11.4) lib/puma/server.rb:446:in `process_client'
puma (3.11.4) lib/puma/server.rb:306:in `block in run'
puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'

NameError: uninitialized constant Mime::HTML
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:58:in `acceptable_content_type?'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:36:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:38:in `call_app'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `block in call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `block in tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:28:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in `tagged'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/request_id.rb:27:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/activesupport-5.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:127:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/railties-5.2.0/lib/rails/engine.rb:524:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/configuration.rb:225:in `call'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:632:in `handle_request'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:446:in `process_client'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/server.rb:306:in `block in run'
    from /Users/ktg/.rvm/gems/ruby-2.5.1/gems/puma-3.11.4/lib/puma/thread_pool.rb:120:in `block in spawn_thread'

엄청나게 긴 에러를 만납니다.
원인을 찾아보니, 원인은 단순합니다.
사용하지 않는 coffeescript 파일들이 프로젝트에 존재하고 있었습니다.

아래 명령으로 확인후 삭제 해줍니다.

$ find . -name "*.coffee"

그러고도 에러가 난다면 **cache*** 문제입니다.

cache 를 삭제해줍니다.

$ rake tmp:cache:clear

관련 내용은 여기서 확인 가능합니다.

web-console 문제

위의 에러에서

NameError: uninitialized constant Mime::HTML
이런 에러가 있는데 이건 web-console 버전 문제였습니다..

web-console을 업데이트 해줍니다.

$ bundle update web-console

다시 실행합니다.

결론


여기까지 제가 해결한 문제였습니다.

Kubernetes on AWS + kops

Kubernetes on AWS + kops

Prerequisite

  • kops 1.9.0
  • kubectl client v1.10.1, server v1.9.3

설치

아래 링크대로 따라서 설치
Following this ref

그리고 어김없이 찾아오는 에러…

Error

kops 로 클러스터 구성(after executing, kops update cluster —yes $NAME) 후에 아래와 같은 output 을 볼수 있습니다.

...

Suggestions:
 * validate cluster: kops validate cluster
 * list nodes: kubectl get nodes --show-labels
 * ssh to the master: ssh -i ~/.ssh/id_rsa admin@api.useast1.k8s.example.com
 * the admin user is specific to Debian. If not using Debian please use the appropriate user based on your OS.
 * read about installing addons at: https://github.com/kubernetes/kops/blob/master/docs/addons.md.

아래 명령을 실행합니다.

kops validate cluster

Output:

tkwon-macbook:~/projects/k8s ktg$ kops validate cluster
Using cluster from kubectl context: useast1.k8s.example.com

Validating cluster useast1.k8s.example.com

INSTANCE GROUPS
NAME            ROLE    MACHINETYPE MIN MAX SUBNETS
master-us-east-1a   Master  m5.large    1   1   us-east-1a
nodes           Node    c5.large    2   2   us-east-1a

NODE STATUS
NAME    ROLE    READY

VALIDATION ERRORS
KIND    NAME        MESSAGE
dns apiserver   Validation Failed

The dns-controller Kubernetes deployment has not updated the Kubernetes cluster's API DNS entry to the correct IP address.  The API DNS IP address is the placeholder address that kops creates: 203.0.113.123.  Please wait about 5-10 minutes for a master to start, dns-controller to launch, and DNS to propagate.  The protokube container and dns-controller deployment logs may contain more diagnostic information.  Etcd and the API DNS entries must be updated for a kops Kubernetes cluster to start.

Validation Failed

뭔지 모르겠지만 실패했습니다.
ssh로 master node 에 접속 시도 해봅니다.

ssh -i ~/.ssh/id_rsa admin@api.useast1.k8s.example.com

ssh 접속이 되지 않았습니다. ..

route53에서 확인해보니 도매인의 ip가 master node ip로 변경되어 있지 않았습니다.

Ec2 dashboard 를 확인하니 정상적으로 instance가 실행중입니다.

ip로 ssh 접속 시도합니다.

ssh -i ~/.ssh/id_rsa admin@1.1.1.1

정상적으로 접속됩니다.

sudo docker ps

Output:

protokube                                          1.9.0

protokube 라는 이미지가 실행중입니다.
docker log 를 확인해보니 아래와 같은 에러로그가 반복되고 있습니다.

...
Mar 30 22:30:38 ip-172-31-1-13 docker[1546]: I0330 22:30:38.659365    1576 aws_volume.go:318] nvme path not found "/rootfs/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0f1a04a36c6baaaae"
Mar 30 22:30:38 ip-172-31-1-13 docker[1546]: I0330 22:30:38.659373    1576 volume_mounter.go:107] Waiting for volume "vol-0f1a04a36c6baaaae" to be attached
Mar 30 22:30:39 ip-172-31-1-13 docker[1546]: I0330 22:30:39.659499    1576 aws_volume.go:318] nvme path not found "/rootfs/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0f1a04a36c6baaaae"
Mar 30 22:30:39 ip-172-31-1-13 docker[1546]: I0330 22:30:39.659519    1576 volume_mounter.go:107] Waiting for volume "vol-0f1a04a36c6baaaae" to be attached
Mar 30 22:30:40 ip-172-31-1-13 docker[1546]: I0330 22:30:40.659641    1576 aws_volume.go:318] nvme path not found "/rootfs/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_vol0f1a04a36c6baaaae"
Mar 30 22:30:40 ip-172-31-1-13 docker[1546]: I0330 22:30:40.659660    1576 volume_mounter.go:107] Waiting for volume "vol-0f1a04a36c6baaaae" to be attached
...

검색해보니,
Cluster hung up starting, waiting for etcd volumes to attach · Issue #4844 · kubernetes/kops · GitHub

위의 링크에 원인이 나와있었습니다.
thumb up 한번 눌러드리고 수정합니다.

$ kops edit ig master-us-east-1a
$ kops edit ig nodes

위 명령을 실행해서 instance type m5, c5 에서 m4, c4로 바꿉니다.

kops rolling-update cluster --cloudonly --yes

실행하고… 기다립니다.

kops validate cluster

Output:

tkwon-macbook:~/projects/k8s ktg$ kops validate cluster
Using cluster from kubectl context: useast1.k8s.example.com

Validating cluster useast1.k8s.example.com

INSTANCE GROUPS
NAME            ROLE    MACHINETYPE MIN MAX SUBNETS
master-us-east-1a   Master  m4.large    1   1   us-east-1a
nodes           Node    c4.large    2   2   us-east-1a

NODE STATUS
NAME                ROLE    READY
ip-10-110-42-179.ec2.internal   node    True
ip-10-110-45-25.ec2.internal    master  True
ip-10-110-47-243.ec2.internal   node    True

Your cluster useast1.k8s.example.com is ready

이제 kubernetes cluster 를 사용할 수 있습니다!

Font awesome 아이콘 정렬 문제

Font awesome 아이콘 정렬 문제

상황

현재 Bootstrap 4 를 사용해서 프로젝트를 진행 중입니다.
bootstrap 4는 버전이 beta 상태로 있지만 어차피 나중엔 쓸테니까 처음으로 시작하는 프로젝트는 모두 bootstrap 4 로 작성 중 입니다.

Bootstrap 4 에는 기존에 있던 Glyphicons 가 사라졌습니다.

링크 참조 Migrating to v4 · Bootstrap

그래서 기존 Glyphicons 를 사용하지 않고 아이콘 버튼을 만들기 위해 font awesome 을 사용하게 되었습니다.

GitHub – Justineo/vue-awesome: Awesome SVG icon component for Vue.js, built-in with Font Awesome icons.

설치하면 font-awesome 이 내장되어 있습니다.

글 작성일 현재 README 문구를 보면 버전을 확인 할 수 있습니다.

Vue-Awesome is built upon Font Awesome v4.5.0 and depends on Vue.js v2.0.1+.

문제점

Vue-awesome code using Pug

icon(name='archive')
span Zones

Font-awesome 에 있는 아이콘과 link를 생성해보면 아래 이미지와 같은 align 관련 문제점을 확인 할 수 있습니다.

http://blog.uniqbuild.co.kr/wp-content/uploads/2017/09/picture-bootstrap-noalign.png

해결

Icon inside bootstrap button · Issue #52 · Justineo/vue-awesome · GitHub
여기에서 보이는 것처럼 css 를 추가해 줍니다.

저는 .btn class 는 사용하지 않으므로 제외 했습니다.

.fa-icon {
    vertical-align: middle;
    margin-right: 0.5rem;
}

입력 후, 화면을 확인하시면 아래와 같이 아이콘이 정렬된 모습을 확인 할 수 있습니다.

http://blog.uniqbuild.co.kr/wp-content/uploads/2017/09/picture-bootstrap-align.png

Rails 5 lib folder 로딩이 안되는 문제

Rails 5 ‘lib’ folder autoload failure

Rails 5 에서 lib 폴더를 autoload path에 포함시키고 싶은데 아래 코드가 제대로 동작을 하지 않았습니다.

config.autoload_paths << Rails.root.join('lib')

첫 번째 방법

찾아보니 스택오버플로우에 아래와 같은 정보가 있습니다.

autoload – Rails 5: Load lib files in production – Stack Overflow

코드를 보면 initializer를 이용해서 rb 파일들을 읽어오도록 구현되어 있습니다.

이런식으로 원하는 코드들만 가져와도 될 듯합니다. 스타도 많이 받았습니다. ㅎㅎㅎㅎ

두번째 방법

Rails falls back on non-thread-safe autoloading even when eager_load is true · Issue #13142 · rails/rails · GitHub

위의 글을 보면 이 아저씨가 해결한 방법은 autoload 를 사용하지 않고 eager_load 를 사용하라고 합니다.

config/environments/production.rb 의 내용을 봅니다.

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

eager_load 가 기본 설정입니다.

config/application.rb 하단에 아래 내용을 추가합니다.

config.eager_load_paths << Rails.root.join('lib')

문제 없이 잘 동작합니다.

iwinv(가상호스팅)에 docker 적용하기

iwinv(가상호스팅)에 docker 적용하기

iwinv 제가 호스팅을 이전했다는 사실은 지난 글에서 이미 언급한 적이 있습니다.

오늘은 iwinv 로 이전하면서 엄청난 고생을 했던 경험에 대한 이야기 및 해결책에 대한 이야기를 적어 보려 합니다.

Environment

  • Ubuntu 16.04 xenial

삽질의 시작

IwinV Manual

iwinv 홈페이지를 가면 이렇게 도커 적용을 하는 것에 대한 매뉴얼이 있습니다만…

가격의 매리트와 docker 적용에 대한 호기심으로 시작한 이 작업이 이렇게 크나큰 고통을 안겨 줄 것이라는 것을 이 때는 몰랐습니다.

사실 저 메뉴얼이 있는걸 확인 하고 docker 적용에 별 어려움이 없을 것이라고 판단했던 것이 제가 서버 이전을 마음 먹은 것에 큰 이유 중 하나이기도 합니다.
물론 iwinv의 메뉴얼은 저를 속였습니다. (물론 회사가 의도친 않았지만…)ㅎㅎㅎ

이유인 즉, 저 매뉴얼은 반 쪽짜리 매뉴얼 이었기 때문입니다.

물론 간단히 하나의 도커파일만으로 사용할 경우는 별 문제가 없을 지도 모르겠습니다만,
도커 이미지간에 네트웍 통신에는 치명적 문제가 있었습니다.

MTU

위의 매뉴얼 링크를 클릭해보시면 아시겠지만, iwinv는 내부적으로 MTU1450으로 사용하고 있다고 합니다. 이리하여 도커의 MTU 설정을 변경해줘야 한다는 것이 저 글의 요지입니다.

자, 그럼 MTU가 무엇이냐하면,

컴퓨터 네트워킹에서, 레이어의 커뮤니케이션 프로토콜의 최대 전송 단위(maximum transmission unit, MTU)란 해당 레이어가 전송할 수 있는 최대 프로토콜 데이터 단위의 크기(바이트)이다.

최대 전송 단위 – 위키백과, 우리 모두의 백과사전

간단히 말해 네트워크 통신에서의 패킷 사이즈를 결정하는 단위라고 생각하면 될 듯 합니다.

이때는 “아 패킷 사이즈를 iwinv가 적게 쓰는 구나.” 하고 넘어갔습니다.

Docker 설치

매뉴얼대로 도커를 설치합니다.
물론 이 포스팅에서는 매뉴얼과 docker 홈페이지를 적절히 이용해서 설치하겠습니다.
현 시점에서의 설치방법입니다. (2017.6)

먼저 apt-get 업데이트를 합니다.

$ sudo apt-get update
$ sudo apt-get upgrade

도커 설치는 공식페이지를 참고합니다.

오래된 버전의 docker 가 있다면 지웁니다.

$ sudo apt-get remove docker docker-engine

docker 설치에 필요한 패키지를 설치합니다.

$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common

docker 의 공식 GPG key를 추가합니다.

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

키를 확인합니다.
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88

$ sudo apt-key fingerprint 0EBFCD88

pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22

amd64 architecture 를 사용하는 docker 를 설치하겠습니다.

$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

Docker 가 설치가 잘 되었는지 확인

$ sudo docker run hello-world

...
Hello from Docker!
This message shows that your installation appears to be working correctly.

여기서부터 iwinv의 메뉴얼을 따릅니다.

$ sudo docker pull ubuntu
$ sudo docker run -it ubuntu

※ update가 진행이 안되는 문제 발생하며 ftp 등 일부 서비스에서 문제 발생.

위 증상은 MTU 때문입니다.
이제 MTU를 1450으로 세팅합니다.

$ cp /lib/systemd/system/docker.service /etc/systemd/system/docker.service
$ vi /etc/systemd/system/docker.service

/etc/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket firewalld.service
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --mtu=1450
#-H fd://
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

ExecStart=/usr/bin/dockerd -H fd:// —mtu=1450

이렇게 변경 후에 아래 명령 실행합니다.

$ sudo systemctl daemon-reload
$ sudo service docker restart

이제 이 전의 명령을 다시 실행해봅니다.

$ sudo docker run -it ubuntu

진행이 정상적으로 되는 것을 확인 할 수 있습니다.

Docker compose

여기까지 설치했다면 iwinv의 메뉴얼 대로 잘 설치된 상황입니다.

허나 함정이 있습니다.
바로 docker-compose를 사용하게 될 때의 문제인데요.

먼저 docker-compose를 알아봅시다.

docker compose 란 간단히 말해서 docker application을 이용한 서비스 환경 구축을 손쉽게 도와주는 tool 이라고 생각하시면 됩니다.

일반적으로 web service 구축을 위해선 web application 과 database 가 필요할 것입니다.
docker compose 는 이 둘을 한번에 구성하기 위한 툴로 보시면 됩니다.

설치방법은 아래 링크를 참고하세요.
docker-compose 설치

docker compose를 설치하고 docker-compose.yml 파일을 작성 후 docker로 서비스를 구축합니다. 여기서는 wordpress 를 구축했습니다.

docker-wordpress-nginx/docker-compose.yml at master · 9to6/docker-wordpress-nginx · GitHub

깃허브 소스를 참고하시면 됩니다.

docker-compose.yml

version: "3.2"
services:
web:
build: .
ports:
- "80:80"
volumes:
- wordpress:/var/www/html
depends_on:
- php
php:
image: wordpress:4.8-php7.1-fpm-alpine
depends_on:
- db
restart: always
ports:
- "9000:9000"
volumes:
- wordpress:/var/www/html
db:
image: mariadb:10.2.6
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- "3306:3306"

docker compose의 파일을 보면 wordpressmariadb 와 함께 설치해서 wordpress web service 를 구성하게 됩니다.

이제 wordpress 설치를 시작하게 되고 첫 화면이 뜨고 난뒤, plugin 이나 theme 를 추가하기 위해 들어가보면 목록이 나오지 않습니다.
에러가 났다고 나오고, (wp-setting.php ?? 기억이 명확하지 않네요..)의 어떤 부분에서 에러가 났다고 합니다.
이제부터 문제 해결 과정입니다.

docker compose 문제 해결 과정

extra_hosts 추가

위의 에러난 부분을 찾아가서 php 소스를 수정, echo 로 확인해봤습니다.
wordpress 내부에서 https 를 이용 api.wordpress.org 에 request 를 보내는 부분에서 계속 에러가 납니다.

구글링을 해봤더니, wordpress docker 내부에서 api.wordpress.org 의 도메인을 lookup을 못해서 일 것이라는 글을 보고 host를 추가해봤는데,

php:
image: wordpress:4.8-php7.1-fpm-alpine
depends_on:
- db
restart: always
ports:
- "9000:9000"
volumes:
- wordpress:/var/www/html
extra_hosts:
- "api.wordpress.org:66.155.40.202"

같은 증상이었습니다…

iptables 추가

전혀 해결이 되지 않아서 또다른 방법을 찾던 중 나온 방법이 iptables를 수정하는 것이 었습니다.
현재 상황이 패킷이 나가지 않는 문제라고 판단했을 때, iptables 를 이용해서 해결 할 수 있을 것이라고 판단하고 적용해봤습니다.

docker 1.10, 1.11 do not infer MTU from eth0; docker 1.9 does · Issue #22028 · moby/moby · GitHub

좋아요도 두개나 받은 내용으로 적용을 해봤는데…

실행이 되었습니다.

이렇게 해결되었다는 기쁨(?)을 느끼고 이제 마무리를 지었는데…

또다른 문제. 다시 원점으로…

제가 모바일 어플의 서버로 사용하던 rails application을 또다른 docker 파일로 실행했는데, 메일이 나가지 않는 문제를 확인했습니다. 이 rails 앱은 smtp 를 사용해서 메일을 보내는 기능이 있었는데 메일이 나가지 않아서 ruby library 파일을 직접 수정하면서 디버깅을 시작했습니다.

문제는 smtp 를 보내는 부분에서 났기 때문에 네트워크 문제로 판단, 결국 다시 원점으로 돌아갔습니다. ㅠㅠ

이렇게 또다시 하루정도 iptables 룰 도 바꿔보고 구글링도 해보고 이것저것 해보게 되었습니다.

이때쯤 iwinv 서비스 이용을 포기할 생각을 잠시 하게 되었습니다…만, 심기일전 하고 다시 구글링.

결국 찾은 해결책과 원인

마침내 찾은 해결책.
containers in docker 1.11 does not get same MTU as host · Issue #22297 · moby/moby · GitHub

docker network 를 구성할 때 mtu 설정을 별도로 해줘야한다는 것이 었습니다.

이제 뭔가 이해되는 느낌…
docker compose 로 docker application을 실행하게 되면,
docker 엔진이 별도의 sub network 를 구성하게 되고, wordpress web app 과 mariadb는 sub network 안에서 통신을 하게 됩니다.
이 때 mtu 사이즈가 1450 이상이었기 때문에 문제가 발생했던 것입니다.

해결을 위해서는
1. 첫번째로, docker-compose 안에 이렇게 network 구성을 해주는 방법이나,

networks:
default:
driver: bridge
driver_opts:
com.docker.network.driver.mtu: 1450
  1. 두번째로는, 미리 생성된 network를 이용하는 방법입니다.
$ suod docker network create -o "com.docker.network.driver.mtu"="1450"
networks:
default:
external:
name:

이 해결책을 찾아보고 다시 두번째 해결책이었던 iptables의 명령어에 대해 찾아봤는데,

TCPMSS target

Under normal circumstances, this means the size of the MTU (Maximum Transfer Unit) value, minus 40 bytes.

정상적 상황에서 MTU 사이즈에서 40바이트를 빼주는 것이라고 하네요.
아마 이래서 잘 작동했었나 봅니다. SMTP 의 패킷은 40을 빼줘도 더 1450보다 더 패킷 사이즈가 컸나 봅니다.

하지만 보다 정확한 해결책은 MTU사이즈 수정입니다.

이제 다시 SMTP 로 메일을 보내봅니다. 정상적으로 동작합니다.

결론

  • iwinvdocker 를 사용은 비추
  •  그러나 이 글을 읽어봤다면 추천;;;
  • docker 를 사용하지 않으면 손쉽게 사용가능 하니 좋은 서비스 저렴하게 사용 가능
  • docker 사용을 하시겠다면 매뉴얼의 MTU 설정과 별도 docker networkMTU 설정도 유념해야 함

ubuntu 14.04(trusty)에 docker install

Ubuntu 우분투 14.04 docker 설치

$ sudo apt-get update
$ sudo apt-get install -y docker-engine

을 하면 에러가 나고 아래와 같은 메시지를 만나게 됩니다.

Reading package lists... Done
Building dependency tree
Reading state information... Done
docker-engine is already the newest version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
docker-engine : Depends: libsystemd-journal0 (>= 201) but it is not going to be installed
Recommends: aufs-tools but it is not going to be installed
Recommends: cgroupfs-mount but it is not installable or
cgroup-lite but it is not going to be installed
Recommends: git but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

보면 dockerlibsystemd-journal0에 의존성이 걸려있어서 그런데요.
설치가 안되는 이유는 잘 모르겠으나, 그냥 수동으로 설치해줬습니다.

파일을 찾아보다가 나중에 또 이런일이 생길 듯하여 기록에 남겨둡니다.

$ wget http://kr.archive.ubuntu.com/ubuntu/pool/main/s/systemd/libsystemd-journal0_204-5ubuntu20_amd64.deb

위 명령으로 *.deb 파일을 다운로드 받은 뒤에 수동 설치합니다.

$ sudo dpkg -I libsystemd-journal0_204-5ubuntu20_amd64.deb

설치 후 다시 docker install 을 시도합니다.

$ sudo apt-get install -y docker-engine

정상 설치가 되었습니다.

Reading package lists... Done
Building dependency tree
Reading state information... Done
docker-engine is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 29 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up docker-engine (17.05.0~ce~rc3-0~ubuntu-trusty) ...
docker start/running, process 3434
Processing triggers for ureadahead (0.100.0-16) ...

설치가 잘 되었는지 확인합니다.

$ docker

정상 설치되었다면 usage가 나옵니다.

잘 설치되었다면 이제 docker를 잘 이용하시면 됩니다.

Error occurs when start an instance AWS OpsWorks

Error occurs when start an instance AWS OpsWorks

When I start a new instance on OpsWorks Layers, I faced this error.

================================================================================
Recipe Compile Error in /var/lib/aws/opsworks/cache.stage2/cookbooks/aws/resources/cloudwatch.rb
================================================================================

NoMethodError
-------------
undefined method `property' for #&lt;Class:0x007f511b6ee538&gt;

Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/aws/resources/cloudwatch.rb:1:in `class_from_file'

Relevant File Content:
----------------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/aws/resources/cloudwatch.rb:

1&gt;&gt; property :alarm_name, String, name_property: true
2: property :alarm_description, String
3: property :actions_enabled, TrueClass
4: property :ok_actions, Array, default: []
5: property :alarm_actions, Array, default: []
6: property :insufficient_data_actions, Array, default: []
7: property :metric_name, String
8: property :namespace, String
9: property :statistic, equal_to: %w(SampleCount Average Sum Minimum Maximum)
10: property :extended_statistic, String

I got a panic….
Because it certainly worked fine when I start an instance before a couple of hours…

I had found a solution.
Finally I found it.

That’s why AWS cookbook updated.

My OpsWorks system used chef11.
When AWS cookbook updated 6.1.0, it has used new method, property.

I specified a version of AWS cookbook on my Berkshelf

Finally it works well.

android GCM Error…

안드로이드 개발시 이런 애러가 나올 경우가 있다.

원인을 찾지 못해서  gcm.jar이 deprecated가 되었다고 해서 모두 google cloud messaging  라이브러리를 사용했는데 해당 에러가 동일하게 발생했다.

06-12 14:44:43.553: E/BroadcastReceiver(27011): java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:783)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.content.BroadcastReceiver.setResultCode(BroadcastReceiver.java:549)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at com.kamsung.anvang.gcm.GcmBroadcastReceiver.onReceive(GcmBroadcastReceiver.java:30)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:2535)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.app.ActivityThread.access$1600(ActivityThread.java:165)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.os.Looper.loop(Looper.java:176)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at android.app.ActivityThread.main(ActivityThread.java:5455)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at java.lang.reflect.Method.invokeNative(Native Method)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at java.lang.reflect.Method.invoke(Method.java:525)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
06-12 14:44:43.553: E/BroadcastReceiver(27011): 	at dalvik.system.NativeStart.main(Native Method)

원인은 삼성 런처를 위한 코드를 넣었을  때 발생했다.

아래와 같은 코드를 사용했을 경우.

Intent badgeIntent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
badgeIntent.putExtra("badge_count", notiCnt);
badgeIntent.putExtra("badge_count_package_name", context.getPackageName());
badgeIntent.putExtra("badge_count_class_name", getLauncherClassName(context));
context.sendBroadcast(badgeIntent);

위의 코드로 뱃지를 업데이트 했을 경우 broadcast 한 인텐트를 지금 개발하는 앱에서 받아서 문제가 생긴다.

 

이럴때는 해당 인텐트를 예외처리 해서 처리할 수 있다.

아래 코드는 필자가 사용한 코드다.

참고 해서 인텐트를 확인해보자.

인텐트의 key 와 value 는 다를 수 있으니 한번 찍어서 확인해보자

내가 원하는 인텐트가 아닐 경우를 찾아내서 예외처리를 해준다면 에러가 나지 않을 것이다.

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    // registration_id가 있는 경우만 receive 한다.
    boolean foundexceptionKey = false;
    for (String key : bundle.keySet()) {
	Object value = bundle.get(key);
	if (key.equals("CMD") && value.toString().equals("RST_FULL")) foundexceptionKey = true;
    }
    if (foundexceptionKey) return; 
    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(),
    GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, intent.setComponent(comp));
    setResultCode(Activity.RESULT_OK);
}

 

ruby rbenv install 2.0.0-p247 fail for Centos

rbenv 를 이용해서 ruby 2.0.0 p247을 설치할 때 에러가 발생한다. centos 6.5에서 발생했다.

해결법을 기록해둔다. 참고가 되길 바란다.

ref web site

rbenv install 2.0.0-p247

위의 명령을 실행했을 때 아래 상황 발생

problem:

BUILD FAILED

Inspect or clean up the working tree at /tmp/ruby-build.20150424111036.5089
Results logged to /tmp/ruby-build.20150424111036.5089.log

Last 10 log lines:
ossl_pkey_ec.c:821: error: for each function it appears in.)
make[2]: *** [ossl_pkey_ec.o] Error 1
make[2]: Leaving directory `/tmp/ruby-build.20150424111036.5089/ruby-2.0.0-p247/ext/openssl'
make[1]: *** [ext/openssl/all] Error 2
make[1]: *** Waiting for unfinished jobs....
installing default callback libraries
linking shared-object dl/callback.so
make[2]: Leaving directory `/tmp/ruby-build.20150424111036.5089/ruby-2.0.0-p247/ext/dl/callback'
make[1]: Leaving directory `/tmp/ruby-build.20150424111036.5089/ruby-2.0.0-p247'
make: *** [build-ext] Error 2

solution:

1. Create “patch.diff” file.
2. Copy the content below.

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41807)
+++ ChangeLog	(revision 41808)
@@ -1,3 +1,16 @@
+Sat Jul  6 07:37:43 2013  Martin Bosslet  <Martin.Bosslet@gmail.com>
+
+	* ext/openssl/ossl_pkey_ec.c: Ensure compatibility to builds of
+	  OpenSSL with OPENSSL_NO_EC2M defined, but OPENSSL_NO_EC not
+	  defined.
+	* test/openssl/test_pkey_ec.rb: Iterate over built-in curves
+	  (and assert their non-emptiness!) instead of hard-coding them, as
+	  this may cause problems with respect to the different availability
+	  of individual curves in individual OpenSSL builds.
+	  [ruby-core:54881] [Bug #8384]
+
+	  Thanks to Vit Ondruch for providing the patch!
+
 Sat Jul  6 07:12:39 2013  Martin Bosslet  <Martin.Bosslet@gmail.com>
 
 	* test/openssl/test_x509crl.rb: Remove unused variable.
Index: ext/openssl/ossl_pkey_ec.c
===================================================================
--- ext/openssl/ossl_pkey_ec.c	(revision 41807)
+++ ext/openssl/ossl_pkey_ec.c	(revision 41808)
@@ -762,8 +762,10 @@
                 method = EC_GFp_mont_method();
             } else if (id == s_GFp_nist) {
                 method = EC_GFp_nist_method();
+#if !defined(OPENSSL_NO_EC2M)
             } else if (id == s_GF2m_simple) {
                 method = EC_GF2m_simple_method();
+#endif
             }
 
             if (method) {
@@ -817,8 +819,10 @@
 
             if (id == s_GFp) {
                 new_curve = EC_GROUP_new_curve_GFp;
+#if !defined(OPENSSL_NO_EC2M)
             } else if (id == s_GF2m) {
                 new_curve = EC_GROUP_new_curve_GF2m;
+#endif
             } else {
                 ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
             }
Index: test/openssl/test_pkey_ec.rb
===================================================================
--- test/openssl/test_pkey_ec.rb	(revision 41807)
+++ test/openssl/test_pkey_ec.rb	(revision 41808)
@@ -7,28 +7,28 @@
     @data1 = 'foo'
     @data2 = 'bar' * 1000 # data too long for DSA sig
 
-    @group1 = OpenSSL::PKey::EC::Group.new('secp112r1')
-    @group2 = OpenSSL::PKey::EC::Group.new('sect163k1')
-    @group3 = OpenSSL::PKey::EC::Group.new('prime256v1')
+    @groups = []
+    @keys = []
 
-    @key1 = OpenSSL::PKey::EC.new
-    @key1.group = @group1
-    @key1.generate_key
+    OpenSSL::PKey::EC.builtin_curves.each do |curve, comment|
+      group = OpenSSL::PKey::EC::Group.new(curve)
 
-    @key2 = OpenSSL::PKey::EC.new(@group2.curve_name)
-    @key2.generate_key
+      key = OpenSSL::PKey::EC.new(group)
+      key.generate_key
 
-    @key3 = OpenSSL::PKey::EC.new(@group3)
-    @key3.generate_key
-
-    @groups = [@group1, @group2, @group3]
-    @keys = [@key1, @key2, @key3]
+      @groups << group
+      @keys << key
+    end
   end
 
   def compare_keys(k1, k2)
     assert_equal(k1.to_pem, k2.to_pem)
   end
 
+  def test_builtin_curves
+    assert(!OpenSSL::PKey::EC.builtin_curves.empty?)
+  end
+
   def test_curve_names
     @groups.each_with_index do |group, idx|
       key = @keys[idx]

3. Create “fedora.configure” file
4. Copy the content below.

#!/bin/sh
patch -p0 -i /tmp/patch.diff
exec ./configure "$@"

5. Execute this command.

RUBY_CONFIGURE=/home/user/fedora-configure rbenv install 2.0.0-p247

6. check ruby version.

rbenv versions