Created
January 9, 2012 08:17
-
-
Save tsabat/1581867 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
action :install do | |
#convenience variable. "new_resource" properties are defined when the provider is defined. | |
r = new_resource | |
install_path = "#{r.parent_dir}/#{r.name}" | |
src_path = "#{install_path}/src/#{r.name}" | |
etc_path = "#{install_path}/etc" | |
generation_path = "#{install_path}/generated" | |
[install_path, src_path, etc_path, generation_path].each do |dir| | |
directory dir do | |
mode r.mode | |
#not_if "test -d #{install_path}" | |
action :create | |
recursive true | |
end | |
end | |
directory "/var/log/sm" do | |
owner "root" | |
group "root" | |
mode "0755" | |
action :create | |
not_if "test -d /var/log/sm" | |
end | |
python_virtualenv install_path do | |
action :create | |
owner r.owner | |
group r.group | |
end | |
git src_path do | |
repository r.source_url | |
reference r.source_branch | |
action "sync" | |
user r.owner | |
group r.group | |
end | |
bash "move chef-provided 'deploy' branch to #{r.source_branch}" do | |
code "git branch -m #{r.source_branch}" | |
cwd src_path | |
#only_if {`cd #{src_path}; branch -l | grep -x '* #{r.source_branch}'`.chomp.empty?} | |
only_if do | |
branch = `cd #{src_path}; git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'`.chomp | |
raise branch | |
if branch == 'deploy' && branch != r.source_branch | |
return true | |
end | |
return false | |
end | |
end | |
bash "install from cheeseshop" do | |
code "source bin/activate; pip install -i #{r.cheeseshop_url} -e src/#{r.name}" | |
cwd install_path | |
user r.owner | |
group r.group | |
environment ({'PIP_DOWNLOAD_CACHE' => '/tmp'}) | |
end | |
git etc_path do | |
repository r.config_url | |
reference r.config_branch | |
action "sync" | |
user r.owner | |
group r.group | |
end | |
bash "move chef-provided 'deploy' branch to #{r.config_branch} in directory #{etc_path}" do | |
code "git branch -m #{r.config_branch}" | |
cwd etc_path | |
only_if {r.source_branch != "master" && `cd #{etc_path}; git branch -l | grep -x '* #{r.config_branch}'`.chomp.empty?} | |
end | |
template "#{generation_path}/app.ini" do | |
source "app.ini.erb" | |
cookbook "monkey_project" | |
variables :name => r.name | |
owner r.owner | |
group r.group | |
end | |
template "#{generation_path}/nginx.conf" do | |
source "nginx.service.conf.erb" | |
cookbook "nginx" | |
variables :port => r.server_port, :name => r.name | |
owner r.owner | |
group r.group | |
end | |
template "#{generation_path}/supervisor.conf" do | |
source "supervisord.service.conf.erb" | |
cookbook "supervisord" | |
variables :port => r.server_port, :name => r.name | |
owner r.owner | |
group r.group | |
end | |
link "/etc/supervisor/conf.d/#{r.name}.conf" do | |
to "#{install_path}/etc/supervisor.conf" | |
owner r.owner | |
group r.group | |
end | |
link "/etc/nginx/sites-enabled/#{r.name}" do | |
to "#{install_path}/etc/nginx.conf" | |
owner r.owner | |
group r.group | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment