From 9d776b8904cdae986f2efb1242d5841e871e522d Mon Sep 17 00:00:00 2001 From: Brian Cunnie & Matthew Kocher Date: Wed, 7 Dec 2011 17:43:10 -0800 Subject: [PATCH] Spike to try out the travis cookbooks --- .../lobot/templates/bootstrap_server.sh | 65 ++++++++-------- .../lobot/templates/capistrano-ci.rb | 11 ++- .../cookbooks/pivotal_ci/attributes/travis.rb | 39 ++++++++++ .../cookbooks/pivotal_ci/recipes/default.rb | 22 +++--- lib/generators/lobot/templates/soloistrc | 74 ++++++++++++++++++- lib/lobot/tasks/ci.rake | 2 +- 6 files changed, 160 insertions(+), 53 deletions(-) create mode 100644 lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/attributes/travis.rb diff --git a/lib/generators/lobot/templates/bootstrap_server.sh b/lib/generators/lobot/templates/bootstrap_server.sh index 495a861..6d22688 100644 --- a/lib/generators/lobot/templates/bootstrap_server.sh +++ b/lib/generators/lobot/templates/bootstrap_server.sh @@ -3,55 +3,50 @@ env | grep -q "APP_USER=" || echo "Please set APP_USER environment variable" # perl -e 'print crypt("password", "salt"),"\n"' -getent passwd $APP_USER >/dev/null 2>&1 || useradd $APP_USER -p DEADBEEFSCRYPTEDPASSWORD #sa3tHJ3/KuYvI would be password +sudo getent passwd $APP_USER >/dev/null 2>&1 || sudo useradd $APP_USER -s /bin/bash -p DEADBEEFSCRYPTEDPASSWORD #sa3tHJ3/KuYvI would be password -# copy root's authorized keys to APP_USER -mkdir -p /home/$APP_USER/.ssh -touch /home/$APP_USER/.ssh/authorized_keys -chmod 700 /home/$APP_USER/.ssh -chmod 600 /home/$APP_USER/.ssh/authorized_keys -chown -R $APP_USER /home/$APP_USER/.ssh -authorized_keys_string=`cat /root/.ssh/authorized_keys` -grep -sq "$authorized_keys_string" /home/$APP_USER/.ssh/authorized_keys || cat /root/.ssh/authorized_keys >> /home/$APP_USER/.ssh/authorized_keys +sudo groupadd vagrant +sudo useradd vagrant -s /bin/bash -p DEADBEEFSCRYPTEDPASSWORD -g vagrant -m + +# copy root's authorized keys to APP_USER +sudo mkdir -p /home/$APP_USER/.ssh +sudo touch /home/$APP_USER/.ssh/authorized_keys +sudo chmod 700 /home/$APP_USER/.ssh +sudo chmod 600 /home/$APP_USER/.ssh/authorized_keys +sudo chown -R $APP_USER /home/$APP_USER +authorized_keys_string=`cat /home/ubuntu/.ssh/authorized_keys` +sudo grep -sq "$authorized_keys_string" /home/$APP_USER/.ssh/authorized_keys || cat /home/ubuntu/.ssh/authorized_keys | sudo tee -a /home/$APP_USER/.ssh/authorized_keys ## enable ssh password auth -perl -p -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config -/etc/init.d/sshd reload +sudo perl -p -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config +sudo restart ssh -# install epel -rpm -q epel-release-5-4.noarch || rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm +# get the latest servers +sudo apt-get update -q # install git -yum -y install git +sudo apt-get install --install-suggests --assume-yes -q git -# rvm prereqs -yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libffi-devel openssl-devel iconv-devel java - -# passwordless sudo -sudo_string='ALL ALL = (ALL) NOPASSWD: ALL' -grep "$sudo_string" /etc/sudoers || echo "$sudo_string" >> /etc/sudoers +# mri ruby prereqs +sudo apt-get install --install-suggests --assume-yes -q build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion -cat <<'BOOTSTRAP_AS_USER' > /home/$APP_USER/bootstrap_as_user.sh -set -e +# jruby +sudo apt-get install --install-suggests --assume-yes -q curl g++ openjdk-6-jre-headless ant openjdk-6-jdk -export APP_USER=$1 +curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer -o /tmp/rvm-installer +sudo chmod +x /tmp/rvm-installer +sudo /tmp/rvm-installer --version latest -mkdir -p /home/$APP_USER/rvm/src -curl -Lskf http://github.com/wayneeseguin/rvm/tarball/0f7135af8f0b6139716637d242a82442dd7fef09 | tar xvz -C/home/$APP_USER/rvm/src --strip 1 -cd "/home/$APP_USER/rvm/src" && ./install - -rvm_include_string='[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' -grep "$rvm_include_string" ~/.bashrc || echo "$rvm_include_string" >> ~/.bashrc - -cat <<'RVMRC_CONTENTS' > ~/.rvmrc +cat <<'RVMRC_CONTENTS' | sudo tee /etc/rvmrc rvm_install_on_use_flag=1 rvm_trust_rvmrcs_flag=1 rvm_gemset_create_on_use_flag=1 RVMRC_CONTENTS -BOOTSTRAP_AS_USER -chmod a+x /home/$APP_USER/bootstrap_as_user.sh -su - $APP_USER /home/$APP_USER/bootstrap_as_user.sh $APP_USER -rm /home/$APP_USER/bootstrap_as_user.sh \ No newline at end of file +sudo usermod -G root,admin,rvm $APP_USER + +# passwordless sudo +sudo_string='ALL ALL = (ALL) NOPASSWD: ALL' +sudo grep "$sudo_string" /etc/sudoers || echo "$sudo_string" | sudo tee -a /etc/sudoers diff --git a/lib/generators/lobot/templates/capistrano-ci.rb b/lib/generators/lobot/templates/capistrano-ci.rb index b307e52..b7ad27a 100644 --- a/lib/generators/lobot/templates/capistrano-ci.rb +++ b/lib/generators/lobot/templates/capistrano-ci.rb @@ -7,7 +7,6 @@ raise "rvm_ruby_string not set - are you using RVM" unless ENV['rvm_ruby_string'] set :rvm_ruby_string, ENV['rvm_ruby_string'] - set :rvm_type, :user set :app_name, ci_conf['app_name'] set(:app_dir) { "/var/#{stage}/#{app_name}" } set :user, ci_conf['app_user'] @@ -18,7 +17,7 @@ desc "check for server availability - run this task in a loop to see if the slice is ready to connect to" task :check_for_server_availability do ci_setup - set :user, "root" + set :user, "ubuntu" run "echo Server is available" end @@ -26,11 +25,11 @@ task :bootstrap do ci_setup app_user = user - set :user, "root" + set :user, "ubuntu" set :default_shell, "/bin/bash" - upload "script/bootstrap_server.sh", "/root/bootstrap_server.sh" - run "chmod a+x /root/bootstrap_server.sh" - run "APP_USER=#{app_user} /root/bootstrap_server.sh" + upload "script/bootstrap_server.sh", "/home/ubuntu/bootstrap_server.sh" + run "chmod a+x /home/ubuntu/bootstrap_server.sh" + run "APP_USER=#{app_user} /home/ubuntu/bootstrap_server.sh" end desc "setup and run chef" diff --git a/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/attributes/travis.rb b/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/attributes/travis.rb new file mode 100644 index 0000000..2a7e32e --- /dev/null +++ b/lib/generators/lobot/templates/chef/cookbooks/pivotal_ci/attributes/travis.rb @@ -0,0 +1,39 @@ +travis_yaml = < 'ami-d4de25bd', + :image_id => 'ami-e358958a', :flavor_id => server_config['flavor_id'] || 'm1.large', :key_name => ec2_key_pair_name, :groups => [security_group_name]