vagrant-openshift 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.gitignore +24 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE.txt +13 -0
  6. data/README.asciidoc +379 -0
  7. data/Rakefile +53 -0
  8. data/lib/vagrant-openshift/action/build_geard.rb +41 -0
  9. data/lib/vagrant-openshift/action/build_geard_broker.rb +59 -0
  10. data/lib/vagrant-openshift/action/build_geard_console.rb +55 -0
  11. data/lib/vagrant-openshift/action/build_geard_images.rb +54 -0
  12. data/lib/vagrant-openshift/action/build_sources.rb +39 -0
  13. data/lib/vagrant-openshift/action/checkout_repositories.rb +72 -0
  14. data/lib/vagrant-openshift/action/checkout_tests.rb +57 -0
  15. data/lib/vagrant-openshift/action/clean.rb +51 -0
  16. data/lib/vagrant-openshift/action/clean_network_setup.rb +52 -0
  17. data/lib/vagrant-openshift/action/clone_upstream_repositories.rb +65 -0
  18. data/lib/vagrant-openshift/action/create_ami.rb +54 -0
  19. data/lib/vagrant-openshift/action/create_bare_repo_placeholders.rb +53 -0
  20. data/lib/vagrant-openshift/action/create_puppet_file.rb +84 -0
  21. data/lib/vagrant-openshift/action/create_test_users.rb +36 -0
  22. data/lib/vagrant-openshift/action/create_yum_repositories.rb +121 -0
  23. data/lib/vagrant-openshift/action/download_artifacts.rb +70 -0
  24. data/lib/vagrant-openshift/action/generate_template.rb +89 -0
  25. data/lib/vagrant-openshift/action/idle_all_gears.rb +36 -0
  26. data/lib/vagrant-openshift/action/install_build_dependencies.rb +48 -0
  27. data/lib/vagrant-openshift/action/install_geard.rb +76 -0
  28. data/lib/vagrant-openshift/action/install_geard_base_dependencies.rb +72 -0
  29. data/lib/vagrant-openshift/action/install_geard_broker.rb +39 -0
  30. data/lib/vagrant-openshift/action/install_geard_images.rb +51 -0
  31. data/lib/vagrant-openshift/action/install_open_shift_dependencies.rb +50 -0
  32. data/lib/vagrant-openshift/action/install_rhc.rb +42 -0
  33. data/lib/vagrant-openshift/action/local_geard_checkout.rb +58 -0
  34. data/lib/vagrant-openshift/action/local_repo_checkout.rb +47 -0
  35. data/lib/vagrant-openshift/action/modify_ami.rb +54 -0
  36. data/lib/vagrant-openshift/action/modify_instance.rb +71 -0
  37. data/lib/vagrant-openshift/action/prepare_ssh_config.rb +89 -0
  38. data/lib/vagrant-openshift/action/preserve_mcollective_logs.rb +48 -0
  39. data/lib/vagrant-openshift/action/restart_geard.rb +39 -0
  40. data/lib/vagrant-openshift/action/restart_geard_broker.rb +43 -0
  41. data/lib/vagrant-openshift/action/restart_geard_console.rb +43 -0
  42. data/lib/vagrant-openshift/action/run_geard_tests.rb +57 -0
  43. data/lib/vagrant-openshift/action/run_tests.rb +47 -0
  44. data/lib/vagrant-openshift/action/set_host_name.rb +43 -0
  45. data/lib/vagrant-openshift/action/setup_bind_dns_key.rb +38 -0
  46. data/lib/vagrant-openshift/action/setup_bind_host.rb +141 -0
  47. data/lib/vagrant-openshift/action/setup_builder_files.rb +57 -0
  48. data/lib/vagrant-openshift/action/setup_geard_broker.rb +71 -0
  49. data/lib/vagrant-openshift/action/sync_local_repository.rb +115 -0
  50. data/lib/vagrant-openshift/action/sync_upstream_repository.rb +71 -0
  51. data/lib/vagrant-openshift/action/test_exit_code.rb +36 -0
  52. data/lib/vagrant-openshift/action/uninstall_openshift_rpms.rb +37 -0
  53. data/lib/vagrant-openshift/action/yum_update.rb +67 -0
  54. data/lib/vagrant-openshift/action.rb +308 -0
  55. data/lib/vagrant-openshift/command/build_geard.rb +51 -0
  56. data/lib/vagrant-openshift/command/build_geard_base.rb +51 -0
  57. data/lib/vagrant-openshift/command/build_geard_broker.rb +59 -0
  58. data/lib/vagrant-openshift/command/build_geard_console.rb +59 -0
  59. data/lib/vagrant-openshift/command/build_geard_images.rb +68 -0
  60. data/lib/vagrant-openshift/command/build_origin_base.rb +51 -0
  61. data/lib/vagrant-openshift/command/checkout_repositories.rb +55 -0
  62. data/lib/vagrant-openshift/command/clone_upstream_repositories.rb +54 -0
  63. data/lib/vagrant-openshift/command/create_ami.rb +49 -0
  64. data/lib/vagrant-openshift/command/install_geard.rb +51 -0
  65. data/lib/vagrant-openshift/command/install_geard_broker.rb +51 -0
  66. data/lib/vagrant-openshift/command/install_rhc.rb +49 -0
  67. data/lib/vagrant-openshift/command/local_geard_setup.rb +62 -0
  68. data/lib/vagrant-openshift/command/local_repo_setup.rb +62 -0
  69. data/lib/vagrant-openshift/command/modify_ami.rb +54 -0
  70. data/lib/vagrant-openshift/command/modify_instance.rb +63 -0
  71. data/lib/vagrant-openshift/command/openshift_init.rb +83 -0
  72. data/lib/vagrant-openshift/command/repo_sync.rb +73 -0
  73. data/lib/vagrant-openshift/command/repo_sync_geard.rb +78 -0
  74. data/lib/vagrant-openshift/command/restart_geard.rb +51 -0
  75. data/lib/vagrant-openshift/command/restart_geard_broker.rb +51 -0
  76. data/lib/vagrant-openshift/command/restart_geard_console.rb +51 -0
  77. data/lib/vagrant-openshift/command/setup_geard_broker.rb +49 -0
  78. data/lib/vagrant-openshift/command/test.rb +108 -0
  79. data/lib/vagrant-openshift/command/test_geard.rb +59 -0
  80. data/lib/vagrant-openshift/command/test_geard_image.rb +147 -0
  81. data/lib/vagrant-openshift/config.rb +56 -0
  82. data/lib/vagrant-openshift/constants.rb +111 -0
  83. data/lib/vagrant-openshift/helper/command_helper.rb +213 -0
  84. data/lib/vagrant-openshift/plugin.rb +171 -0
  85. data/lib/vagrant-openshift/provisioner.rb +82 -0
  86. data/lib/vagrant-openshift/templates/builder/Rakefile +231 -0
  87. data/lib/vagrant-openshift/templates/builder/lib/.gitkeep +0 -0
  88. data/lib/vagrant-openshift/templates/builder/lib/rpm.rb +248 -0
  89. data/lib/vagrant-openshift/templates/builder/lib/test.rb +432 -0
  90. data/lib/vagrant-openshift/templates/builder/yum-listbuilddep +124 -0
  91. data/lib/vagrant-openshift/templates/command/init-openshift/Vagrantfile.erb +175 -0
  92. data/lib/vagrant-openshift/templates/command/init-openshift/box_info.yaml +152 -0
  93. data/lib/vagrant-openshift/version.rb +21 -0
  94. data/lib/vagrant-openshift.rb +34 -0
  95. data/vagrant-openshift.gemspec +43 -0
  96. metadata +234 -0
