forked from crowbar/crowbar
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Guardfile
211 lines (183 loc) · 5.33 KB
/
Guardfile
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# vi:syntax=ruby
#
# Copyright 2011-2013, Dell
# Copyright 2013-2015, SUSE Linux GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# First ensure you have the necessary gems by cd'ing to this directory and
# running 'bundle install'. Then use as follows:
#
# $ export GUARD_RELEASE_NAME=development # Default `development`
# $ export GUARD_SYNC_USER=root # Default `root`
# $ export GUARD_SYNC_HOST=192.168.124.10 # Default `192.168.124.10`
# $ export GUARD_SYNC_PORT=22 # Default `22`
# $ export GUARD_TREE_TARGET=/opt/crowbar # Default `/opt/crowbar`
# $ export GUARD_MIRROR_TARGET=/root/barclamps # Default `/root/barclamps`
# $ export GUARD_SCRIPT_TARGET=/opt/crowbar/bin # Default `/opt/crowbar/bin`
# $ bundle exec guard
#
# Now all required files and directories are getting synchronized with the
# admin node so you can work with this crowbar files now. More about Guard
# at https://github.com/guard/guard#readme.
#
def value_for(variable, default)
target = if ENV[variable]
ENV[variable]
else
default
end
if target.empty?
fail "#{variable} have to be non-empty"
end
target
end
user = value_for(
"GUARD_SYNC_USER",
"root"
)
host = value_for(
"GUARD_SYNC_HOST",
"192.168.124.10"
)
port = value_for(
"GUARD_SYNC_PORT",
"22"
)
notification :off
group :tree do
target = value_for(
"GUARD_TREE_TARGET",
"/opt/crowbar"
)
Pathname.new("barclamps").children.each do |barclamp|
next unless barclamp.directory?
exclude_tree = File.expand_path(
"../.guard-exclude-tree",
__FILE__
)
File.open(exclude_tree, "w") do |file|
file.write "+ /BDD/\n"
file.write "+ /bin/\n"
file.write "+ /chef/\n"
file.write "+ /crowbar_framework/\n"
file.write "+ /doc/\n"
file.write "+ /etc/\n"
file.write "+ /updates/\n"
file.write "- navigation.rb\n"
file.write "- catalog.yml\n"
file.write "- ==BC-MODEL==*\n"
file.write "- *==BC-MODEL==\n"
file.write "- *==BC-MODEL==*\n"
file.write "- *.swp\n"
file.write "- /*\n"
end
guard_params = [
"-ar --stats --cvs-exclude",
"--chown 'crowbar:crowbar'",
"--exclude-from '#{exclude_tree}'",
"-e 'ssh -p #{port}'",
"#{barclamp.to_s}/",
"#{user}@#{host}:#{target}"
]
guard "remote-sync", sync_on_start: true, source: "#{barclamp.to_s}/", cli_options: guard_params.join(" ") do
watch(/\A#{barclamp.to_s}\/.+/)
end
exclude_barclamp = File.expand_path(
"../.guard-exclude-barclamp",
__FILE__
)
File.open(exclude_barclamp, "w") do |file|
file.write "+ /*.yml\n"
file.write "+ /Gemfile\n"
file.write "+ /Rakefile\n"
file.write "+ /README.md\n"
file.write "+ /doc/\n"
file.write "+ /smoketest/\n"
file.write "+ /spec/\n"
file.write "+ /updates/\n"
file.write "- *.swp\n"
file.write "- /*\n"
end
config_params = [
"-ar --stats --cvs-exclude --delete",
"--chown 'crowbar:crowbar'",
"--exclude-from '#{exclude_barclamp}'",
"-e 'ssh -p #{port}'",
"#{barclamp.to_s}/",
"#{user}@#{host}:#{File.join(target, barclamp.to_s)}"
]
guard "remote-sync", sync_on_start: true, source: "#{barclamp.to_s}/", cli_options: config_params.join(" ") do
watch(/\A#{barclamp.to_s}\/.+/)
end
end
end
group :script do
target = value_for(
"GUARD_SCRIPT_TARGET",
"/opt/crowbar/bin"
)
exclude_script = File.expand_path(
"../.guard-exclude-script",
__FILE__
)
File.open(exclude_script, "w") do |file|
file.write "+ barclamp_*\n"
file.write "+ json-*\n"
file.write "+ install-*\n"
file.write "+ network-*\n"
file.write "- *.swp\n"
file.write "- /*\n"
end
script_params = [
"-ar --stats --cvs-exclude --delete",
"--chown 'crowbar:crowbar'",
"--exclude-from '#{exclude_script}'",
"-e 'ssh -p #{port}'",
"scripts/",
"#{user}@#{host}:#{target}"
]
guard "remote-sync", sync_on_start: true, source: "scripts/", cli_options: script_params.join(" ") do
watch(/\Ascripts\/barclamp_.+\z/)
watch(/\Ascripts\/json\-.+\z/)
watch(/\Ascripts\/install\-.+\z/)
watch(/\Ascripts\/network\-.+\z/)
end
end
group :mirror do
target = value_for(
"GUARD_MIRROR_TARGET",
"/root/barclamps"
)
exclude_mirror = File.expand_path(
"../.guard-exclude-mirror",
__FILE__
)
File.open(exclude_mirror, "w") do |file|
file.write "+ /*\n"
file.write "- .KEEP_ME\n"
file.write "- *.swp\n"
end
mirror_params = [
"-ar --stats --cvs-exclude --delete",
"--chown 'crowbar:crowbar'",
"--exclude-from '#{exclude_mirror}'",
"-e 'ssh -p #{port}'",
"barclamps/",
"#{user}@#{host}:#{target}"
]
guard "remote-sync", sync_on_start: true, source: "barclamps/", cli_options: mirror_params.join(" ") do
watch(/\Abarclamps\/.+/)
end
end