Last active
November 11, 2016 09:12
-
-
Save benridane/eb5439a7c53007a12f8f24c75395fbc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if type git > /dev/null 2>&1; then | |
echo "git found" | |
else | |
sudo yum install git | |
fi | |
if type rbenv > /dev/null 2>&1; then | |
echo "rbenv found" | |
else | |
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv | |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile | |
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile | |
exec $SHELL -l | |
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build | |
fi | |
if type ruby > /dev/null 2>&1; then | |
echo "ruby found" | |
else | |
rbenv install 2.3.0 | |
rbenv global 2.3.0 | |
rbenv rehash | |
fi | |
if type bundle > /dev/null 2>&1; then | |
echo "bundle found" | |
else | |
gem install bundle | |
fi | |
if type serf > /dev/null 2>&1; then | |
echo "serf found" | |
else | |
wget https://releases.hashicorp.com/serf/0.8.0/serf_0.8.0_linux_amd64.zip | |
unzip serf_0.8.0_linux_amd64.zip | |
sudo mv serf /usr/local/bin | |
rm serf_0.8.0_linux_amd64.zip | |
fi | |
if type consul > /dev/null 2>&1; then | |
echo "consul found" | |
else | |
wget https://releases.hashicorp.com/consul/0.7.1/consul_0.7.1_linux_amd64.zip | |
unzip consul_0.7.1_linux_amd64.zip | |
sudo mv consul /usr/local/bin | |
rm consul_0.7.1_linux_amd64.zip | |
fi | |
mkdir -p itamae/recipes/remote_files itamae/nodes itamae/spec/centos | |
cat << 'EOS' > itamae/Gemfile | |
source 'https://rubygems.org' | |
gem 'itamae' | |
gem 'rake' | |
gem 'serverspec' | |
EOS | |
cat << 'EOS' > itamae/recipes/ruby_build.rb | |
package "epel-release" | |
package "gcc" | |
package "openssl-devel" | |
package "libyaml-devel" | |
package "readline-devel" | |
package "zlib-devel" | |
package "git" | |
RBENV_DIR = "/usr/local/rbenv" | |
RBENV_SCRIPT = "/etc/profile.d/rbenv.sh" | |
git RBENV_DIR do | |
repository "git://github.com/sstephenson/rbenv.git" | |
end | |
remote_file RBENV_SCRIPT do | |
source "remote_files/rbenv.sh" | |
end | |
execute "set owner and mode for #{RBENV_SCRIPT} " do | |
command "chown root: #{RBENV_SCRIPT}; chmod 644 #{RBENV_SCRIPT}" | |
user "root" | |
end | |
execute "mkdir #{RBENV_DIR}/plugins" do | |
not_if "test -d #{RBENV_DIR}/plugins" | |
end | |
git "#{RBENV_DIR}/plugins/ruby-build" do | |
repository "git://github.com/sstephenson/ruby-build.git" | |
end | |
node["rbenv"]["versions"].each do |version| | |
execute "install ruby #{version}" do | |
command "source #{RBENV_SCRIPT}; rbenv install #{version}" | |
not_if "source #{RBENV_SCRIPT}; rbenv versions | grep #{version}" | |
end | |
end | |
execute "set global ruby #{node["rbenv"]["global"]}" do | |
command "source #{RBENV_SCRIPT}; rbenv global #{node["rbenv"]["global"]}; rbenv rehash" | |
not_if "source #{RBENV_SCRIPT}; rbenv global | grep #{node["rbenv"]["global"]}" | |
end | |
node["rbenv"]["gems"].each do |gem| | |
execute "gem install #{gem}" do | |
command "source #{RBENV_SCRIPT}; gem install #{gem}; rbenv rehash" | |
not_if "source #{RBENV_SCRIPT}; gem list | grep #{gem}" | |
end | |
end | |
execute "echo using user rbenv" do | |
command "echo 'using user rbenv below'; cat RBENV_SCRIPT" | |
end | |
EOS | |
cat << 'EOS' > itamae/recipes/remote_files/rbenv.sh | |
export RBENV_ROOT="/usr/local/rbenv" | |
export PATH="${RBENV_ROOT}/bin:${PATH}" | |
eval "$(rbenv init --no-rehash -)" | |
EOS | |
cat << 'EOS' > itamae/nodes/node.json | |
{ | |
"rbenv": { | |
"versions": ["2.1.1", "2.1.2",2.3.0], | |
"global": "2.3.0", | |
"gems": ["bundler"] | |
} | |
} | |
EOS | |
cat << 'EOS' > itamae/spec/centos/ruby_build_spec.rb | |
require 'spec_helper' | |
describe command('which rbenv') do | |
let(:disable_sudo) { true } | |
its(:stdout) { should match %r{~/.rbenv/bin/rbenv} } | |
end | |
describe file('~/.bash_profile') do | |
it { should be_file } | |
its(:content) { should match(/^export RBENV_ROOT="~\/.rbenv"$/) } | |
its(:content) { should match(/^export PATH="\${RBENV_ROOT}\/bin:\${PATH}"$/) } | |
its(:content) { should match(/^eval "\$\(rbenv init --no-rehash -\)"$/) } | |
end | |
describe file('/usr/local/rbenv/plugins') do | |
it { should be_directory } | |
it { should be_owned_by 'mike' } | |
it { should be_grouped_into 'mike' } | |
it { should be_mode 755 } | |
end | |
describe file('/usr/local/rbenv/plugins/ruby-build') do | |
it { should be_directory } | |
it { should be_owned_by 'mike' } | |
it { should be_grouped_into 'mike' } | |
it { should be_mode 755 } | |
end | |
%w(2.3.0).each do |versoin| | |
describe command("rbenv versions | grep #{versoin}") do | |
let(:disable_sudo) { true } | |
its(:stdout) { should match(/#{Regexp.escape(versoin)}/) } | |
end | |
end | |
describe command('rbenv global') do | |
let(:disable_sudo) { true } | |
its(:stdout) { should match(/2\.3\.0/) } | |
end | |
EOS | |
cd itamae | |
bundle install --path=vendor/bundle | |
#~/bin/bundle exec itamae ssh -h localhost -u vagrant -j nodes/node.json recipes/ruby_build.rb | |
#~/bin/bundle exec itamae ssh -h localhost -u mike -j nodes/node.json recipes/ruby_build.rb | |
bundle exec serverspec-init | |
#~/bin/bundle exec rake spec spec/centos/ruby_build_spec.rb | |
#serf agent -iface=eth1 -discover=serf -event-handler=query=uptime & | |
#consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment