Last active
December 18, 2015 16:58
-
-
Save andykent/5814997 to your computer and use it in GitHub Desktop.
An Example Orca File
This file contains 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
require "rest-client" | |
require "orca/extensions/apt" | |
require "orca/extensions/file_sync" | |
group 'server' do | |
node 'kent-web-1', 'xxx.xxx.xxx.xxx', :test_url => 'http://mysite.com/' | |
end | |
package 'app' do | |
depends_on 'deploy-user' | |
depends_on 'dev' | |
depends_on 'ruby-1.9.3' | |
depends_on 'nginx-passenger' | |
depends_on 'bundler' | |
depends_on 'postgres' | |
depends_on 'libxml2' | |
depends_on 'libxslt' | |
depends_on 'nodejs' | |
apply do | |
trigger 'nginx:restart' | |
end | |
validate do | |
RestClient.get(node.test_url).code == 200 rescue false | |
end | |
end | |
apt_package 'build-essential' | |
apt_package 'git', 'git-core' | |
apt_package 'postgresql' | |
apt_package 'libpq-dev' | |
apt_package 'libxml2', 'libxml2-dev' | |
apt_package 'libxslt', 'libxslt1-dev' | |
apt_package 'nginx' do | |
action('start') { sudo 'service nginx start' } | |
action('stop') { sudo 'service nginx stop' } | |
action('restart') { trigger('nginx:running') ? sudo('service nginx restart') : trigger('nginx:start') } | |
action('running') { run('ps aux | grep [n]ginx') =~ /nginx: master process/ } | |
action('reload') { sudo 'pkill -HUP nginx' } | |
end | |
package 'dev' do | |
depends_on 'build-essential' | |
depends_on 'git' | |
end | |
package 'postgres' do | |
depends_on 'postgresql', 'libpq-dev' | |
end | |
package 'nginx-passenger' do | |
depends_on 'gem', 'nginx', 'passenger-common' | |
validate do | |
trigger('gem:exists', 'passenger') && | |
remote("/etc/nginx/sites-enabled/default").exists? == false | |
end | |
apply do | |
trigger 'gem:install', 'passenger' | |
remote("/etc/nginx/sites-enabled/default").delete! | |
end | |
remove do | |
trigger 'gem:uninstall', 'passenger' | |
end | |
file({ | |
:source => 'files/nginx.conf', | |
:destination => '/etc/nginx/nginx.conf', | |
:permissions => 0644, | |
:user => 'root', | |
:group => 'root' | |
}) { trigger 'nginx:restart' } | |
end | |
apt_package 'passenger-common', 'passenger-common1.9.1' do | |
depends_on 'ruby-1.9.3' | |
end | |
package 'ruby-1.9.3' do | |
depends_on 'apt' | |
validate do | |
trigger('apt:exists', 'ruby1.9.3') && binary_exists?('ruby') | |
end | |
apply do | |
trigger 'apt:ppa', 'ppa:brightbox/ruby-ng' | |
trigger 'apt:update' | |
trigger 'apt:install', 'ruby1.9.3' | |
end | |
end | |
package 'nodejs' do | |
depends_on 'apt' | |
validate do | |
trigger('apt:exists', 'nodejs') && | |
binary_exists?('node') && | |
binary_exists?('npm') | |
end | |
apply do | |
trigger 'apt:ppa', 'ppa:chris-lea/node.js' | |
trigger 'apt:update' | |
trigger 'apt:install', 'nodejs' | |
end | |
remove do | |
trigger 'apt:remove', 'nodejs' | |
end | |
end | |
package 'gem' do | |
depends_on 'ruby-1.9.3' | |
action 'exists' do |gem_name| | |
run("gem list -i #{gem_name}") =~ /true/ | |
end | |
action 'install' do |gem_name| | |
sudo "gem install #{gem_name} --no-ri --no-rdoc" | |
end | |
action 'uninstall' do |gem_name| | |
sudo "gem uninstall #{gem_name} -x -a" | |
end | |
end | |
package 'bundler' do | |
depends_on 'gem' | |
apply { trigger 'gem:install', 'bundler' } | |
remove { trigger 'gem:remove', 'bundler' } | |
validate { trigger 'gem:exists', 'bundler' } | |
end | |
package 'deploy-user' do | |
apply do | |
sudo "useradd -d /home/deploy -G sudo -m -U deploy" | |
sudo "echo 'deploy ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers" | |
end | |
remove do | |
sudo "userdel -f deploy" | |
sudo "rm -rf /home/deploy" | |
end | |
validate do | |
sudo('getent passwd deploy') =~ /^deploy:/ && | |
sudo('groups deploy') =~ /deploy sudo/ | |
end | |
file({ | |
:source => 'files/ssh.keys', | |
:destination => '/home/deploy/.ssh/authorized_keys', | |
:create_dirs => true, | |
:permissions => 0644, | |
:user => 'deploy', | |
:group => 'deploy' | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment