Class: Jets::Code::Copy::Base
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util::Sh
#capture, #quiet_sh, #sh
#log
Methods included from Util::Git
#git?, #git_installed?
Class Method Details
.run ⇒ Object
11
12
13
|
# File 'lib/jets/code/copy/base.rb', line 11
def self.run
new.run
end
|
Instance Method Details
#always_keep ⇒ Object
Copy always_keep files and folders like .deploy for remote runner regardless of .gitignore. Allows user to use .deploy/.env files for remote runner And have a .gitignore for .env at the project root level.
68
69
70
71
72
73
74
75
76
|
# File 'lib/jets/code/copy/base.rb', line 68
def always_keep
config.code.copy.always_keep.each do |path|
next unless File.exist?(path)
FileUtils.rm_rf("#{build_root}/stage/code/#{path}")
FileUtils.mkdir_p("#{build_root}/stage/code")
FileUtils.cp_r(path, "#{build_root}/stage/code/#{path}")
end
end
|
#always_remove ⇒ Object
78
79
80
81
82
|
# File 'lib/jets/code/copy/base.rb', line 78
def always_remove
config.code.copy.always_remove.each do |path|
FileUtils.rm_rf("#{build_root}/stage/code/#{path}")
end
end
|
Extract code-temp.zip immediately
26
27
28
|
# File 'lib/jets/code/copy/base.rb', line 26
def
quiet_sh "unzip -q #{build_root}/stage/code-temp.zip -d #{build_root}/stage/code"
end
|
#git_info ⇒ Object
47
48
49
|
# File 'lib/jets/code/copy/base.rb', line 47
def git_info
Jets::Git::Info.new
end
|
#gitconfig ⇒ Object
Ensure gitconfig to avoid the Author identity unknown git warning.
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/jets/code/copy/base.rb', line 53
def gitconfig
home = ENV["HOME"] || "/root"
git_user = capture "git config user.name || true"
return unless git_user.blank?
IO.write("#{home}/.gitconfig", <<~EOL)
[user]
name = Nobody
email = "[email protected]"
EOL
end
|
#remove_temp_files ⇒ Object
Remove code-temp files. Not needed anymore.
31
32
33
34
|
# File 'lib/jets/code/copy/base.rb', line 31
def remove_temp_files
FileUtils.rm_f "#{build_root}/stage/code-temp.zip"
FileUtils.rm_rf "#{build_root}/stage/code-temp"
end
|
#run ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/jets/code/copy/base.rb', line 15
def run
create_temp_zip remove_temp_files
always_keep
always_remove
save_gitinfo
"#{build_root}/stage/code"
end
|
#save_gitinfo ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/jets/code/copy/base.rb', line 36
def save_gitinfo
dest = "#{build_root}/stage/code/.jets/gitinfo.yml"
FileUtils.mkdir_p(File.dirname(dest))
if File.exist?(".jets/gitinfo.yml")
FileUtils.cp(".jets/gitinfo.yml", dest)
else
IO.write(dest, git_info.params.deep_stringify_keys.to_yaml)
end
end
|