Skip to content

Instantly share code, notes, and snippets.

@sompa
Created February 14, 2014 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sompa/9008544 to your computer and use it in GitHub Desktop.
Save sompa/9008544 to your computer and use it in GitHub Desktop.
Recipe to install ruby, required gems and run dashing server
#
# Cookbook Name:: deploy_artifact
# Recipe:: dashing
#
include_recipe "ruby_build"
branch_name = node['program-dashboard']['branch_or_tag']
ruby_version = node['ruby']['version']
repo_url = node['dashboard_repo']
ruby_prefix_path = node['ruby']['prefix_path']
dashboard_repo_path = node['dashboard_repo_path']
ruby_home = ::File.expand_path('bin',ruby_prefix_path)
bundle_home = ::File.expand_path('bundle', ruby_home)
thin_home = ::File.expand_path('thin', ruby_home)
dashing_start = "#{bundle_home} exec #{thin_home} -R config.ru start -p 3030 -d"
dashing_stop = "#{bundle_home} exec #{thin_home} stop"
bundle_install = "#{bundle_home} install"
package 'git' do
action :install
not_if "which git"
end
ruby_build_ruby ruby_version do
user "root"
prefix_path ruby_prefix_path
definition ruby_version
action :install
not_if "{::File.exists?(ruby_home)}"
end
#Getting the latest from repository
log "Getting the latest from the program-dev-dashboard repo"
git dashboard_repo_path do
repository repo_url
reference branch_name
user "root"
end
%w{bundler dashing}.each do |pkg|
gem_package pkg do
gem_binary "#{ruby_home}/gem"
end
end
execute bundle_install do
cwd dashboard_repo_path
not_if "#{bundle_home} check --gemfile #{::File.expand_path('Gemfile',dashboard_repo_path)}"
end
#Cycle the dashing server
log "Getting the Dashboard Up and Running"
bash "stop dashing" do
user "root"
cwd dashboard_repo_path
flags "-e"
code <<-EOH
echo "Stopping the dashing server if running"
#{dashing_stop}
EOH
only_if "ps aux | grep [t]hin"
end
bash "start dashing" do
user "root"
cwd dashboard_repo_path
flags "-e"
code <<-EOH
echo "Starting the dashing server"
#{dashing_start}
EOH
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment