Skip to content

Commit ed43e66

Browse files
Enhance the development setup
* Add Rakefile to setup/maintain the development setup for crowbar * Add documentation to the development setup * Adapt Guardfile's default directory to /opt/crowbar * Add Gems dependencies for the development group This is a squashed collaborative effort of: Thomas Boerger <[email protected]> Rick Salevsky <[email protected]> Maximilian Meister <[email protected]>
1 parent 6c8a7ed commit ed43e66

File tree

6 files changed

+415
-12
lines changed

6 files changed

+415
-12
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/.guard-exclude-tree
66
/.guard-exclude-barclamp
77

8+
/config/barclamps.local.yml
9+
810
*.lock
911
*.lck
1012
*~

Gemfile

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1-
source 'https://rubygems.org'
1+
#
2+
# Copyright 2011-2013, Dell
3+
# Copyright 2013-2015, SUSE Linux GmbH
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
source "https://rubygems.org"
219

320
group :development do
4-
gem 'rb-inotify', '>= 0.9'
5-
gem 'guard', '>= 1.8'
6-
gem 'guard-remote-sync', '>= 0.1'
21+
gem "rake", ">= 10.3"
22+
gem "rb-inotify", ">= 0.9"
23+
gem "guard", ">= 1.8"
24+
gem "guard-remote-sync", ">= 0.1"
25+
gem "octokit", ">= 4.0"
26+
gem "git", ">= 1.2"
27+
gem "netrc", ">= 0.10"
28+
gem "deep_merge", ">= 1.0"
729
end

Guardfile

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
# First ensure you have the necessary gems by cd'ing to this directory and
2121
# running 'bundle install'. Then use as follows:
2222
#
23-
# $ export GUARD_RELEASE_NAME=development # Default is `development`
24-
# $ export GUARD_SYNC_USER=root # Default is `root`
25-
# $ export GUARD_SYNC_HOST=192.168.124.10 # Default is `192.168.124.10`
26-
# $ export GUARD_TREE_TARGET=/opt/dell # Default is `/opt/dell`
27-
# $ export GUARD_MIRROR_TARGET=/root/barclamps # Default is `/root/barclamps`
28-
# $ export GUARD_SCRIPT_TARGET=/opt/dell/bin # Default is `/opt/dell/bin`
23+
# $ export GUARD_RELEASE_NAME=development # Default `development`
24+
# $ export GUARD_SYNC_USER=root # Default `root`
25+
# $ export GUARD_SYNC_HOST=192.168.124.10 # Default `192.168.124.10`
26+
# $ export GUARD_TREE_TARGET=/opt/crowbar # Default `/opt/crowbar`
27+
# $ export GUARD_MIRROR_TARGET=/root/barclamps # Default `/root/barclamps`
28+
# $ export GUARD_SCRIPT_TARGET=/opt/crowbar/bin # Default `/opt/crowbar/bin`
2929
# $ bundle exec guard
3030
#
3131
# Now all required files and directories are getting synchronized with the
@@ -62,7 +62,7 @@ notification :off
6262
group :tree do
6363
target = value_for(
6464
"GUARD_TREE_TARGET",
65-
"/opt/dell"
65+
"/opt/crowbar"
6666
)
6767

6868
Pathname.new("barclamps").children.each do |barclamp|
@@ -146,7 +146,7 @@ end
146146
group :script do
147147
target = value_for(
148148
"GUARD_SCRIPT_TARGET",
149-
"/opt/dell/bin"
149+
"/opt/crowbar/bin"
150150
)
151151

