ruby が色々入っている docker イメージを作っておいた。自分のために一回まとめておく。
Docker は Ubuntu 推奨だが、深淵な理由により Vagrant で CentOS 6.5 環境で動くことを確認しながら作業。
vagrant box add centos-6.5 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
vagrant init centos-6.5
Vagrant の CentOS 6.5 環境はネットワークが遅延してすごく遅くなるっぽいので以下のような Vagrantfile で対応。
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos-6.5"
config.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/vagrant", nfs: true
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--cpus", "4"]
vb.customize ["modifyvm", :id, "--memory", "2048"]
# IPv6とDNSでのネットワーク遅延対策で追記
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
end
end
マシンに入って Docker のインストール.
sudo yum install docker-io
sudo /etc/init.d/docker start
Dockerfile の作成. こんなかんじにして、1.9.3, 2.0.0, 2.1 を pre-install しておくことにした。 ポイントは ruby-build(rbenv)でビルド時に名前を指定する のテクニックを使って patch level を省略させているところかな。
FROM centos
# packages
RUN yum groupinstall -y "Development tools"
RUN yum -y install openssl openssl-devel readline-devel readline compat-readline5 libxml2-devel libxslt-devel libyaml-devel git
# rbenv
RUN git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
RUN mkdir -p ~/.rbenv/plugins && git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
RUN echo -e 'PATH=~/.rbenv/bin:$PATH\neval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh && source /etc/profile.d/rbenv.sh
# ruby
ENV CONFIGURE_OPTS --disable-install-doc
RUN bash -lc '~/.rbenv/plugins/ruby-build/bin/ruby-build 1.9.3-p545 ~/.rbenv/versions/1.9.3'
RUN bash -lc '~/.rbenv/plugins/ruby-build/bin/ruby-build 2.0.0-p451 ~/.rbenv/versions/2.0.0'
RUN bash -lc '~/.rbenv/plugins/ruby-build/bin/ruby-build 2.1.1 ~/.rbenv/versions/2.1'
# bundler for all ruby
RUN echo 'gem: --no-rdoc --no-ri' >> /.gemrc
RUN bash -lc 'for v in 1.9.3 2.0.0 2.1; do rbenv global $v; gem install bundler; done'
ビルド
docker build -t sonots/ruby .
プッシュ
したものがこちらにあります => https://index.docker.io/u/sonots/ruby/
これにさらに mongo, mysql, redis, memcached などを加えて travis のコンテナっぽくして、@takus のDocker/Drone を CentOS 6.5 で動かして Github Enterprise のリポジトリをテストする環境を使ってテストを流せるようにする予定。# travis は Docker ではないが、こんなかんじで各言語ごとに1コンテナ用意しているらしい。たぶん。