If you are trying to deploy code from git, then You should look at the deploy resource, its syntax is like this:
deploy 'private_repo' do
repo 'git@github.com:acctname/private-repo.git'
user 'ubuntu'
deploy_to '/tmp/private_code'
end
Here is how I use it to deploy code from my repo
include_recipe 'deploy'
application = search(:aws_opsworks_app).first
deploy = node[:deploy][application['shortname']]
directory deploy[:deploy_to] do
group deploy[:group]
owner deploy[:user]
mode "0775"
action :create
recursive true
end
prepare_git_checkouts(
user: deploy[:user],
group: deploy[:group],
home: deploy[:home],
ssh_key: "#{application['app_source']['ssh_key']}"
)
ruby_block "change HOME to #{deploy[:home]} for source checkout" do
block do
ENV['HOME'] = deploy[:home]
end
end
deploy application['shortname'] do
before_migrate do
link_tempfiles_to_current_release
# Do NPM Install here.
end
branch application['app_source']['revision']
create_dirs_before_symlink deploy[:create_dirs_before_symlink]
deploy_to deploy[:deploy_to] # defaults to 'name' if not specified
environment OpsWorks::Escape.escape_double_quotes(application[:environment])
group deploy[:group]
keep_releases deploy[:keep_releases]
migrate false
provider Chef::Provider::Deploy.const_get(deploy[:chef_provider])
purge_before_symlink(deploy[:purge_before_symlink]) unless deploy[:purge_before_symlink].nil?
repository application['app_source']['url']
revision application['app_source']['revision']
scm_provider Chef::Provider::Git
shallow_clone deploy[:shallow_clone]
symlinks(deploy[:symlinks]) unless deploy[:symlinks].nil?
user deploy[:user]
action deploy[:action] # defaults to :create if not specified
rollback_on_error true
end
ruby_block "change HOME back to /root after source checkout" do
block do
ENV['HOME'] = "/root"
end
end
Here,
we are using the deploy cookbook provided by Opsworks. so prepare_git_checkouts is coming from Opsworks.
Now,
- Set this recipe to execute on the deploy lifecyle event.
- every time things change in your repo. you should trigger a deploy on opsworks & it should be okay.
Hope it helps