This repository has been archived by the owner on Sep 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
123 lines (105 loc) · 2.8 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
require 'erb'
require 'rake'
require 'rspec/core/rake_task'
task :default => "test"
desc "run server spec"
task :spec => 'spec:all'
desc "run unit test"
task "test" do
sh 'docker run --rm -it -v "$(pwd)":/go/src/github.com/STNS/libnss_stns -w /go/src/github.com/STNS/libnss_stns -t pyama/stns:ubuntu-x86 /bin/bash'
end
desc "make centos5 package"
task "make_centos5_pkg" => [:clean_bin, :ubuntu_build_x86] do
sh "docker build -f docker/centos5-pkg -t stns:cent5 ."
sh "docker run -v \"$(pwd)\"/binary:/go/src/github.com/STNS/libnss_stns/binary stns:cent5"
end
desc "make package all architecture"
task "make_pkg" => %W(
clean_pkg
make_pkg_x86
make_pkg_i386
)
desc "test package all architecture"
task "test_pkg" => %W(
make_pkg
test_pkg_x86
test_pkg_i386
)
%w(x86 i386).each do |arch|
desc "make package #{arch}"
task "make_pkg_#{arch}" => %W(
clean_bin
ubuntu_build_#{arch}
centos_pkg_#{arch}
ubuntu_pkg_#{arch}
)
desc "test package #{arch}"
task "test_pkg_#{arch}" => %W(
centos_ci_#{arch}
ubuntu_ci_#{arch}
)
end
task "clean_all" do
sh "rm -rf binary/*"
end
desc "delete binarys"
task "clean_bin" do
sh "find binary/* | grep -v -e 'rpm$' -e 'deb$' | xargs rm -rf"
end
desc "delete packages"
task "clean_pkg" do
sh "find binary/* | grep -e 'rpm$' -e 'deb$' | xargs rm -rf"
end
[
{
os: "centos",
arch: %w(x86 i386),
pkg_arch: %w(x86_64 i386)
},
{
os: "ubuntu",
arch: %w(x86 i386),
pkg_arch: %w(amd64 i386)
}
].each do |h|
h[:arch].each_with_index do |arch,index|
unless h[:os] == "centos"
desc "#{h[:os]}_build_#{arch}"
task "#{h[:os]}_build_#{arch}" do
docker_run(h[:os], arch, "build")
end
end
%w(pkg ci).each do |t|
task "#{h[:os]}_#{t}_#{arch}" do
docker_run(h[:os], arch, t, h[:pkg_arch][index])
end
end
end
end
def docker_run(os, arch, task, pkg_arch=nil)
content = ERB.new(open("docker/#{os}-#{task}.erb").read).result(binding)
open("docker/tmp/#{os}-#{arch}-#{task}","w") {
|f| f.write(content)
}
sh "docker build --rm -f docker/tmp/#{os}-#{arch}-#{task} -t stns:lib_stns ."
sh "docker run --rm -it -v \"$(pwd)\"/binary:/go/src/github.com/STNS/libnss_stns/binary -t stns:lib_stns"
end
namespace :spec do
targets = []
Dir.glob('./spec/*').each do |dir|
next unless File.directory?(dir)
target = File.basename(dir)
target = "_#{target}" if target == "default"
targets << target
end
task :all => targets
task :default => :all
targets.each do |target|
original_target = target == "_default" ? target[1..-1] : target
desc "Run serverspec tests to #{original_target}"
RSpec::Core::RakeTask.new(target.to_sym) do |t|
ENV['TARGET_HOST'] = original_target
t.pattern = "spec/#{original_target}/*_spec.rb"
end
end
end