152152
exclude_script = File.expand_path(

Rakefile

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#
2+
# Copyright 2011-2013, Dell
3+
# Copyright 2013-2015, SUSE Linux GmbH
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
namespace :crowbar do
19+
require "git"
20+
require "octokit"
21+
require "netrc"
22+
require "yaml"
23+
require "deep_merge"
24+
25+
task :configure do
26+
@git = Git::Lib.new
27+
28+
general_path = File.expand_path("../config/barclamps.yml", __FILE__)
29+
30+
general_config = if File.exist? general_path
31+
YAML.load_file(
32+
general_path
33+
)
34+
else
35+
{}
36+
end
37+
38+
local_path = File.expand_path("../config/barclamps.local.yml", __FILE__)
39+
40+
local_config = if File.exist? local_path
41+
YAML.load_file(
42+
local_path
43+
)
44+
else
45+
{}
46+
end
47+
48+
@barclamps = general_config.deep_merge(
49+
local_config
50+
).values.flatten
51+
end
52+
53+
desc "Init all barclamps"
54+
task init: [:fork, :clone, :add_upstream, :add_susecloud] do
55+
# nothing to do here
56+
end
57+
58+
desc "Update all clones"
59+
task update: [:pull_upstream] do
60+
# nothing to do here
61+
end
62+
63+
desc "Forks all required barclamps to your home project"
64+
task fork: [:configure] do
65+
client = Octokit::Client.new(netrc: true)
66+
67+
@barclamps.each do |barclamp|
68+
begin
69+
if client.repository? "#{client.login}/barclamp-#{barclamp}"
70+
puts "Barclamp #{barclamp} already forked. Skipping..."
71+
else
72+
puts "Forking barclamp #{barclamp}..."
73+
client.fork("crowbar/barclamp-#{barclamp}")
74+
end
75+
rescue Octokit::NotFound
76+
puts "Barclamp #{barclamp} does not exist"
77+
end
78+
end
79+
end
80+
81+
desc "Clones all required barclamps into the barclamps folder"
82+
task clone: [:configure] do
83+
client = Octokit::Client.new(netrc: true)
84+
85+
Dir.chdir "barclamps" do
86+
@barclamps.each do |barclamp|
87+
if Dir.exist? barclamp
88+
puts "Barclamp #{barclamp} already exists. Skipping..."
89+
else
90+
if client.repository? "#{client.login}/barclamp-#{barclamp}"
91+
puts "Cloning barclamp #{barclamp}..."
92+
Git.clone("[email protected]:#{client.login}/barclamp-#{barclamp}.git", barclamp)
93+
else
94+
puts "Barclamp #{barclamp} does not exist"
95+
end
96+
end
97+
end
98+
end
99+
end
100+
101+
desc "Add upstream remote to the crowbar organisation"
102+
task add_upstream: [:configure] do
103+
client = Octokit::Client.new(netrc: true)
104+
105+
@barclamps.each do |barclamp|
106+
barclamp_dir = File.join("barclamps", barclamp)
107+
108+
unless Dir.exist? barclamp_dir
109+
puts "Barclamp #{barclamp} directory does not exist"
110+
next
111+
end
112+
113+
Dir.chdir barclamp_dir do
114+
next if @git.remotes.include? "upstream"
115+
116+
if client.repository? "crowbar/barclamp-#{barclamp}"
117+
puts "Adding remote upstream for #{barclamp}..."
118+
@git.remote_add("upstream", "[email protected]:crowbar/barclamp-#{barclamp}.git", fetch: true)
119+
else
120+
puts "Barclamp #{barclamp} doesn't exist within Crowbar org"
121+
end
122+
end
123+
end
124+
end
125+
126+
desc "Add upstream remote to the SUSE-Cloud organisation"
127+
task add_susecloud: [:configure] do
128+
client = Octokit::Client.new(netrc: true)
129+
130+
@barclamps.each do |barclamp|
131+
barclamp_dir = File.join("barclamps", barclamp)
132+
133+
unless Dir.exist? barclamp_dir
134+
puts "Barclamp #{barclamp} directory does not exist"
135+
next
136+
end
137+
138+
Dir.chdir barclamp_dir do
139+
next if @git.remotes.include? "suse-cloud"
140+
141+
if client.repository? "SUSE-Cloud/barclamp-#{barclamp}"
142+
puts "Adding remote suse-cloud for #{barclamp}..."
143+
@git.remote_add("suse-cloud", "[email protected]:SUSE-Cloud/barclamp-#{barclamp}.git", fetch: true)
144+
else
145+
puts "Barclamp #{barclamp} doesn't exist within SUSE-Cloud org"
146+
end
147+
end
148+
end
149+
end
150+
151+
desc "Update remotes repositories"
152+
task update_remotes: [:configure] do
153+
@barclamps.each do |barclamp|
154+
barclamp_dir = File.join("barclamps", barclamp)
155+
156+
unless Dir.exist? barclamp_dir
157+
puts "Barclamp #{barclamp} directory does not exist"
158+
next
159+
end
160+
161+
Dir.chdir barclamp_dir do
162+
["upstream" "suse-cloud"].each do |remote|
163+
if @git.remotes.include? remote
164+
puts "Updating #{remote} of #{barclamp}..."
165+
msg = @git.fetch(remote, prune: true)
166+
puts msg unless msg.empty?
167+
else
168+
puts "Remote #{remote} of #{barclamp} does not exist"
169+
end
170+
end
171+
end
172+
end
173+
end
174+
175+
desc "Pull from upstream/master"
176+
task pull_upstream: [:configure] do
177+
@barclamps.each do |barclamp|
178+
barclamp_dir = File.join("barclamps", barclamp)
179+
180+
unless Dir.exist? barclamp_dir
181+
puts "Barclamp #{barclamp} directory does not exist"
182+
next
183+
end
184+
185+
Dir.chdir barclamp_dir do
186+
current_branch = @git.branch_current
187+
stash = { saved: false, branch: current_branch }
188+
189+
# save a stash if there are changes
190+
unless @git.diff_files.empty?
191+
puts "Saving stash of #{barclamp}..."
192+
@git.stash_save("Automatic stash by rake - #{Time.now}")
193+
stash[:saved] = true
194+
end
195+
196+
# checkout master if on a different branch
197+
unless current_branch == "master"
198+
puts "Checking out master of #{barclamp}..."
199+
@git.checkout("master")
200+
end
201+
202+
# pull changes from upstream/master
203+
if @git.remotes.include? "upstream"
204+
puts "Pull from upstream/master of #{barclamp}"
205+
msg = @git.pull("upstream")
206+
unless msg.include? "Already up-to-date"
207+
puts msg
208+
puts "^^^^^^^^^^^^^^^^^^^^^^^^^^^"
209+
end
210+
else
211+
puts "Remote upstream of #{barclamp} does not exist"
212+
end
213+
214+
# reapply stash
215+
if stash[:saved]
216+
puts "Reapplying stash to #{stash[:branch]}..."
217+
@git.checkout(stash[:branch]) unless stash[:branch] == "master"
218+
@git.stash_apply
219+
@git.stash_clear
220+
end
221+
end
222+
end
223+
end
224+
end

config/barclamps.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
crowbar:
2+
- cisco-ucs
3+
- crowbar
4+
- deployer
5+
- dns
6+
- ipmi
7+
- logging
8+
- network
9+
- nfs_client
10+
- ntp
11+
- provisioner
12+
- suse-manager-client
13+
- updater
14+
15+
openstack:
16+
- ceilometer
17+
- ceph
18+
- cinder
19+
- database
20+
- glance
21+
- heat
22+
- hyperv-compute
23+
- keystone
24+
- manila
25+
- neutron
26+
- nova
27+
- nova_dashboard
28+
- openstack
29+
- pacemaker
30+
- rabbitmq
31+
- swift
32+
- tempest
33+
- trove

0 commit comments

Comments
 (0)