@@ -0,0 +1,231 @@
1
+ #--
2
+ # Copyright 2013 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #++
16
+
17
+ require 'rubygems'
18
+ require 'pathname'
19
+ require 'yaml'
20
+ require 'tsort'
21
+ require_relative 'lib/constants'
22
+ require_relative 'lib/options'
23
+ require_relative 'lib/rpm'
24
+ require_relative 'lib/test'
25
+ $stdout.sync = true
26
+ $stderr.sync = true
27
+
28
+ VALID_IP_ADDR_RE = Regexp.new('^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$')
29
+
30
+ task :install_deps do
31
+ spec_files = RPM::get_packages(ignore_packages: OPTIONS[:ignore_packages], ignore_cache: true)
32
+
33
+ all_build_dependencies = []
34
+ all_inst_dependencies = []
35
+ spec_files.each do |spec|
36
+ all_build_dependencies += spec[:build_deps]
37
+ all_inst_dependencies += spec[:deps]
38
+ end
39
+
40
+ all_packages = all_build_dependencies + all_inst_dependencies
41
+
42
+ all_packages.map! do |name|
43
+ m = name.match(/(ruby193-)?rubygem[(]([a-z\-_]*)[)]/)
44
+ if m.nil?
45
+ name.strip
46
+ else
47
+ scl_prefix = m[1].nil? ? "" : m[1]
48
+ "#{scl_prefix}rubygem-#{m[2]}".strip
49
+ end
50
+ end
51
+
52
+ all_packages.delete_if { |name| name.match(/openshift/)}
53
+
54
+ RPM::install_rpms(all_packages)
55
+ end
56
+
57
+ task :build_all do
58
+ FileUtils.rm_rf("/tmp/tito/*")
59
+ spec_files = RPM::get_packages(remove_os_build_deps: true, ignore_packages: OPTIONS[:ignore_packages], ignore_cache: true)
60
+ RPM::build_packages(spec_files)
61
+ end
62
+
63
+ task :clean_rpms do
64
+ FileUtils.rm_rf("/tmp/tito/*")
65
+ RPM::uninstall_openshift
66
+ end
67
+
68
+ task :install_puppet do
69
+ Dir.chdir((Vagrant::Openshift::Constants.build_dir + "puppet-openshift_origin").to_s) do
70
+ FileUtils.rm_rf "pkg"
71
+ system("puppet module build .")
72
+ pkg = Dir.glob((Vagrant::Openshift::Constants.build_dir + "puppet-openshift_origin/pkg/openshift-openshift_origin*.tar.gz").to_s).first
73
+ system("puppet module uninstall openshift-openshift_origin")
74
+ system("puppet module install #{pkg}")
75
+ system("rm -rf #{Vagrant::Openshift::Constants.build_dir + "puppet-openshift_origin/pkg"}")
76
+ end
77
+ end
78
+
79
+ task :update_packages do
80
+ if (Vagrant::Openshift::Constants.build_dir + ".built_packages").exist?
81
+ print "Updating packages\n"
82
+ RPM::updated_packages
83
+ else
84
+ print "Building all packages\n"
85
+ Rake::Task['build_all'].invoke
86
+ print "Installing openshift puppet module\n"
87
+ Rake::Task['install_puppet'].invoke
88
+ print "Applying openshift puppet recipe\n"
89
+ system("puppet apply --verbose #{Vagrant::Openshift::Constants.build_dir + 'configure_origin.pp'}")
90
+ end
91
+ Rake::Task['restart_services'].invoke
92
+ end
93
+
94
+ task :restart_services do
95
+ is_fedora=File.exists?("/etc/fedora-release")
96
+ system(Vagrant::Openshift::Constants.restart_services_cmd(is_fedora).join("\n"))
97
+ cmd = ""
98
+ OPTIONS[:additional_services].each do |service|
99
+ cmd += "service #{service} restart;"
100
+ end
101
+ system(cmd)
102
+
103
+ unless system("service openshift-tc status 2>/dev/null 1>/dev/null")
104
+ system("service openshift-tc reload")
105
+ end
106
+
107
+ # TODO: Replace this temporary fix with a complete post-install routine
108
+ `oo-admin-ctl-cartridge -c import-node --activate --obsolete && RAILS_ENV=test oo-admin-ctl-cartridge -c import-node --activate --obsolete`
109
+ end
110
+
111
+ task :checkout_tests do
112
+ print "Updating remote tests..."
113
+ system "rm -rf #{Vagrant::Openshift::Constants.build_dir}/openshift-test"
114
+ git_archive_commands = ''
115
+ Vagrant::Openshift::Constants.repos.each do |repo_name, url|
116
+ repo_dir = "#{Vagrant::Openshift::Constants.build_dir}/#{repo_name}-bare"
117
+ git_archive_commands += "pushd #{repo_dir} > /dev/null; git archive --prefix openshift-test/ --format=tar 'HEAD' | (cd #{Vagrant::Openshift::Constants.build_dir} && tar --warning=no-timestamp -xf -); popd > /dev/null; "
118
+ end
119
+ git_archive_commands += "pushd #{Vagrant::Openshift::Constants.build_dir}/rhc-bare > /dev/null; git archive --prefix openshift-test/rhc/ --format=tar 'HEAD' | (cd #{Vagrant::Openshift::Constants.build_dir} && tar --warning=no-timestamp -xf -); popd > /dev/null; "
120
+
121
+ system %{
122
+ set -e;
123
+ rm -rf #{Vagrant::Openshift::Constants.build_dir}/openshift-test
124
+ #{git_archive_commands}
125
+ mkdir -p /tmp/rhc/junit
126
+ }
127
+
128
+ system(%{
129
+ rm -rf #{Vagrant::Openshift::Constants.build_dir}/openshift-test/tests;
130
+ ln -s #{Vagrant::Openshift::Constants.build_dir}/openshift-test/controller/test/cucumber #{Vagrant::Openshift::Constants.build_dir}/openshift-test/tests
131
+ })
132
+ print "done\n"
133
+ end
134
+
135
+ task :create_test_users do
136
+ system("mkdir -p /etc/openshift && touch /etc/openshift/htpasswd")
137
+ ['test_user@test.com', 'user_with_multiple_gear_sizes@test.com', 'user_with_extra_storage@test.com', 'user_with_certificate_capabilities@test.com']. each do |user|
138
+ unless system("/usr/bin/curl -f -k https://broker.example.com/broker/rest/user -u #{user}:test 2>/dev/null 1>/dev/null")
139
+
140
+ # Try to create the user record
141
+ print "Creating test user: #{user}\n"
142
+ user_created = false
143
+ create_retries = 0
144
+ while create_retries < 3 do
145
+ user_created = system("/usr/bin/htpasswd -b /etc/openshift/htpasswd #{user} test")
146
+ break if user_created
147
+ create_retries = create_retries + 1
148
+ print "Could not add user #{user} to htpasswd file on attempt #{create_retries}\n"
149
+ sleep 2
150
+ end
151
+ if not user_created
152
+ print "Unable to add user '#{user}' to /etc/openshift/htpasswd\n"
153
+ exit 1
154
+ end
155
+
156
+ # Test the user record via the REST API
157
+ rest_connected = false
158
+ rest_retries = 0
159
+ while rest_retries < 3 do
160
+ rest_connected = system("/usr/bin/curl -f -k https://broker.example.com/broker/rest/user -u #{user}:test 2>/dev/null 1>/dev/null")
161
+ break if rest_connected
162
+ rest_retries = rest_retries + 1
163
+ print "Could not verify user #{user} via the REST API on attempt #{rest_retries}\n"
164
+ sleep 10
165
+ end
166
+ if not rest_connected
167
+ print "Unable to verify user #{user} via the REST API\n"
168
+ exit 1
169
+ end
170
+ else
171
+ print "#{user} already exists\n"
172
+ end
173
+ end
174
+
175
+ # Create a known test user with medium-sized gears
176
+ # This must be done before the deployment of application templates!
177
+ exitcode = system("/usr/sbin/oo-admin-ctl-user -l user_with_multiple_gear_sizes@test.com --addgearsize medium")
178
+ if(!exitcode)
179
+ print "Unable to assign medium gear capability to user_with_multiple_gear_sizes@test.com"
180
+ exit 1
181
+ end
182
+
183
+ # Create a test user with additional storage capabilities
184
+ exitcode = system("/usr/sbin/oo-admin-ctl-user -l user_with_extra_storage@test.com --setmaxuntrackedstorage 5 --setmaxgears 10")
185
+ if(!exitcode)
186
+ print "Unable to assign additional storage to user_with_extra_storage@test.com"
187
+ exit 1
188
+ end
189
+
190
+ # Create a test user with ssl certificates capabilities
191
+ exitcode = system("/usr/sbin/oo-admin-ctl-user -l user_with_certificate_capabilities@test.com --allowprivatesslcertificates true")
192
+ if(!exitcode)
193
+ print "Unable to assign ssl certificates capabilities to user_with_certificate_capabilities@test.com"
194
+ exit 1
195
+ end
196
+
197
+ unless system("test -e /root/.ssh/id_rsa")
198
+ system("ssh-keygen -q -f /root/.ssh/id_rsa -P \"\" </dev/null")
199
+ end
200
+ end
201
+
202
+ task :idle_all_gears do
203
+ Test.new.idle_all_gears
204
+ end
205
+
206
+ task :run_tests do
207
+ options = {}
208
+ options[:fixme] = ENV["fixme"] == "true"
209
+ if ENV["extended"] == "true"
210
+ options[:gear_extended] = ENV["gear"] == "true"
211
+ options[:node_extended] = ENV["node"] == "true"
212
+ options[:cart_extended] = ENV["cart"] == "true"
213
+ options[:broker_extended] = ENV["broker"] == "true"
214
+ options[:rhc_extended] = ENV["rhc"] == "true"
215
+ options[:console_extended] = ENV["console"] == "true"
216
+ options[:node] = false
217
+ options[:cart] = false
218
+ options[:broker] = false
219
+ options[:rhc] = false
220
+ options[:console] = false
221
+ else
222
+ options[:gear] = ENV["gear"] == "true"
223
+ options[:node] = ENV["node"] == "true"
224
+ options[:cart] = ENV["cart"] == "true"
225
+ options[:broker] = ENV["broker"] == "true"
226
+ options[:rhc] = ENV["rhc"] == "true"
227
+ options[:console] = ENV["console"] == "true"
228
+ end
229
+
230
+ Test.new.test(options)
231
+ end
@@ -0,0 +1,248 @@
1
+ #--
2
+ # Copyright 2013 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #++
16
+
17
+ require_relative 'constants'
18
+ require_relative 'options'
19
+ require 'tempfile'
20
+ require 'fileutils'
21
+ require 'pathname'
22
+ require 'yaml'
23
+
24
+ class RPM
25
+ def self.get_packages(options={})
26
+ spec_cache = Pathname.new(Vagrant::Openshift::Constants.build_dir + ".spec_cache")
27
+ if spec_cache.exist? && !options[:ignore_cache]
28
+ return YAML.load(File.open(spec_cache.to_s))
29
+ end
30
+
31
+ parent_dir = Pathname.new(File.expand_path("__FILE__/../../"))
32
+
33
+ #find all spec files
34
+ spec_files = []
35
+ Vagrant::Openshift::Constants.repos.each do |name, url|
36
+ repo_dir = parent_dir + name
37
+ spec_files += Dir.glob((repo_dir + "**/*.spec").to_s).map{ |p| {path: p}}
38
+ end
39
+
40
+ #exclude ones that have not been tagged
41
+ source_package_names = []
42
+ spec_files.delete_if do |spec|
43
+ spec[:name] = `rpm -q --specfile --queryformat '%{NAME}\n' #{spec[:path]}`.split("\n")[0]
44
+ spec[:version] = `rpm -q --specfile --queryformat '%{VERSION}\n' #{spec[:path]}`.split("\n")[0]
45
+ source_package_names << spec[:name]
46
+ spec[:dir] = Pathname.new(spec[:path]).dirname
47
+ is_tagged = Dir.chdir(spec[:dir]) { system "git tag | grep '#{spec[:name]}' 2>&1 1>/dev/null" }
48
+ is_spec_bad = false
49
+ if is_tagged
50
+ begin
51
+ spec[:build_deps] = YAML.load(`./yum-listbuilddep #{spec[:path]}`.split("\n").last)
52
+ raise "Bad spec" if spec[:build_deps].class == Hash
53
+ spec[:deps] = `rpm -q --specfile --requires #{spec[:path]}`.split("\n")
54
+ rescue Exception => e
55
+ next true
56
+ end
57
+ else
58
+ puts "\n\nSkipping '#{spec[:name]}' in '#{spec[:dir]}' since it is not tagged.\n"
59
+ next true
60
+ end
61
+
62
+ options.has_key?(:ignore_packages) && options[:ignore_packages].include?(spec[:name])
63
+ end
64
+
65
+ if(options.has_key?(:remove_os_build_deps) && options[:remove_os_build_deps])
66
+ #remove deps provided by OS and keep only the ones that will be built from source
67
+ spec_files.each do |spec|
68
+ spec[:build_deps].delete_if{ |dep| not source_package_names.include? dep }
69
+ end
70
+ end
71
+
72
+ File.open(spec_cache.to_s, "w") do |file|
73
+ file.write(spec_files.to_yaml)
74
+ end
75
+
76
+ spec_files
77
+ end
78
+
79
+ def self.install_rpms(list)
80
+ print "Installing #{list.size} in chunks of 20 packages"
81
+ list.uniq.each_slice(20) do |sub_list|
82
+ system %{yum install -y --skip-broken "#{sub_list.join('" "')}"}
83
+ end
84
+ end
85
+
86
+ def self.uninstall_openshift
87
+ #undo pam.d sshd modification
88
+ if system("grep -n 'pam_openshift' /etc/pam.d/sshd")
89
+ file = Tempfile.new('temp')
90
+ begin
91
+ file.write(%{
92
+ set /files/etc/pam.d/sshd/#comment[.='pam_openshift.so close should be the first session rule'] 'pam_selinux.so close should be the first session rule'
93
+ ins 01 before /files/etc/pam.d/sshd/*[argument='close']
94
+ set /files/etc/pam.d/sshd/01/type session
95
+ set /files/etc/pam.d/sshd/01/control required
96
+ set /files/etc/pam.d/sshd/01/module pam_selinux.so
97
+ set /files/etc/pam.d/sshd/01/argument close
98
+
99
+ set /files/etc/pam.d/sshd/#comment[.='pam_openshift.so open should only be followed by sessions to be executed in the user context'] 'pam_selinux.so open should only be followed by sessions to be executed in the user context'
100
+ ins 02 before /files/etc/pam.d/sshd/*[argument='open']
101
+ set /files/etc/pam.d/sshd/02/type session
102
+ set /files/etc/pam.d/sshd/02/control required
103
+ set /files/etc/pam.d/sshd/02/module pam_selinux.so
104
+ set /files/etc/pam.d/sshd/02/argument[1] open
105
+ set /files/etc/pam.d/sshd/02/argument[2] env_params
106
+
107
+ rm /files/etc/pam.d/sshd/*[module='pam_openshift.so']
108
+ rm /files/etc/pam.d/sshd/*[module='pam_namespace.so']
109
+ rm /files/etc/pam.d/sshd/*[module='pam_cgroup.so']
110
+ rm /files/etc/pam.d/sshd/*[module='pam_succeed_if.so']
111
+ save
112
+ })
113
+ file.close
114
+ system("augtool --file #{file.path}")
115
+ ensure
116
+ file.unlink
117
+ end
118
+ end
119
+ FileUtils.rm_rf("/etc/openshift")
120
+
121
+ get_packages(ignore_cache: true).each_slice(10) do |spec_files_list|
122
+ sub_list = spec_files_list.map {|s| s[:name] }
123
+ system %{yum erase -y "#{sub_list.join('" "')}"}
124
+ end
125
+ end
126
+
127
+ def self.build_packages(spec_files, opts={})
128
+ built_specs = []
129
+
130
+ FileUtils.mkdir_p "/tmp/tito/noarch/"
131
+ FileUtils.mkdir_p (Vagrant::Openshift::Constants.build_dir + "origin-rpms").to_s
132
+ FileUtils.mkdir_p (Vagrant::Openshift::Constants.build_dir + "origin-srpms").to_s
133
+ (1..3).each do |phase|
134
+ print "Build phase #{phase}\n"
135
+ buildable = []
136
+
137
+ #install pre reqs if they have already been built
138
+ spec_files.each do |spec|
139
+ spec[:build_deps].delete_if do |dep|
140
+ if opts[:assume_deps_built] || built_specs.map{ |s| s[:name] }.include?(dep)
141
+ puts "\n Installing...#{dep}"
142
+ raise "Unable to install package #{package.name}" unless system("rpm -Uvh --force /tmp/tito/noarch/#{dep}*.rpm")
143
+ true
144
+ else
145
+ false
146
+ end
147
+ end
148
+ end
149
+
150
+ buildable = spec_files.select{ |spec| spec[:build_deps].size == 0 }
151
+
152
+ buildable.each do |spec|
153
+ Dir.chdir(spec[:dir]) do
154
+ puts "\n#{'-'*60}"
155
+ system "rm -f /tmp/tito/noarch/#{spec[:name]}*.rpm"
156
+ system "rm -f /tmp/tito/#{spec[:name]}*.src.rpm"
157
+
158
+ raise "Unable to build #{spec[:name]}" unless system("tito build --rpm --test")
159
+
160
+ Dir.glob('/tmp/tito/x86_64/*.rpm').each {|file|
161
+ FileUtils.mv file, "/tmp/tito/noarch/"
162
+ }
163
+ Dir.glob("/tmp/tito/noarch/#{spec[:name]}*.rpm").each do |file|
164
+ FileUtils.rm_f (Vagrant::Openshift::Constants.build_dir + "origin-rpms/" + "#{spec[:name]}*.rpm").to_s
165
+ FileUtils.cp file, (Vagrant::Openshift::Constants.build_dir + "origin-rpms/").to_s
166
+ end
167
+ Dir.glob('/tmp/tito/*.src.rpm').each {|file|
168
+ FileUtils.rm_f (Vagrant::Openshift::Constants.build_dir + "origin-srpms/" + "#{spec[:name]}*.src.rpm").to_s
169
+ FileUtils.mv file, (Vagrant::Openshift::Constants.build_dir + "origin-srpms/").to_s
170
+ }
171
+
172
+ built_specs << spec
173
+ spec_files.delete(spec)
174
+ end
175
+ end
176
+ end
177
+
178
+ File.open((Vagrant::Openshift::Constants.build_dir + ".built_packages").to_s, "w") do |file|
179
+ file.write(tito_report.to_yaml)
180
+ end
181
+
182
+ print "Updating local repo for built sources"
183
+ Dir.chdir((Vagrant::Openshift::Constants.build_dir + "origin-rpms/").to_s) do
184
+ system("createrepo .")
185
+ system("yum clean all")
186
+ end
187
+
188
+ built_specs
189
+ end
190
+
191
+ def self.updated_packages
192
+ spec_files = get_updated_packages
193
+ built_packages = build_packages(spec_files, {assume_deps_built: true})
194
+ built_packages.each do |spec|
195
+ unless system("rpm -Uvh --force #{Vagrant::Openshift::Constants.build_dir + "origin-rpms"}/#{spec[:name]}*.rpm")
196
+ unless system("rpm -e --justdb --nodeps #{spec[:name]}; yum install -y #{Vagrant::Openshift::Constants.build_dir + "origin-rpms"}/#{spec[:name]}*.rpm")
197
+ print "Unable to install updated package #{spec[:name]}"
198
+ exit 1
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ private
205
+
206
+ def self.get_updated_packages
207
+ raise "Please perform full build with 'rake openshift:build_all' before running sync" unless (Vagrant::Openshift::Constants.build_dir + ".built_packages").exist?
208
+
209
+ spec_files = get_packages(remove_os_build_deps: true)
210
+ cur_report = tito_report
211
+ old_report = YAML.load(File.new((Vagrant::Openshift::Constants.build_dir + ".built_packages").to_s))
212
+
213
+ updated_packages = []
214
+ spec_files.each do |spec|
215
+ cur_package_report = cur_report[spec[:name]]
216
+ old_package_report = old_report[spec[:name]]
217
+
218
+ if (old_package_report.nil? && !cur_package_report.nil?) ||
219
+ (!cur_package_report.nil? && cur_package_report[:version] != old_package_report[:version]) ||
220
+ (!cur_package_report.nil? && cur_package_report[:untagged_revisions] != old_package_report[:untagged_revisions])
221
+ updated_packages << spec unless OPTIONS[:ignore_packages].include?(spec[:name])
222
+ end
223
+ end
224
+
225
+ updated_packages
226
+ end
227
+
228
+ def self.tito_report
229
+ packages = {}
230
+ Vagrant::Openshift::Constants.repos.each do |name, url|
231
+ Dir.chdir((Vagrant::Openshift::Constants.build_dir + name).to_s) do
232
+ tito_report = `tito report --untagged-commits`
233
+ tito_report = tito_report.split(/[-]+{10,100}[\n]/)
234
+ tito_report.shift
235
+
236
+ tito_report.each do |package_report|
237
+ package_report = package_report.split("\n")
238
+ m = package_report.shift.match(/([a-z0-9\-]+)-([\d\.\-]+)..HEAD/)
239
+ packages[m[1]] = {
240
+ version: m[2],
241
+ untagged_revisions: package_report.map{ |line| line.split(" ")[0] }
242
+ }
243
+ end
244
+ end
245
+ end
246
+ packages
247
+ end
248
+ end