-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
archive.rb
43 lines (36 loc) · 1.25 KB
/
archive.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'tmpdir'
module OpsWorks
module SCM
module Archive
def prepare_archive_checkouts(scm_options)
unless scm_options[:user].blank? || scm_options[:password].blank?
archive_url = URI.parse(scm_options[:repository])
archive_url.user = scm_options[:user]
archive_url.password = scm_options[:password]
archive_url = archive_url.to_s
else
archive_url = scm_options[:repository]
end
tmpdir = Dir.mktmpdir('opsworks')
directory tmpdir do
mode 0755
end
remote_file "#{tmpdir}/archive" do
source archive_url
retries 2
end
execute 'extract files' do
command "#{node[:opsworks_agent][:current_dir]}/bin/extract #{tmpdir}/archive"
end
execute 'create git repository' do
cwd "#{tmpdir}/archive.d"
command "find . -type d -name .git -exec rm -rf {} \\;; find . -type f -name .gitignore -exec rm -f {} \\;; git init; git add .; git -c user.name='AWS OpsWorks' -c user.email=none commit -m 'Create temporary repository from downloaded contents.'"
end
"#{tmpdir}/archive.d"
end
end
end
end
class Chef::Recipe
include OpsWorks::SCM::Archive
end