Last active
August 29, 2015 14:20
-
-
Save christinedraper/679edad431c935afc8ba to your computer and use it in GitHub Desktop.
Using deploy_revision resource to deploy nodejs from git
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
path = node['myapp']['path'] | |
install_options = [] | |
install_options << "--registry=#{node['myapp']['npm_registry']}" if (node['myapp']['npm_registry']) | |
# option is to prevent failure as pkgs are unauthenticated | |
package 'git' do | |
action :install | |
options "--allow-unauthenticated" | |
end | |
# g++, make and python are needed by node-gyp to build some packages | |
package 'g++' do | |
action :install | |
end | |
package 'make' do | |
action :install | |
end | |
group node['myapp']['user'] | |
user node['myapp']['user'] do | |
group node['myapp']['user'] | |
shell "/bin/bash" | |
home home | |
manage_home true | |
action [:create, :lock] | |
end | |
# Deploy the application from git, if there is a new commit | |
deploy_revision "#{path}" do | |
repo node['myapp']['repo_url'] | |
revision "HEAD" | |
user node['myapp']['user'] | |
action :deploy | |
before_migrate do | |
nodejs_npm "myapp" do | |
path "#{release_path}" | |
package "" | |
user node['myapp']['user'] | |
json "" | |
end | |
end | |
# Next lines prevent symlink problem | |
# http://stackoverflow.com/questions/12568767/chef-deployment-with-irrelevant-default-symlinks | |
symlink_before_migrate.clear | |
create_dirs_before_symlink.clear | |
purge_before_symlink.clear | |
symlinks.clear | |
end | |
# setup the service - template is the one from application_nodejs cookbook | |
template "myapp.upstart.conf" do | |
path "/etc/init/myapp.conf" | |
source 'nodejs.upstart.conf.erb' | |
mode '0644' | |
variables( | |
:user => node['myapp']['user'], | |
:group => node['myapp']['user'], | |
:node_dir => '/usr/local', | |
:app_dir => "#{path}/current", | |
:entry => "server.js" | |
) | |
end | |
# Start the service | |
service node['myapp']['name'] do | |
provider Chef::Provider::Service::Upstart | |
supports :restart => true, :start => true, :stop => true | |
action [:restart] | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment