-
Notifications
You must be signed in to change notification settings - Fork 187
/
Rakefile
136 lines (117 loc) · 4.26 KB
/
Rakefile
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
require 'rake'
require 'rake/packagetask'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'rubygems'
require 'cucumber'
# Run all units tests in test/
desc "Run unit tests in test/"
Rake::TestTask.new(:test) do |t|
t.libs << ['test', 'lib', 'test/helpers']
test_files = FileList.new("test/**/*_test.rb")
test_files.exclude("test/instance_agent/plugins/windows/*_test.rb")
t.test_files = test_files
t.verbose = true
end
task :default => [:version_tracking, :test]
task :release => [:version_tracking, :test]
desc "Run unit tests in spec/"
RSpec::Core::RakeTask.new({:exclude_pattern =>'spec/aws/codedeploy/local/deployer_spec.rb'})
task :test => :spec
begin
require 'cucumber'
require 'cucumber/rake/task'
desc = 'aws codedeploy agent integration tests'
Cucumber::Rake::Task.new('test-integration-aws-codedeploy-agent', desc) do |t|
t.cucumber_opts = "features -t ~@Ignore"
end
task 'test-integration' => 'test-integration-aws-codedeploy-agent'
rescue LoadError
desc 'aws codedeploy agent integration tests'
task 'test:integration' do
puts 'skipping aws-codedeploy-agent integration tests, cucumber not loaded'
end
end
# Version tracking
require 'fileutils'
task :version_tracking do
FileUtils.rm('.version') if File.exist?('.version')
File.open('.version', 'w+') {|file| file.write("agent_version: #{getAgentTrackingInfo}")}
FileUtils.chmod(0444, '.version')
end
def getAgentTrackingInfo
begin
commit_id = `git rev-parse HEAD`.chop!
tracking = "COMMIT_#{commit_id}"
rescue
tracking = "UNKNOWN_VERSION"
end
end
# Packaging into a tar
# we need GNU tar to avoid warning when extracting the content on linux systems
def tar
_tar = `which tar`.chomp
# we must use GNU tar
unless `#{_tar} --version`.include?('GNU')
# probably on a Mac
_tar = `which gtar`.chomp
raise 'The GNU tar utility was not found in this system. Please install GNU tar before trying to run this task.' if _tar.empty?
end
_tar
end
BIN = "bin"
LIB = "lib"
CERTS = "certs"
CONF = "conf"
VENDOR = "vendor"
VERSION_FILE = ".version"
CONFIG_FILE = "#{CONF}/codedeployagent.yml"
FEATURES = "features"
config = YAML.load(File.read(CONFIG_FILE))
def rubygem_folder
ruby_version = RUBY_VERSION
ruby_version_array = ruby_version.split(".")
ruby_version_array[-1] = "0" # 2.6.x will become 2.6.0
ruby_version_array.join(".")
end
pkg = "#{Dir.pwd}/pkg" ## Package where the tar will be generated.
desc "Package files into a tar"
task :package do
# Clean up existing package
FileUtils.rm_rf(pkg)
# Set up directories
bundle_dir = "#{pkg}/#{config[:program_name]}"
FileUtils.mkdir_p bundle_dir
FileUtils.mkdir_p "#{bundle_dir}/opt/#{config[:program_name]}/"
FileUtils.mkdir_p "#{bundle_dir}/opt/#{config[:program_name]}/bin"
FileUtils.mkdir_p "#{bundle_dir}/etc/#{config[:program_name]}/conf"
FileUtils.mkdir_p "#{bundle_dir}/etc/init.d/"
# Copy files
sh "cp -rf #{BIN} #{bundle_dir}/opt/#{config[:program_name]}/"
sh "cp -rf #{LIB} #{bundle_dir}/opt/#{config[:program_name]}/"
sh "cp -f #{CONF}/codedeployagent.yml #{bundle_dir}/etc/#{config[:program_name]}/conf/"
sh "cp -rf #{CERTS} #{bundle_dir}/opt/#{config[:program_name]}/"
sh "cp -rf #{VENDOR} #{bundle_dir}/opt/#{config[:program_name]}/"
sh "cp -rf init.d #{bundle_dir}/etc/"
sh "cp -f LICENSE #{bundle_dir}/opt/#{config[:program_name]}/"
# Vendor folder needs an extra effort, we also need to package the gems installed
gem_lib_folder = "vendor-thirdparty"
rubygemlibs = "#{gem_lib_folder}/ruby/#{rubygem_folder}"
Dir.glob("#{rubygemlibs}/gems/*") do |path|
sh "cp -r #{path} #{bundle_dir}/opt/#{config[:program_name]}/#{VENDOR}/gems"
end
Dir.glob("#{rubygemlibs}/specifications/*") do |path|
sh "cp -r #{path} #{bundle_dir}/opt/#{config[:program_name]}/#{VENDOR}/specifications"
end
sh "sed '/group :test/,$d' Gemfile > #{bundle_dir}/opt/#{config[:program_name]}/Gemfile"
sh "sed '/add_development_dependency/d' codedeploy_agent.gemspec > #{bundle_dir}/opt/#{config[:program_name]}/codedeploy_agent.gemspec"
# Build tar
sh "cd #{bundle_dir} && COPYFILE_DISABLE=true #{tar} --owner=0 --group=0 -cf #{pkg}/#{config[:program_name]}.tar *"
FileUtils.rm_rf("#{bundle_dir}")
end
# Clean up
task :clean do
rm_rf 'deployment'
rm_rf 'pkg'
rm_rf 'vendor-thirdparty'
end