メインコンテンツへスキップ
見出し画像

ItamaeがサポートするRubyのversionについて

    先日開催されたOSSパッチ会で気づいたのですが、現在、ItamaeではサポートするRubyのversionをgemspecにおいて明確には定めていません。

    "REQUIRED RUBY VERSION: >= 0" という表記が気になるなぁと思い、 @sue445 さんに相談したのですが、Infrastructureに関連するツールであることから、公式でEOLになったからといってサポートを切るのはどうなのだろう、という意見を頂きました。確かに、そうですね。

    例えばRed Hat Enterprise Linuxの場合、延長ライフサイクルサポートアドオンを利用している場合において、記事執筆時点でサポートされている最古のバージョンは5になります。 (2020年11月30日まで)

    RHEL 5において使用できるRubyのversionはどうやら1.8.7のようです。まじか。

    また @sue445 さんとは、「unit testが通る最古の Ruby version を調べて、それをrequired ruby versionとすればよいのでは」という話もしました。なのでちょっと調べてみましょう。

    ……とは言ったものの、例えばRuby 2.2.10 を単純に "$ rbenv install 2.2.10" でインストールしようとしても、OpenSSL周りでビルドに失敗してしまいます。

    % rbenv install 2.2.10
    Downloading ruby-2.2.10.tar.bz2...
    -> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.10.tar.bz2
    Installing ruby-2.2.10...
    WARNING: ruby-2.2.10 is past its end of life and is now unsupported.
    It no longer receives bug fixes or critical security updates.
    
    
    BUILD FAILED (Arch Linux using ruby-build 20190423)
    
    Inspect or clean up the working tree at /tmp/ruby-build.20190517222414.12439
    Results logged to /tmp/ruby-build.20190517222414.12439.log
    
    Last 10 log lines:
    make[1]: *** [exts.mk:205: ext/openssl/all] エラー 2
    make[1]: *** 未完了のジョブを待っています....
    linking shared-object objspace.so
    make[2]: ディレクトリ '/tmp/ruby-build.20190517222414.12439/ruby-2.2.10/ext/objspace' から出ます
    linking shared-object pathname.so
    make[2]: ディレクトリ '/tmp/ruby-build.20190517222414.12439/ruby-2.2.10/ext/pathname' から出ます
    linking shared-object nkf.so
    make[2]: ディレクトリ '/tmp/ruby-build.20190517222414.12439/ruby-2.2.10/ext/nkf' から出ます
    make[1]: ディレクトリ '/tmp/ruby-build.20190517222414.12439/ruby-2.2.10' から出ます
    make: *** [uncommon.mk:189: build-ext] エラー 2

    DockerでないRuby 2.2の環境が欲しくなり、そして永い旅へ……

    — うなすけ (@yu_suke1994) May 16, 2019

    ここで "Dockerでない" としている理由は、Itamaeのintegration testではdocker containerに対してrecipeを適用した結果をみているためです。ただ、unit testだけであればdocker container内で完結でき、文法に非互換があるかどうかの確認もできるので、もしかしたらcontainerがあれば十分なのかもしれません。

    なので、Dockerを使って試してみましょう。

    Docker HubでホスティングされているRubyで、最古のものは1.9.3-p550でした。このRubyにおいては、bundle install時に rake が Ruby 2.0 以上を要求するので、そもそもunit testを実行することができません。

    root@7a14576593e3:/tmp/itamae# ruby -v
    ruby 1.9.3p550 (2014-10-27 revision 48165) [x86_64-linux]
    
    root@7a14576593e3:/tmp/itamae# bundle install
    Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all
    non-root users on this machine.
    Fetching gem metadata from https://rubygems.org/........
    Resolving dependencies...
    Gem::InstallError: rake requires Ruby version >= 2.0.0.
    An error occurred while installing rake (12.3.2), and Bundler cannot continue.
    Make sure that `gem install rake -v '12.3.2'` succeeds before bundling.

    また、Itamaeの依存であるSpecinfraが要求するnet-ssh gemが Ruby 2.2.6 を要求するので、そもそもgem install itamaeは Ruby 2.2.6 以上でないと成功しません。

    root@f47f2b9dbc02:/# gem install itamae
    Fetching: thor-0.20.3.gem (100%)
    Fetching: net-ssh-5.2.0.gem (100%)
    ERROR:  Error installing itamae:
           net-ssh requires Ruby version >= 2.2.6.

    そして、 Ruby 2.2.6 では以下に示すように bundle exec rake spec:unit がpassすることが確認できました。

    root@b65d5b19cf7b:/tmp/itamae# ruby -v
    ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux]
    
    root@b65d5b19cf7b:/tmp/itamae# bundle exec rake spec:unit
    /usr/local/bin/ruby -I ./spec/unit -I/usr/local/bundle/gems/rspec-core-3.8.0/lib:/usr/local/bundle/gems/rspec-support-3.8.0/lib /usr/local/bundle/gems/rspec-core-3.8.0/exe/rspec --pattern ./spec/unit\{,/\*/\*\*\}/\*_spec.rb
    Run options: include {:focus=>true}
    All examples were filtered out; ignoring {:focus=>true}
    Randomized with seed 18044
    ...snip...
    Finished in 0.09785 seconds (files took 0.55001 seconds to load)
    32 examples, 0 failures, 1 pending

    ということは、とりあえず、「事実上、ItamaeのサポートするRubyのversionは2.2.6以上である」と言えそうですね。

    追記

    記事執筆にあたり、@orisanoと@arayaryomaと@do_su_0805に助けていただきました。ありがとうございました。

    あなたへのおすすめ