rvm リハビリ
とりあえず、rails2.3.4 な環境を作りたい。手元にあるのは以下らしい。
$ rvm list rvm rubies ruby-1.8.7-p352 [ x86_64 ] => ruby-1.9.2-p180 [ x86_64 ] $ rvm gemset list gemsets for ruby-1.9.2-p180 (found in /home/hoge/.rvm/gems/ruby-1.9.2-p180) global keydown => rails3tutorial $
ええと、1.8.7 配下で 2.3.4 が使えれば良いのだろうか。
とりあえず
$ rvm use 1.8.7
しといて
$ sudo rake gems:install
してみるとどうなるのかな。あ、gemset 作っといた方が良いのか
rvm gemset create rails2.3.4
。あと gitosis-web-admin 配下に以下な .rvmrc を作成。
rvm use ruby-1.8.7-p352@rails2.3.4
で、rake gems install してみる。と `gem install -v=2.3.4 rails` しろ、って言われましたな。ご託宣に従いコマンド実行。
$ gem install -v=2.3.4 rails Fetching: activesupport-2.3.4.gem (100%) Fetching: activerecord-2.3.4.gem (100%) Fetching: rack-1.0.1.gem (100%) Fetching: actionpack-2.3.4.gem (100%) Fetching: actionmailer-2.3.4.gem (100%) Fetching: activeresource-2.3.4.gem (100%) Fetching: rails-2.3.4.gem (100%) Successfully installed activesupport-2.3.4 Successfully installed activerecord-2.3.4 Successfully installed rack-1.0.1 Successfully installed actionpack-2.3.4 Successfully installed actionmailer-2.3.4 Successfully installed activeresource-2.3.4 Successfully installed rails-2.3.4 7 gems installed
どうも --no-ri とか --no-rdoc とか忘れるな。とりあえずこれで rake gems install できるのかどうなのか。
$ rake gems install (in /home/hoge/Documents/rails_proj/gitosis-web-admin) rake aborted! uninitialized constant ActiveSupport::Dependencies::Mutex /home/hoge/Documents/rails_proj/gitosis-web-admin/Rakefile:10 (See full trace by running task with --trace) $
gem のバージョンが微妙なのか。ココによると 1.3.7 と記述があるのでそれに沿ってみる。
$ gem update --system 1.3.7 (中略 RubyGems system software updated $
で、リトライ。
$ rake gems install (in /home/hoge/Documents/rails_proj/gitosis-web-admin) rake aborted! No such file or directory - /home/hoge/Documents/rails_proj/gitosis-web-admin/config/database.yml (See full trace by running task with --trace) $
あ、、、
これは example をそのまま流用。
$ cp config/database.example.yml config/database.yml $ rake gems install (in /home/hoge/Documents/rails_proj/gitosis-web-admin) - [ ] configatron - [ ] git I = Installed F = Frozen R = Framework (loaded before rails starts) rake aborted! Don't know how to build task 'install' (See full trace by running task with --trace) $
あ、なんかもの凄いナチュラルをぶちカマシてますorz
リトライ。
$ rake gems:install (in /home/hoge/Documents/rails_proj/gitosis-web-admin) gem install configatron Successfully installed yamler-0.1.0 Successfully installed configatron-2.8.3 2 gems installed Installing ri documentation for yamler-0.1.0... Installing ri documentation for configatron-2.8.3... Installing RDoc documentation for yamler-0.1.0... Installing RDoc documentation for configatron-2.8.3... gem install git Successfully installed git-1.2.5 1 gem installed Installing ri documentation for git-1.2.5... Installing RDoc documentation for git-1.2.5... $
やれやれ。で、以下なコマンド実行してみたら
$ rake --rules (in /home/hoge/Documents/rails_proj/gitosis-web-admin) No such file or directory - /home/hoge/Documents/rails_proj/gitosis-web-admin/config/application.yml rake aborted! no such file to load -- sqlite3 (See full trace by running task with --trace) $
これも example しか無い。とりあえず先に gitosis 入れないと駄目かな。config/application.example.yml が以下。
$ cat config/application.example.yml # Settings that are the same for each environment global: &global gitosis_admin_root: /path/to/gitosis_admin_working_copy # Absolute path to your gitosis admin working copy remote_git_repository: git@yourhost.com # Where your repositories are hosted gitosis_config: gitosis.conf # You don't need to change this gitosis_keydir: keydir # You don't need to change this # Environment specific variables. # Just override global settings as needed. development: <<: *global production: <<: *global # Use tmp files during tests test: <<: *global gitosis_admin_root: <%= RAILS_ROOT+"/tmp/" %> gitosis_config: 'gitosis.conf.test' gitosis_keydir: 'keydir.test' $
とりあえず gitosis をローカルに入れる。
$ sudo apt-get install gitosis
で、初期化を手前ミソながら_ココ_を見つつ以下。
$ sudo -H -u gitosis gitosis-init < ~/.ssh/id_rsa.pub Initialized empty Git repository in /srv/gitosis/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /srv/gitosis/repositories/gitosis-admin.git/ $
で、どこに clone しよう。あ、application.example.yml には_gitosis_admin_root_ってあるので /srv/gitosis ってことで良いのかな。や、working copy ってことなので、clone して云々なディレクトリなのか。
なので適当なディレクトリで以下。
$ cd ~/Documents $ git clone gitosis@localhost:gitosis-admin.git Initialized empty Git repository in /home/hoge/Documents/gitosis-admin/.git/ remote: Counting objects: 5, done. remote: Compressing objects: 100% (5/5), done. remote: Total 5 (delta 0), reused 5 (delta 0) Receiving objects: 100% (5/5), done. $
で、ここの絶対パスを書いてあげれば良いのか。コピーして
$ cp config/application.example.yml config/application.yml
編集 (一部のみ引用)。
global: &global gitosis_admin_root: /home/hoge/Documents/gitosis-admin # Absolute path to your gitosis admin working copy # remote_git_repository: git@yourhost.com # Where your repositories are hosted
で、rake --rules 確認。
$ rake --rules (in /home/hoge/Documents/rails_proj/gitosis-web-admin) rake aborted! no such file to load -- sqlite3 (See full trace by running task with --trace) $
あら。sqlite3 なパケジは導入済みのはずなのですがこれは一体何だろ。ちなみに導入済みなナニは以下。
$ dpkg --get-selections|grep sqlite libqt4-sql-sqlite install libsqlite0 install libsqlite3-0 install libsqlite3-dev install libsqlite3-ruby install libsqlite3-ruby1.8 install meego-sdk-libqt4-sql-sqlite install python-sqlite install python-sqlitecachec install sqlite3 install $
- dev とか -ruby なんてのも入ってるなぁ。あるいは以下。
$ dpkg --get-selections|grep ruby libruby install libruby1.8 install libsqlite3-ruby install libsqlite3-ruby1.8 install ruby install ruby1.8 install
ええと gem なのかなぁ。これで gem の導入が足らんとか言われると非常に辛いのですが。
$ gem search sqlite3 -r *** REMOTE GEMS *** activerecord-jdbcsqlite3-adapter (1.2.0, 1.0.3 java) dawanda-sqlite3 (1.3.3) dbd-sqlite3 (1.2.5) do_sqlite3 (0.10.7 ruby java x86-mingw32 x86-mswin32-60) fluent-query-sqlite3 (0.9.0) jdbc-sqlite3 (3.7.2, 3.6.14.2.056 java) rdbi-driver-sqlite3 (0.9.1) sqlite3 (1.3.4 ruby x86-mingw32 x86-mswin32-60) sqlite3-dotnet (3.7.2.1) sqlite3-ironruby (0.1.1) sqlite3-ruby (1.3.3, 1.3.2 x86-mingw32 x86-mswin32-60, 1.2.5 x86-mswin32, 1.2.3 mswin32) $
入れてみるか。
$ gem install sqlite3-ruby -r Building native extensions. This could take a while... ####################################################### Hello! The sqlite3-ruby gem has changed it's name to just sqlite3. Rather than installing `sqlite3-ruby`, you should install `sqlite3`. Please update your dependencies accordingly. Thanks from the Ruby sqlite3 team! <3 <3 <3 <3 ####################################################### Successfully installed sqlite3-1.3.4 Successfully installed sqlite3-ruby-1.3.3 2 gems installed Installing ri documentation for sqlite3-1.3.4... No definition for libversion Enclosing class/module 'mSqlite3' for class Statement not known Installing ri documentation for sqlite3-ruby-1.3.3... Installing RDoc documentation for sqlite3-1.3.4... No definition for libversion Enclosing class/module 'mSqlite3' for class Statement not known Installing RDoc documentation for sqlite3-ruby-1.3.3... $
うーん。。。
$ rake --rules (in /home/hoge/Documents/rails_proj/gitosis-web-admin) You have 3 pending migrations: 20091025074158 CreateRepositories 20091025112742 CreatePublicKeys 20091025181442 CreatePermissions Run "rake db:migrate" to update your database then try again. $
正解だったらしい。しかも環境構築は未だ完了していない模様。
$ rake db:create (in /home/hoge/Documents/rails_proj/gitosis-web-admin) db/development.sqlite3 already exists $ rake db:migrate (in /home/hoge/Documents/rails_proj/gitosis-web-admin) == CreateRepositories: migrating ============================================= -- create_table(:repositories) -> 0.0031s == CreateRepositories: migrated (0.0034s) ==================================== == CreatePublicKeys: migrating =============================================== -- create_table(:public_keys) -> 0.0039s == CreatePublicKeys: migrated (0.0042s) ====================================== == CreatePermissions: migrating ============================================== -- create_table(:permissions) -> 0.0036s -- add_index(:permissions, :repository_id) -> 0.0010s -- add_index(:permissions, :public_key_id) -> 0.0009s -- add_index(:permissions, [:repository_id, :public_key_id], {:unique=>true}) -> 0.0011s == CreatePermissions: migrated (0.0075s) ===================================== $
で、以下。
$ rake --rules (in /home/hoge/Documents/rails_proj/gitosis-web-admin) /home/hoge/.rvm/rubies/ruby-1.8.7-p352/bin/ruby -I"lib:test" "/home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/repository_test.rb" "test/unit/helpers/repositories_helper_test.rb" "test/unit/helpers/public_keys_helper_test.rb" "test/unit/public_key_test.rb" "test/unit/gitosis_admin_test.rb" "test/unit/permission_test.rb" /home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rails-2.3.4/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement Missing these required gems: shoulda factory_girl mocha You're running: ruby 1.8.7.352 at /home/hoge/.rvm/rubies/ruby-1.8.7-p352/bin/ruby rubygems 1.3.7 at /home/hoge/.rvm/gems/ruby-1.8.7-p352, /home/hoge/.rvm/gems/ruby-1.8.7-p352@global Run `rake gems:install` to install the missing gems. /home/hoge/.rvm/rubies/ruby-1.8.7-p352/bin/ruby -I"lib:test" "/home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/functional/repositories_controller_test.rb" "test/functional/public_keys_controller_test.rb" /home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rails-2.3.4/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement Missing these required gems: shoulda factory_girl mocha You're running: ruby 1.8.7.352 at /home/hoge/.rvm/rubies/ruby-1.8.7-p352/bin/ruby rubygems 1.3.7 at /home/hoge/.rvm/gems/ruby-1.8.7-p352, /home/hoge/.rvm/gems/ruby-1.8.7-p352@global Run `rake gems:install` to install the missing gems. /home/hoge/.rvm/rubies/ruby-1.8.7-p352/bin/ruby -I"lib:test" "/home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" Errors running test:units and test:functionals! $
なんか rake gems:install しろ、と言われている模様。なのですが
$ rake gems:install (in /home/hoge/Documents/rails_proj/gitosis-web-admin) $
だんまりだな。面倒なので手動で入れる? このあたり 3.x な Gemfile は明快で良いですね。
$ gem install shoulda factory_girl mocha -r Successfully installed shoulda-2.11.3 Successfully installed factory_girl-2.2.0 Successfully installed multi_json-1.0.3 Successfully installed metaclass-0.0.1 Successfully installed mocha-0.10.0 5 gems installed
で、rake --rules じゃなくて rake --tasks だった。
$ rake --tasks rake db:migrate:redo # Rollbacks the database one migration and re migrate up. rake db:migrate:reset # Resets your database using your migrations for the current environment rake db:migrate:up # Runs the "up" for a given migration VERSION. rake db:reset # Drops and recreates the database from db/schema.rb for the current environment and loads the seeds. rake db:rollback # Rolls the schema back to the previous version. rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb rake db:sessions:clear # Clear the sessions table rake db:sessions:create # Creates a sessions migration for use with ActiveRecord::SessionStore rake db:setup # Create the database, load the schema, and initialize with the seed data rake db:structure:dump # Dump the database structure to a SQL file rake db:test:clone # Recreate the test database from the current environment's database schema rake db:test:clone_structure # Recreate the test databases from the development structure rake db:test:load # Recreate the test database from the current schema.rb rake db:test:prepare # Check for pending migrations and load the test schema rake db:test:purge # Empty the test database rake db:version # Retrieves the current schema version number rake doc:app # Build the RDOC HTML Files rake doc:clobber_app # Remove rdoc products rake doc:clobber_plugins # Remove plugin documentation rake doc:clobber_rails # Remove rdoc products rake doc:guides # Generate Rails guides rake doc:plugins # Generate documentation for all installed plugins rake doc:plugins:input_css # Generate documentation for the input_css plugin rake doc:rails # Build the RDOC HTML Files rake doc:reapp # Force a rebuild of the RDOC files rake doc:rerails # Force a rebuild of the RDOC files rake gems # List the gems that this rails application depends on rake gems:build # Build any native extensions for unpacked gems rake gems:build:force # Force the build of all gems rake gems:install # Installs all required gems. rake gems:refresh_specs # Regenerate gem specifications in correct format. rake gems:unpack # Unpacks all required gems into vendor/gems. rake gems:unpack:dependencies # Unpacks all required gems and their dependencies into vendor/gems. rake gitosis:import # Imports the data from your gitosis.conf to your database rake log:clear # Truncates all *.log files in log/ to zero bytes rake middleware # Prints out your Rack middleware stack rake notes # Enumerate all annotations rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=WTFHAX rake notes:fixme # Enumerate all FIXME annotations rake notes:optimize # Enumerate all OPTIMIZE annotations rake notes:todo # Enumerate all TODO annotations rake rails:freeze:edge # Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0 rake rails:freeze:gems # Lock this application to the current gems (by unpacking them into vendor/rails) rake rails:template # Applies the template supplied by LOCATION=/path/to/template rake rails:unfreeze # Unlock this application from freeze of gems or edge and return to a fluid use of system gems rake rails:update # Update both configs, scripts and public/javascripts from Rails rake rails:update:application_controller # Rename application.rb to application_controller.rb rake rails:update:configs # Update config/boot.rb from your current rails install rake rails:update:generate_dispatchers # Generate dispatcher files in RAILS_ROOT/public rake rails:update:javascripts # Update your javascripts from your current rails install rake rails:update:scripts # Add new scripts to the application script/ directory rake routes # Print out all defined routes in match order, with names. rake secret # Generate a crytographically secure secret key. rake stats # Report code statistics (KLOCs, etc) from the application rake test # Run all unit, functional and integration tests rake test:benchmark # Run tests for benchmarkdb:test:prepare / Benchmark the performance tests rake test:functionals # Run tests for functionalsdb:test:prepare / Run the functional tests in test/functional rake test:integration # Run tests for integrationdb:test:prepare / Run the integration tests in test/integration rake test:plugins # Run tests for pluginsenvironment / Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name) rake test:profile # Run tests for profiledb:test:prepare / Profile the performance tests rake test:recent # Run tests for recentdb:test:prepare / Test recent changes rake test:uncommitted # Run tests for uncommitteddb:test:prepare / Test changes since last checkin (only Subversion and Git) rake test:units # Run tests for unitsdb:test:prepare / Run the unit tests in test/unit rake time:zones:all # Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset. rake time:zones:local # Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time rake time:zones:us # Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. rake tmp:cache:clear # Clears all files and directories in tmp/cache rake tmp:clear # Clear session, cache, and socket files from tmp/ rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids rake tmp:pids:clear # Clears all files in tmp/pids rake tmp:sessions:clear # Clears all files in tmp/sessions rake tmp:sockets:clear # Clears all files in tmp/sockets $
ようけあるある。とりあえず rake test してみましょう。
$ rake test (略 17 tests, 0 assertions, 0 failures, 26 errors /home/hoge/.rvm/rubies/ruby-1.8.7-p352/bin/ruby -I"lib:test" "/home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" Errors running test:units and test:functionals! $
あらまあ。試験の数以上にエラーがあったりするあたり、微妙杉。rake test:units に至っては異常終了しておる始末。何が悪いのかなぁ。てか、ちゃんと動くの? これ。
む
なんとなく gem で入れたナニのバージョンが微妙なのかなぁ、と類推。面倒なので script/server してブラウザでアクセスしてみたら_We're sorry, but something went wrong._とのこと。
log/development.log に以下なソレが。
Status: 500 Internal Server Error no such file to load -- openssl
うーん。どうやら rvmからrailsを利用しようとすると'no such file to load -- openssl'のエラーというエントリによるとちょっとした操作が必要らしい。
だんだん面倒になってきたのですが、もう少し頑張ってみます。
$ rvm package install openssl Fetching openssl-0.9.8n.tar.gz to /home/hoge/.rvm/archives % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 3681k 100 3681k 0 0 121k 0 0:00:30 0:00:30 --:--:-- 233k Extracting openssl-0.9.8n.tar.gz to /home/hoge/.rvm/src Configuring openssl in /home/hoge/.rvm/src/openssl-0.9.8n. Compiling openssl in /home/hoge/.rvm/src/openssl-0.9.8n. Installing openssl to /home/hoge/.rvm/usr $
なんかコンパイルとかしてる模様。rvm 便利って思ってたのだけど段々面倒臭くなってきつつあります。で、削除か。
$ rvm remove 1.8.7 Removing /home/hoge/.rvm/src/ruby-1.8.7-p352... Removing /home/hoge/.rvm/rubies/ruby-1.8.7-p352... Removing ruby-1.8.7-p352 aliases... Removing ruby-1.8.7-p352 wrappers... Removing ruby-1.8.7-p352 environments... Removing ruby-1.8.7-p352 binaries... $
何故に green なのだろう。で、再度導入。
$ rvm install 1.9.1 -C --with-openssl-dir=$HOME/.rvm/usr Installing Ruby from source to: /home/hoge/.rvm/rubies/ruby-1.8.7-p352, this may take a while depending on your cpu(s)... ruby-1.8.7-p352 - #fetching ruby-1.8.7-p352 - #downloading ruby-1.8.7-p352, this may take a while depending on your connection... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 4108k 100 4108k 0 0 555k 0 0:00:07 0:00:07 --:--:-- 856k ERROR: Error running 'bunzip2 '/home/hoge/.rvm/archives/ruby-1.8.7-p352.tar.bz2'', please read /home/hoge/.rvm/log/ruby-1.8.7-p352/extract.log ruby-1.8.7-p352 - #extracting ruby-1.8.7-p352 to /home/hoge/.rvm/src/ruby-1.8.7-p352 ruby-1.8.7-p352 - #extracted to /home/hoge/.rvm/src/ruby-1.8.7-p352 ruby-1.8.7-p352 - #configuring ruby-1.8.7-p352 - #compiling ruby-1.8.7-p352 - #installing Removing old Rubygems files... Installing rubygems dedicated to ruby-1.8.7-p352... Installing rubygems for /home/hoge/.rvm/rubies/ruby-1.8.7-p352/bin/ruby Installation of rubygems completed successfully. ruby-1.8.7-p352 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake). ruby-1.8.7-p352 - #importing default gemsets (/home/hoge/.rvm/gemsets/) Install of ruby-1.8.7-p352 - #complete $
で、リトライ。
$ ./script/server /home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) from /home/hoge/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /home/hoge/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.4/lib/active_support.rb:56 from /home/hoge/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /home/hoge/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rails-2.3.4/lib/commands/server.rb:1 from /home/hoge/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require' from /home/hoge/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require' from ./script/server:3 $
何これ、と言いつつ Google 先生に確認したら gem のバージョンが云々とか。何故か gem のバージョンが元に戻っておる。
$ gem -v 1.6.2 $
再度 1.3.7 に戻してリトライ。そうか 1.8.7 な ruby を入れなおした形になってるから gem もデフォなバージョンになってるのね。
で、リトライ。
$ ./script/server => Booting WEBrick => Rails 2.3.4 application starting on http://0.0.0.0:3000 /home/hoge/.rvm/gems/ruby-1.8.7-p352/gems/rails-2.3.4/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement => Call with -d to detach => Ctrl-C to shutdown server [2011-10-26 10:37:09] INFO WEBrick 1.3.1 [2011-10-26 10:37:09] INFO ruby 1.8.7 (2011-06-30) [x86_64-linux] [2011-10-26 10:37:14] INFO WEBrick::HTTPServer#start: pid=5664 port=3000 Processing RepositoriesController#index (for 127.0.0.1 at 2011-10-26 10:37:17) [GET] Repository Load (25.1ms) SELECT * FROM "repositories" Rendering template within layouts/application Rendering repositories/index Completed in 563ms (View: 453, DB: 25) | 200 OK [http://localhost/]
とりあえず試験は動かぬが動作はする模様。
取り組みとして中身を精査しながら 3.x に移行させて rspec な試験も書く、というのは良いかもしれんが時間があるのかどうなのか。
今はとりあえず動くソレがあれば良いので。