From b46028826819474e141eadd9a627a7183ba6c95e Mon Sep 17 00:00:00 2001 From: Krishna Raman Date: Sun, 25 Aug 2013 19:09:00 -0700 Subject: [PATCH] First implementation of commands to run Origin. Still requires refinement based on most common use-cases. --- .gitignore | 5 + .idea/.rakeTasks | 2 +- .idea/vagrant-openshift.iml | 14 +- .idea/workspace.xml | 384 +++++++----------- Gemfile | 7 + README.asciidoc | 153 +++++++ README.md | 21 - Rakefile | 6 +- builder/Rakefile | 51 --- lib/vagrant-openshift.rb | 2 +- lib/vagrant-openshift/action.rb | 101 +++++ lib/vagrant-openshift/action/build_sources.rb | 37 ++ .../action/checkout_repositories.rb | 44 ++ .../action/checkout_tests.rb | 35 ++ lib/vagrant-openshift/action/clean.rb | 48 +++ .../action/clone_upstream_repositories.rb | 55 +++ .../action/create_bare_repo_placeholders.rb | 55 +++ .../action/create_puppet_file.rb | 71 ++++ .../action/create_test_users.rb | 35 ++ .../action/create_yum_repositories.rb | 106 +++++ .../action/idle_all_gears.rb | 35 ++ .../action/install_build_dependencies.rb | 44 ++ .../action/install_open_shift_dependencies.rb | 48 +++ .../action/local_repo_checkout.rb | 47 +++ .../action/prepare_ssh_config.rb | 84 ++++ .../action/preserve_mcollective_logs.rb | 40 ++ lib/vagrant-openshift/action/run_tests.rb | 46 +++ lib/vagrant-openshift/action/set_host_name.rb | 43 ++ .../action/setup_bind_dns_key.rb | 38 ++ .../action/setup_builder_files.rb | 57 +++ .../action/sync_local_repository.rb | 113 ++++++ lib/vagrant-openshift/action/yum_update.rb | 66 +++ .../command/build_origin_base.rb | 46 +++ .../command/local_repo_setup.rb | 49 +++ .../command/openshift_init.rb | 98 +++++ lib/vagrant-openshift/command/repo_sync.rb | 72 ++++ lib/vagrant-openshift/command/test.rb | 83 ++++ .../commands/build_origin_base.rb | 111 ----- lib/vagrant-openshift/commands/repo_sync.rb | 176 -------- lib/vagrant-openshift/config.rb | 41 ++ lib/vagrant-openshift/constants.rb | 24 +- .../helper/command_helper.rb | 101 +++++ .../helpers/command_helper.rb | 48 --- lib/vagrant-openshift/plugin.rb | 31 +- lib/vagrant-openshift/provisioner.rb | 63 +++ .../templates/builder/Rakefile | 189 +++++++++ .../templates/builder}/lib/.gitkeep | 0 .../templates/builder/lib/rpm.rb | 239 +++++++++++ .../templates/builder/lib/test.rb | 369 +++++++++++++++++ .../templates/builder}/yum-listbuilddep | 0 .../command/init-openshift/Vagrantfile.erb | 124 ++++++ .../command/init-openshift/box_info.yaml | 58 +++ 52 files changed, 3162 insertions(+), 653 deletions(-) create mode 100644 README.asciidoc delete mode 100644 README.md delete mode 100644 builder/Rakefile create mode 100644 lib/vagrant-openshift/action.rb create mode 100644 lib/vagrant-openshift/action/build_sources.rb create mode 100644 lib/vagrant-openshift/action/checkout_repositories.rb create mode 100644 lib/vagrant-openshift/action/checkout_tests.rb create mode 100644 lib/vagrant-openshift/action/clean.rb create mode 100644 lib/vagrant-openshift/action/clone_upstream_repositories.rb create mode 100644 lib/vagrant-openshift/action/create_bare_repo_placeholders.rb create mode 100644 lib/vagrant-openshift/action/create_puppet_file.rb create mode 100644 lib/vagrant-openshift/action/create_test_users.rb create mode 100644 lib/vagrant-openshift/action/create_yum_repositories.rb create mode 100644 lib/vagrant-openshift/action/idle_all_gears.rb create mode 100644 lib/vagrant-openshift/action/install_build_dependencies.rb create mode 100644 lib/vagrant-openshift/action/install_open_shift_dependencies.rb create mode 100644 lib/vagrant-openshift/action/local_repo_checkout.rb create mode 100644 lib/vagrant-openshift/action/prepare_ssh_config.rb create mode 100644 lib/vagrant-openshift/action/preserve_mcollective_logs.rb create mode 100644 lib/vagrant-openshift/action/run_tests.rb create mode 100644 lib/vagrant-openshift/action/set_host_name.rb create mode 100644 lib/vagrant-openshift/action/setup_bind_dns_key.rb create mode 100644 lib/vagrant-openshift/action/setup_builder_files.rb create mode 100644 lib/vagrant-openshift/action/sync_local_repository.rb create mode 100644 lib/vagrant-openshift/action/yum_update.rb create mode 100644 lib/vagrant-openshift/command/build_origin_base.rb create mode 100644 lib/vagrant-openshift/command/local_repo_setup.rb create mode 100644 lib/vagrant-openshift/command/openshift_init.rb create mode 100644 lib/vagrant-openshift/command/repo_sync.rb create mode 100644 lib/vagrant-openshift/command/test.rb delete mode 100644 lib/vagrant-openshift/commands/build_origin_base.rb delete mode 100644 lib/vagrant-openshift/commands/repo_sync.rb create mode 100644 lib/vagrant-openshift/config.rb create mode 100644 lib/vagrant-openshift/helper/command_helper.rb delete mode 100644 lib/vagrant-openshift/helpers/command_helper.rb create mode 100644 lib/vagrant-openshift/provisioner.rb create mode 100644 lib/vagrant-openshift/templates/builder/Rakefile rename {builder => lib/vagrant-openshift/templates/builder}/lib/.gitkeep (100%) create mode 100644 lib/vagrant-openshift/templates/builder/lib/rpm.rb create mode 100644 lib/vagrant-openshift/templates/builder/lib/test.rb rename {builder => lib/vagrant-openshift/templates/builder}/yum-listbuilddep (100%) create mode 100644 lib/vagrant-openshift/templates/command/init-openshift/Vagrantfile.erb create mode 100644 lib/vagrant-openshift/templates/command/init-openshift/box_info.yaml diff --git a/.gitignore b/.gitignore index d87d4be6..c1855d8f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,9 @@ rdoc spec/reports test/tmp test/version_tmp +test/Vagrantfile +test/Vagrantfile +test/origin-server +test/puppet-openshift_origin +test/rhc tmp diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks index ffccf7c9..420f76d5 100644 --- a/.idea/.rakeTasks +++ b/.idea/.rakeTasks @@ -4,4 +4,4 @@ You are allowed to: 1. Remove rake task 2. Add existing rake tasks To add existing rake tasks automatically delete this file and reload the project. ---> +--> diff --git a/.idea/vagrant-openshift.iml b/.idea/vagrant-openshift.iml index b655da14..5a6df94d 100644 --- a/.idea/vagrant-openshift.iml +++ b/.idea/vagrant-openshift.iml @@ -13,12 +13,20 @@ - + + - + + + + + + + - + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5c9df800..f4dc8477 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,40 +1,22 @@ - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - + @@ -99,29 +63,29 @@ @@ -149,6 +113,7 @@ + @@ -156,9 +121,15 @@ + - + + @@ -170,6 +141,10 @@ @@ -184,6 +159,10 @@ + + @@ -202,6 +181,18 @@ + + + + + + @@ -221,7 +212,11 @@ - + + @@ -243,7 +238,15 @@ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1377192074240 - 1377192074240 + + 1378876546223 + 1378876546223 - - + + - + - + @@ -499,117 +420,114 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/Gemfile b/Gemfile index 63587390..92b57a92 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,10 @@ source 'https://rubygems.org' # Specify your gem's dependencies in vagrant-openshift.gemspec gemspec + +group :development do + # We depend on Vagrant for development, but we don't add it as a + # gem dependency because we expect to be installed within the + # Vagrant environment itself using `vagrant plugin`. + gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git" +end diff --git a/README.asciidoc b/README.asciidoc new file mode 100644 index 00000000..48146f5b --- /dev/null +++ b/README.asciidoc @@ -0,0 +1,153 @@ +== OpenShift Origin Build Tools + +This is a link:http://www.vagrantup.com[Vagrant] 1.2+ plugin that adds command and provisioner to +build and test link:http://openshift.github.io[OpenShift Origin]. + +NOTE: This plugin requires Vagrant 1.2+ + +=== Features + +* Compatible with VMs run via link:https://www.virtualbox.org[VirtualBox], link:https://github.com/mitchellh/vagrant-aws[AWS] + or link:https://github.com/tknerr/vagrant-managed-servers[managed] providers. +* Provides commands to install build dependencies, sync repositories, and run tests + +=== Installing + +To work on the *vagrant-openshift* plugin, clone this repository out, and use +link:http://gembundler.com[Bundler] to get the dependencies: + +[source, sh] +---- +$ bundle +---- + +Compile an install the plugin using Rake + +[source, sh] +---- +$ rake install +---- + +=== Getting started + +==== Clone the OpenShift Origin repositories + +[source, sh] +---- +$ vagrant origin-local-checkout +---- + +This will clone 3 repositores from your link:http://www.github.com[GitHub] account and links it against the upstream repositories. + +.GitHub repositories + +* link:http://github.com/openshift/rhc[Command line tools] +* link:http://github.com/openshift/origin-server[OpenShift Origin console, broker and node] +* link:http://github.com/openshift/puppet-openshift_origin[Puppet module for OpenShift Origin] + +==== Initialize the Vagrantfile + +Create a Vagrantfile and customize it to match your requirements: + +[source, sh] +---- +$ vagrant origin-init +---- + +.Command options: + +* Specify which OS to build with: +** --os fedora - Launch a Fedora 19 image +** --os rhel - Launch a RHEL image (where available) +** --os centos - Launch a CentOS image (where available) +* Build from bare installation of OS: +** --no-base + +==== Start the machine + +.VirtualBox + +Running with the default VirtualBox provider + +[source, sh] +---- +vagrant up +---- + +.AWS/EC2 + +* Edit the Vagrantfile and update your EC2 credentials. + +---- +aws.access_key_id = "" +aws.secret_access_key = "" +aws.keypair_name = "" +override.ssh.private_key_path = "" +---- + +* Start the AWS machine + +[source, sh] +---- +vagrant up --provider=aws +---- + +NOTE: Requires latest link:https://github.com/mitchellh/vagrant-aws[AWS] provider. + +NOTE: You can use the link:https://github.com/mikery/vagrant-ami[Vagrant-AMI] plugin to create an AMI from a running AWS machine. + +.Managed + +Running on other environments which are not managed by Vagrant directly. + +* Edit the Vagrantfile and update the managed section to update the IP address, User name and SSH key. + +---- +managed.server = "HOST or IP of machine" +override.ssh.username = "root" +override.ssh.private_key_path = "~/.ssh/id_rsa" +---- + +* Start the AWS machine + +[source, sh] +---- +vagrant up --provider=managed +---- + +NOTE: Requires latest link:https://github.com/tknerr/vagrant-managed-servers[Managed] provider + +==== Install build dependencies + +If starting from a bare OS image, install the build and package dependencies. + +[source, sh] +---- +$ vagrant origin-build-base +---- + +NOTE: Its is a good idea to snapshot the VM after this step so that you don't have to redo this step every time. + +==== Sync and Build OpenShift packages + +[source, sh] +---- +$ vagrant sync -l +---- + +==== Running OpenShift Origin Tests + +.Running basic tests +[source, sh] +---- +$ vagrant test --all +---- + +.Running extended tests +---- +$ vagrant origin-test --extended --all +---- + +== Notice of Export Control Law + +This software distribution includes cryptographic software that is subject to the U.S. Export Administration Regulations (the "*EAR*") and other U.S. and foreign laws and may not be exported, re-exported or transferred (a) to any country listed in Country Group E:1 in Supplement No. 1 to part 740 of the EAR (currently, Cuba, Iran, North Korea, Sudan & Syria); (b) to any prohibited destination or to any end user who has been prohibited from participating in U.S. export transactions by any federal agency of the U.S. government; or (c) for use in connection with the design, development or production of nuclear, chemical or biological weapons, or rocket systems, space launch vehicles, or sounding rockets, or unmanned air vehicle systems.You may not download this software or technical information if you are located in one of these countries or otherwise subject to these restrictions. You may not provide this software or technical information to individuals or entities located in one of these countries or otherwise subject to these restrictions. You are also responsible for compliance with foreign law requirements applicable to the import, export and use of this software and technical information. diff --git a/README.md b/README.md deleted file mode 100644 index ec769752..00000000 --- a/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# @title OpenShift Origin Build Tools - -#License - -Copyright 2013 Red Hat, Inc. - -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. - -# Notice of Export Control Law - -This software distribution includes cryptographic software that is subject to the U.S. Export Administration Regulations (the "*EAR*") and other U.S. and foreign laws and may not be exported, re-exported or transferred (a) to any country listed in Country Group E:1 in Supplement No. 1 to part 740 of the EAR (currently, Cuba, Iran, North Korea, Sudan & Syria); (b) to any prohibited destination or to any end user who has been prohibited from participating in U.S. export transactions by any federal agency of the U.S. government; or (c) for use in connection with the design, development or production of nuclear, chemical or biological weapons, or rocket systems, space launch vehicles, or sounding rockets, or unmanned air vehicle systems.You may not download this software or technical information if you are located in one of these countries or otherwise subject to these restrictions. You may not provide this software or technical information to individuals or entities located in one of these countries or otherwise subject to these restrictions. You are also responsible for compliance with foreign law requirements applicable to the import, export and use of this software and technical information. diff --git a/Rakefile b/Rakefile index 1787426e..f4cebaa0 100644 --- a/Rakefile +++ b/Rakefile @@ -27,9 +27,11 @@ namespace :vagrant do Rake::Task['build'].invoke name = Bundler::GemHelper.instance.send(:name) version = Bundler::GemHelper.instance.send(:version).to_s - system("vagrant plugin install pkg/#{name}-#{version}.gem") + Bundler.with_clean_env do + system("vagrant plugin install pkg/#{name}-#{version}.gem") + end end end Bundler::GemHelper.install_tasks -task :default => "vagrant:install" \ No newline at end of file +task :default => "vagrant:install" diff --git a/builder/Rakefile b/builder/Rakefile deleted file mode 100644 index c4caf497..00000000 --- a/builder/Rakefile +++ /dev/null @@ -1,51 +0,0 @@ -#-- -# Copyright 2013 Red Hat, Inc. -# -# 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. -#++ - -require 'rubygems' -require 'pathname' -require 'yaml' -require_relative 'lib/constants' -$stdout.sync = true -$stderr.sync = true - -namespace :openshift do - task :install_deps do - spec_files = [] - parent_dir = Pathname.new(File.expand_path("__FILE__/../../")) - Vagrant::Openshift::Constants.repos.each do |name, url| - repo_dir = parent_dir + name - spec_files += Dir.glob((repo_dir + "**/*.spec").to_s) - end - - all_build_dependencies = [] - all_inst_dependencies = [] - spec_files.each do |spec| - spec_build_deps = YAML.load(`./yum-listbuilddep #{spec}`) - all_build_dependencies += spec_build_deps - - spec_inst_deps = `rpm -q --specfile --requires #{spec}`.split("\n") - all_inst_dependencies += spec_inst_deps - end - - all_packages = all_build_dependencies + all_inst_dependencies - print "Installing #{all_packages.size} in chunks of 20 packages" - all_packages.uniq.each_slice(20) do |list| - system %{sudo yum install -y --skip-broken "#{list.join('" "')}"} - end - end - - -end diff --git a/lib/vagrant-openshift.rb b/lib/vagrant-openshift.rb index b1b7ed52..9656100c 100644 --- a/lib/vagrant-openshift.rb +++ b/lib/vagrant-openshift.rb @@ -26,7 +26,7 @@ module Vagrant module Openshift plugin_path = Pathname.new(File.expand_path("#{__FILE__}/../vagrant-openshift/")) - autoload :CommandHelper, plugin_path + "helpers/command_helper" + autoload :CommandHelper, plugin_path + "helper/command_helper" autoload :Constants, plugin_path + "constants" end end diff --git a/lib/vagrant-openshift/action.rb b/lib/vagrant-openshift/action.rb new file mode 100644 index 00000000..153b403d --- /dev/null +++ b/lib/vagrant-openshift/action.rb @@ -0,0 +1,101 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require "vagrant/action/builder" +require "pathname" + +module Vagrant + module Openshift + module Action + include Vagrant::Action::Builtin + + def self.build_origin_base(options) + Vagrant::Action::Builder.new.tap do |b| + b.use CreateYumRepositories + b.use YumUpdate + b.use InstallBuildDependencies + b.use SetupBuilderFiles + b.use Clean + b.use CloneUpstreamRepositories + b.use SetHostName + b.use SetupBindDnsKey + b.use CheckoutRepositories + b.use InstallOpenShiftDependencies + b.use CreatePuppetFile + end + end + + def self.repo_sync(options) + Vagrant::Action::Builder.new.tap do |b| + b.use PrepareSshConfig + if options[:clean] + b.use Clean + b.use SetupBuilderFiles + b.use CreatePuppetFile + if options[:local_source] + b.use CreateBareRepoPlaceholders + else + b.use CloneUpstreamRepositories + end + end + + b.use SyncLocalRepository if options[:local_source] + b.use CheckoutRepositories + b.use InstallOpenShiftDependencies if options[:deps] + b.use BuildSources unless options[:no_build] + end + end + + def self.local_repo_checkout(options) + Vagrant::Action::Builder.new.tap do |b| + b.use LocalRepoCheckout unless options[:no_build] + end + end + + def self.run_tests(options) + Vagrant::Action::Builder.new.tap do |b| + b.use CreateTestUsers + b.use PreserveMcollectiveLogs + b.use IdleAllGears + b.use CheckoutTests + b.use RunTests, options + end + end + + action_root = Pathname.new(File.expand_path("../action", __FILE__)) + autoload :Clean, action_root.join("clean") + autoload :CloneUpstreamRepositories, action_root.join("clone_upstream_repositories") + autoload :CreateYumRepositories, action_root.join("create_yum_repositories") + autoload :CreatePuppetFile, action_root.join("create_puppet_file") + autoload :InstallOpenShiftDependencies, action_root.join("install_open_shift_dependencies") + autoload :CheckoutRepositories, action_root.join("checkout_repositories") + autoload :SetupBindDnsKey, action_root.join("setup_bind_dns_key") + autoload :SetHostName, action_root.join("set_host_name") + autoload :YumUpdate, action_root.join("yum_update") + autoload :SetupBuilderFiles, action_root.join("setup_builder_files") + autoload :InstallBuildDependencies, action_root.join("install_build_dependencies") + autoload :PrepareSshConfig, action_root.join("prepare_ssh_config") + autoload :SyncLocalRepository, action_root.join("sync_local_repository") + autoload :BuildSources, action_root.join("build_sources") + autoload :LocalRepoCheckout, action_root.join("local_repo_checkout") + autoload :CreateBareRepoPlaceholders, action_root.join("create_bare_repo_placeholders") + autoload :CreateTestUsers, action_root.join("create_test_users") + autoload :IdleAllGears, action_root.join("idle_all_gears") + autoload :PreserveMcollectiveLogs, action_root.join("preserve_mcollective_logs") + autoload :RunTests, action_root.join("run_tests") + autoload :CheckoutTests, action_root.join("checkout_tests") + end + end +end diff --git a/lib/vagrant-openshift/action/build_sources.rb b/lib/vagrant-openshift/action/build_sources.rb new file mode 100644 index 00000000..ba448697 --- /dev/null +++ b/lib/vagrant-openshift/action/build_sources.rb @@ -0,0 +1,37 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class BuildSources + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + is_fedora = env[:machine].communicate.test("test -e /etc/fedora-release") + sudo(env[:machine], "cd #{Constants.build_dir + "builder"}; #{scl_wrapper(is_fedora,'rake update_packages')}", {timeout: 60*30}) + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/checkout_repositories.rb b/lib/vagrant-openshift/action/checkout_repositories.rb new file mode 100644 index 00000000..2444624f --- /dev/null +++ b/lib/vagrant-openshift/action/checkout_repositories.rb @@ -0,0 +1,44 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class CheckoutRepositories + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + git_clone_commands = "" + Constants.repos.each do |repo_name, url| + bare_repo_name = repo_name + "-bare" + bare_repo_path = Constants.build_dir + bare_repo_name + repo_path = Constants.build_dir + repo_name + + git_clone_commands += "rm -rf #{repo_path}; git clone #{bare_repo_path} #{repo_path}; " + end + do_execute env[:machine], git_clone_commands + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/checkout_tests.rb b/lib/vagrant-openshift/action/checkout_tests.rb new file mode 100644 index 00000000..02fb9ad9 --- /dev/null +++ b/lib/vagrant-openshift/action/checkout_tests.rb @@ -0,0 +1,35 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class CheckoutTests + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + sudo env[:machine], "cd #{Constants.build_dir}/builder; rake checkout_tests" + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/clean.rb b/lib/vagrant-openshift/action/clean.rb new file mode 100644 index 00000000..bf2b5494 --- /dev/null +++ b/lib/vagrant-openshift/action/clean.rb @@ -0,0 +1,48 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class Clean + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + is_fedora = env[:machine].communicate.test("test -e /etc/fedora-release") + + git_clone_commands = "" + Constants.repos.each do |repo_name, url| + bare_repo_name = repo_name + "-bare" + bare_repo_path = Constants.build_dir + bare_repo_name + git_clone_commands += "rm -rf #{bare_repo_path}; \n" + end + do_execute env[:machine], git_clone_commands + + sudo env[:machine], "rm -rf /etc/yum.repos.d/openshift-origin.repo" + sudo env[:machine], "rm -rf /var/cache/yum/x86_64/19/openshift-origin" #clear openshift package cache + sudo env[:machine], "cd #{Constants.build_dir + "builder; #{scl_wrapper(is_fedora,'rake clean_rpms')}"}" + sudo env[:machine], "rm -rf #{Constants.build_dir + "origin-rpms"} #{Constants.build_dir + ".built_packages"} #{Constants.build_dir + ".spec_cache"}" + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/clone_upstream_repositories.rb b/lib/vagrant-openshift/action/clone_upstream_repositories.rb new file mode 100644 index 00000000..f6cf5d93 --- /dev/null +++ b/lib/vagrant-openshift/action/clone_upstream_repositories.rb @@ -0,0 +1,55 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class CloneUpstreamRepositories + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + remote_write(env[:machine], "/root/.ssh/config", "root:root", "0600") { + %{Host github.com + StrictHostKeyChecking no + UserKnownHostsFile=/dev/null +}} + + git_clone_commands = "" + Constants.repos.each do |repo_name, url| + bare_repo_name = repo_name + "-bare" + bare_repo_path = Constants.build_dir + bare_repo_name + + git_clone_commands += "if [ ! -d #{bare_repo_path} ]; then\n" + git_clone_commands += "git clone --bare #{url} #{bare_repo_path};\n" + git_clone_commands += "fi\n" + end + + ssh_user = env[:machine].ssh_info[:username] + sudo(env[:machine], "mkdir -p #{Constants.build_dir}") + sudo(env[:machine], "mkdir -p #{Constants.build_dir + "builder"}; chown -R #{ssh_user}:#{ssh_user} #{Constants.build_dir};") + do_execute env[:machine], git_clone_commands + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/create_bare_repo_placeholders.rb b/lib/vagrant-openshift/action/create_bare_repo_placeholders.rb new file mode 100644 index 00000000..ef17e2f8 --- /dev/null +++ b/lib/vagrant-openshift/action/create_bare_repo_placeholders.rb @@ -0,0 +1,55 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class CreateBareRepoPlaceholders + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + remote_write(env[:machine], "/root/.ssh/config", "root:root", "0600") { + %{Host github.com + StrictHostKeyChecking no + UserKnownHostsFile=/dev/null +}} + + git_clone_commands = "" + Constants.repos.each do |repo_name, url| + bare_repo_name = repo_name + "-bare" + bare_repo_path = Constants.build_dir + bare_repo_name + + git_clone_commands += "if [ ! -d #{bare_repo_path} ]; then\n" + git_clone_commands += "git init --bare #{bare_repo_path};\n" + git_clone_commands += "fi\n" + end + + ssh_user = env[:machine].ssh_info[:username] + sudo(env[:machine], "mkdir -p #{Constants.build_dir}") + sudo(env[:machine], "mkdir -p #{Constants.build_dir + "builder"}; chown -R #{ssh_user}:#{ssh_user} #{Constants.build_dir};") + do_execute env[:machine], git_clone_commands + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/create_puppet_file.rb b/lib/vagrant-openshift/action/create_puppet_file.rb new file mode 100644 index 00000000..71b659b4 --- /dev/null +++ b/lib/vagrant-openshift/action/create_puppet_file.rb @@ -0,0 +1,71 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class CreatePuppetFile + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + hostname = env[:machine].config.vm.hostname + domain = env[:machine].config.openshift.cloud_domain + key,_ = sudo(env[:machine], "cat /var/named/K#{domain}.*.key") + key = key.first.strip.split(' ') + key = "#{key[6]}#{key[7]}" + + links,_ = sudo(env[:machine], "ip link") + links = links.map!{ |l| l.split("\n") }.flatten + + links.map! do |link| + m = link.match(/[0-9]+: ([a-z0-9]+):/) + m.nil?? "lo" : m[1] + end + links.delete "lo" + + remote_write(env[:machine], "#{Constants.build_dir}/configure_origin.pp") { + config = " +class { 'openshift_origin' : + node_fqdn => '#{hostname}', + mq_fqdn => '#{hostname}', + broker_fqdn => '#{hostname}', + cloud_domain => '#{domain}', + named_tsig_priv_key => '#{key}', + dns_servers => ['8.8.8.8'], + os_unmanaged_users => ['#{env[:machine].ssh_info[:username]}'], + install_repo => 'file://#{Constants.build_dir}/origin-rpms', + development_mode => true, + configure_cgroups => true, + eth_device => '#{links.first}', + node_container => '#{env[:machine].config.openshift.container}'\n" + env[:machine].config.openshift.advanced_puppet_values.each do |k,v| + config += %{ #{k} => #{v}\n} + end + config += "}" + config + } + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/create_test_users.rb b/lib/vagrant-openshift/action/create_test_users.rb new file mode 100644 index 00000000..7b9380c4 --- /dev/null +++ b/lib/vagrant-openshift/action/create_test_users.rb @@ -0,0 +1,35 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class CreateTestUsers + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + sudo env[:machine], "cd #{Constants.build_dir}/builder; rake create_test_users" + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/create_yum_repositories.rb b/lib/vagrant-openshift/action/create_yum_repositories.rb new file mode 100644 index 00000000..f0a7a111 --- /dev/null +++ b/lib/vagrant-openshift/action/create_yum_repositories.rb @@ -0,0 +1,106 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class CreateYumRepositories + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + is_fedora = env[:machine].communicate.test("test -e /etc/fedora-release") + + unless is_fedora + sudo env[:machine], "yum install -y http://mirror.pnl.gov/epel/6/i386/epel-release-6-8.noarch.rpm" + remote_write(env[:machine], "/etc/yum.repos.d/epel.repo") { + %{ +[epel] +name=Extra Packages for Enterprise Linux 6 - $basearch +#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch +exclude=*passenger* nodejs* +failovermethod=priority +enabled=1 +gpgcheck=1 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 + +[epel-debuginfo] +name=Extra Packages for Enterprise Linux 6 - $basearch - Debug +#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch +exclude=*passenger* nodejs* +failovermethod=priority +enabled=0 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 +gpgcheck=1 + +[epel-source] +name=Extra Packages for Enterprise Linux 6 - $basearch - Source +#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch +exclude=*passenger* nodejs* +failovermethod=priority +enabled=0 +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 +gpgcheck=1 + } + } + + remote_write(env[:machine], "/etc/yum.repos.d/puppet.repo") { + %{[puppet] +name=Puppet +baseurl=http://yum.puppetlabs.com/el/6/products/x86_64/ +enabled=1 +gpgcheck=0 +exclude=mcollective* + +[puppet-deps] +name=Puppet-Deps +baseurl=http://yum.puppetlabs.com/el/6/dependencies/x86_64/ +enabled=1 +gpgcheck=0}} + end + + if is_fedora + deps_mirror_url = "https://mirror.openshift.com/pub/origin-server/nightly/fedora-19/dependencies/x86_64/" + else + deps_mirror_url = "https://mirror.openshift.com/pub/origin-server/nightly/rhel-6/dependencies/x86_64/" + end + + remote_write(env[:machine], "/etc/yum.repos.d/openshift-origin-deps.repo") { + %{[openshift-origin-deps] +name=openshift-origin-deps +baseurl=#{deps_mirror_url} +gpgcheck=0 +enabled=1}} + + unless env[:machine].communicate.test("test -f /etc/yum.repos.d/jenkins.repo") + sudo(env[:machine], "yum install -y wget") + sudo(env[:machine], "wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo") + sudo(env[:machine], "rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key") + end + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/idle_all_gears.rb b/lib/vagrant-openshift/action/idle_all_gears.rb new file mode 100644 index 00000000..8e957da4 --- /dev/null +++ b/lib/vagrant-openshift/action/idle_all_gears.rb @@ -0,0 +1,35 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class IdleAllGears + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + sudo env[:machine], "cd #{Constants.build_dir}/builder; rake idle_all_gears" + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/install_build_dependencies.rb b/lib/vagrant-openshift/action/install_build_dependencies.rb new file mode 100644 index 00000000..88cb7d5d --- /dev/null +++ b/lib/vagrant-openshift/action/install_build_dependencies.rb @@ -0,0 +1,44 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class InstallBuildDependencies + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + sudo(env[:machine], "yum install -y puppet git tito yum-utils wget make tig mlocate bind augeas vim") + is_fedora = env[:machine].communicate.test("test -e /etc/fedora-release") + + if is_fedora + sudo(env[:machine], "yum install -y rubygem-rake") + else + sudo(env[:machine], "yum install -y ruby193-rubygem-rake ruby193-build scl-utils-build") + #test dependencies + sudo(env[:machine], "yum install -y ruby193-rubygem-net-ssh ruby193-rubygem-archive-tar-minitar ruby193-rubygem-fakefs ruby193-rubygem-httpclient") + end + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/install_open_shift_dependencies.rb b/lib/vagrant-openshift/action/install_open_shift_dependencies.rb new file mode 100644 index 00000000..aa742eda --- /dev/null +++ b/lib/vagrant-openshift/action/install_open_shift_dependencies.rb @@ -0,0 +1,48 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class InstallOpenShiftDependencies + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + is_fedora = env[:machine].communicate.test("test -e /etc/fedora-release") + + if is_fedora + unless env[:machine].communicate.test("rpm -q activemq-5.6.0-6.fc19.x86_64") + sudo(env[:machine], "yum erase -y activemq") + sudo(env[:machine], "yum install -y https://mirror.openshift.com/pub/origin-server/nightly/fedora-19/dependencies/x86_64/activemq-5.6.0-6.fc19.x86_64.rpm") + end + sudo(env[:machine], "yum install -y rubygem-rake") + else + sudo(env[:machine], "yum install -y activemq") + sudo(env[:machine], "yum install -y ruby193-rubygem-rake ruby193-build scl-utils-build") + end + + sudo(env[:machine], "cd #{Constants.build_dir + "builder"}; #{scl_wrapper(is_fedora, 'rake install_deps')}", {timeout: 0}) + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/local_repo_checkout.rb b/lib/vagrant-openshift/action/local_repo_checkout.rb new file mode 100644 index 00000000..a763d4e9 --- /dev/null +++ b/lib/vagrant-openshift/action/local_repo_checkout.rb @@ -0,0 +1,47 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class LocalRepoCheckout + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + Constants.repos.each do |repo, url| + unless Pathname.new(File.expand_path(repo)).exist? + if system("git clone git@github.com:#{env[:username]}/#{repo}") + Dir.chdir(repo) do + system("git remote add upstream #{url}; git fetch upstream") + end + else + @env.ui.warn "Fork of repo #{repo} not found. Cloning read-only copy from upstream" + system("git clone #{url}") + end + end + end + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/prepare_ssh_config.rb b/lib/vagrant-openshift/action/prepare_ssh_config.rb new file mode 100644 index 00000000..65f2dc17 --- /dev/null +++ b/lib/vagrant-openshift/action/prepare_ssh_config.rb @@ -0,0 +1,84 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class PrepareSshConfig + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + ssh_user = env[:machine].ssh_info[:username] + ssh_host = env[:machine].ssh_info[:host] + ssh_port = env[:machine].ssh_info[:port] + ssh_id_file = env[:machine].ssh_info[:private_key_path] + ssh_id = env[:machine].id.gsub("-","") + + ssh_config_path = Pathname.new(File.expand_path("~/.ssh/config")) + ssh_config_str = %{ +Host verifier + HostName #{ssh_host} + Port #{ssh_port} + User #{ssh_user} + IdentityFile #{ssh_id_file} + } + + if ssh_config_path.exist? + if system( "grep -n 'Host verifier' #{ssh_config_path}" ) + lines = File.new(ssh_config_path.to_s).readlines + idx = lines.index{ |l| l.match(/Host verifier/)} + lines.map!{ |line| line.rstrip } + + lines.delete_at(idx) + while(not (lines[idx].nil? or lines[idx].match(/Host /))) + lines.delete_at(idx) + end + + File.open(ssh_config_path.to_s, "w") do |file| + file.write(lines.join("\n")) + file.write(ssh_config_str) + end + else + File.open(ssh_config_path.to_s, "a") do |file| + file.write(ssh_config_str) + end + end + else + File.open(ssh_config_path.to_s, "w") do |file| + file.write(ssh_config_str) + end + FileUtils.chmod(0600, ssh_config_path.to_s) + end + + home_dir=File.join(ENV['HOME'], '.openshiftdev/home.d') + if File.exists?(home_dir) + Dir.glob(File.join(home_dir, '???*'), File::FNM_DOTMATCH).each {|file| + puts "Installing ~/#{File.basename(file)}" + system "scp #{file} verifier:" + } + end + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/preserve_mcollective_logs.rb b/lib/vagrant-openshift/action/preserve_mcollective_logs.rb new file mode 100644 index 00000000..32b3cb0e --- /dev/null +++ b/lib/vagrant-openshift/action/preserve_mcollective_logs.rb @@ -0,0 +1,40 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class PreserveMcollectiveLogs + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + unless env[:machine].communicate.test("grep 'keeplogs=9999' /etc/mcollective/server.cfg") + env[:machine].ui.info "Keep all mcollective logs on remote instance" + sudo(env[:machine], "echo keeplogs=9999 >> /etc/mcollective/server.cfg") + sudo(env[:machine], "/sbin/service mcollective restart") + end + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/run_tests.rb b/lib/vagrant-openshift/action/run_tests.rb new file mode 100644 index 00000000..3e64a153 --- /dev/null +++ b/lib/vagrant-openshift/action/run_tests.rb @@ -0,0 +1,46 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class RunTests + include CommandHelper + + @@SSH_TIMEOUT = 4800 + + def initialize(app, env, options) + @app = app + @env = env + @options = options + end + + def call(env) + cmd = "cd #{Constants.build_dir + 'builder'}; rake run_tests " + + @options.delete :help + @options.each do |k,v| + cmd += "#{k}=#{v} " + end + + sudo env[:machine], cmd, {timeout: 0} + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/set_host_name.rb b/lib/vagrant-openshift/action/set_host_name.rb new file mode 100644 index 00000000..0ba0fc6d --- /dev/null +++ b/lib/vagrant-openshift/action/set_host_name.rb @@ -0,0 +1,43 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class SetHostName + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + hostname = env[:machine].config.vm.hostname + remote_write(env[:machine], "/etc/sysconfig/network") { + "NETWORKING=yes\nNETWORKING_IPV6=no\nHOSTNAME=#{hostname}\n" + } + remote_write(env[:machine], "/etc/hostname") { + hostname + } + sudo(env[:machine],"restorecon -v /etc/sysconfig/network /etc/hostname") + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/setup_bind_dns_key.rb b/lib/vagrant-openshift/action/setup_bind_dns_key.rb new file mode 100644 index 00000000..66c3a0cf --- /dev/null +++ b/lib/vagrant-openshift/action/setup_bind_dns_key.rb @@ -0,0 +1,38 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class SetupBindDnsKey + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + domain = env[:machine].config.openshift.cloud_domain + + sudo(env[:machine], "rm -rf /var/named/K*.*.*") + sudo(env[:machine], "/usr/sbin/dnssec-keygen -a HMAC-MD5 -b 512 -n USER -r /dev/urandom -K /var/named #{domain}") + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/setup_builder_files.rb b/lib/vagrant-openshift/action/setup_builder_files.rb new file mode 100644 index 00000000..5b36b253 --- /dev/null +++ b/lib/vagrant-openshift/action/setup_builder_files.rb @@ -0,0 +1,57 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require 'yaml' + +module Vagrant + module Openshift + module Action + class SetupBuilderFiles + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + ssh_user = env[:machine].ssh_info[:username] + sudo(env[:machine], "rm -rf #{Constants.build_dir}") + sudo(env[:machine], "mkdir #{Constants.build_dir}") + sudo(env[:machine], "mkdir -p #{Constants.build_dir + "builder"}; chown #{ssh_user}:#{ssh_user} #{Constants.build_dir + "builder"};") + sudo(env[:machine], "mkdir -p #{Constants.build_dir}") + env[:machine].communicate.upload(File.expand_path("#{__FILE__}/../../templates/builder"), Constants.build_dir.to_s ) + env[:machine].communicate.upload(File.expand_path("#{__FILE__}/../../constants.rb"), (Constants.build_dir + "builder/lib/constants.rb").to_s ) + sudo(env[:machine], "chmod +x #{Constants.build_dir + "builder/yum-listbuilddep"}; chown #{ssh_user}:#{ssh_user} -R #{Constants.build_dir}") + remote_write(env[:machine], Constants.build_dir + "builder/lib/options.rb") do +%{ +require 'yaml' +OPTIONS = YAML.load( + "#{ + { + :ignore_packages => env[:machine].config.openshift.ignore_packages, + :cloud_domain => env[:machine].config.openshift.cloud_domain, + :additional_services => env[:machine].config.openshift.additional_services, + }.to_yaml}" + ) +} + end + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/sync_local_repository.rb b/lib/vagrant-openshift/action/sync_local_repository.rb new file mode 100644 index 00000000..67899817 --- /dev/null +++ b/lib/vagrant-openshift/action/sync_local_repository.rb @@ -0,0 +1,113 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class SyncLocalRepository + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + env[:machine].env.ui.info("Sync'ing local sources") + + Constants.repos.each do |repo_name, url| + local_repo = Pathname.new(File.expand_path(env[:machine].env.root_path + repo_name)) + unless local_repo.exist? + env[:machine].ui.warn "Missing local clone of repository #{local_repo}" + next + end + + FileUtils.cd(local_repo) do + sync_repo(env[:machine], repo_name) + end + end + + @app.call(env) + end + + private + + def sync_repo(machine, repo_name) + begin + temp_commit + + # Get the current branch + branch = get_branch + + puts "Synchronizing local changes from branch #{branch} for repo #{repo_name} from #{File.basename(FileUtils.pwd)}..." + + command = "" + command += "export GIT_SSH=#{Constants.git_ssh};\n" unless Constants.git_ssh.nil? or Constants.git_ssh.empty? + command += "git push -q verifier:#{Constants.build_dir + repo_name}-bare master:master --tags --force;\n" if branch == 'origin/master' + command += "git push -q verifier:#{Constants.build_dir + repo_name }-bare #{branch}:master --tags --force" + exitcode = system(command) + + puts "Done" + ensure + reset_temp_commit + end + end + + def temp_commit + # Warn on uncommitted changes + `git diff-index --quiet HEAD` + + if $? != 0 + # Perform a temporary commit + puts "Creating temporary commit to build" + + begin + `git commit -m "Temporary commit #1 - index changes"` + ensure + (@temp_commit ||= []).push("git reset --soft HEAD^") if $? == 0 + end + + begin + `git commit -a -m "Temporary commit #2 - non-index changes"` + ensure + (@temp_commit ||= []).push("git reset --mixed HEAD^") if $? == 0 + end + + puts @temp_commit ? "No-op" : "Done" + end + end + + def reset_temp_commit + if @temp_commit + puts "Undoing temporary commit..." + while undo = @temp_commit.pop + `#{undo}` + end + @temp_commit = nil + puts "Done." + end + end + + def get_branch + branch_str = `git status | head -n1`.chomp + branch_str =~ /.*branch (.*)/ + branch = $1 ? $1 : 'origin/master' + return branch + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/action/yum_update.rb b/lib/vagrant-openshift/action/yum_update.rb new file mode 100644 index 00000000..cebe5877 --- /dev/null +++ b/lib/vagrant-openshift/action/yum_update.rb @@ -0,0 +1,66 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + module Action + class YumUpdate + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + sudo env[:machine], "rm -rf /etc/yum.repos.d/openshift-origin.repo" + sudo env[:machine], "yum clean all; yum -y update --exclude=kernel*" + + env[:machine].ui.warn "Increasing YUM cache timeout to 9999999. You will need manually clear cache to get additonal updates." + remote_write(env[:machine], "/etc/yum.conf") { + %{ +[main] +cachedir=/var/cache/yum/$basearch/$releasever +keepcache=0 +debuglevel=2 +logfile=/var/log/yum.log +exactarch=1 +obsoletes=1 +gpgcheck=1 +plugins=1 +installonly_limit=3 + +# This is the default, if you make this bigger yum won't see if the metadata +# is newer on the remote and so you'll "gain" the bandwidth of not having to +# download the new metadata and "pay" for it by yum not having correct +# information. +# It is esp. important, to have correct metadata, for distributions like +# Fedora which don't keep old packages around. If you don't like this checking +# interupting your command line usage, it's much better to have something +# manually check the metadata once an hour (yum-updatesd will do this). +metadata_expire=9999999 + +# PUT YOUR REPOS HERE OR IN separate files named file.repo +# in /etc/yum.repos.d + } + } + + @app.call(env) + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/command/build_origin_base.rb b/lib/vagrant-openshift/command/build_origin_base.rb new file mode 100644 index 00000000..933ac90c --- /dev/null +++ b/lib/vagrant-openshift/command/build_origin_base.rb @@ -0,0 +1,46 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require_relative "../action" + +module Vagrant + module Openshift + module Commands + class BuildOriginBase < Vagrant.plugin(2, :command) + include CommandHelper + + def execute + options = {} + options[:clean] = false + options[:local_source] = false + + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant origin-build-base [vm-name]" + o.separator "" + end + + # Parse the options + argv = parse_options(opts) + + with_target_vms(argv, :reverse => true) do |machine| + actions = Vagrant::Openshift::Action.build_origin_base(options) + @env.action_runner.run actions, {:machine => machine} + 0 + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/command/local_repo_setup.rb b/lib/vagrant-openshift/command/local_repo_setup.rb new file mode 100644 index 00000000..3c090b65 --- /dev/null +++ b/lib/vagrant-openshift/command/local_repo_setup.rb @@ -0,0 +1,49 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require_relative "../action" + +module Vagrant + module Openshift + module Commands + class LocalRepoSetup < Vagrant.plugin(2, :command) + include CommandHelper + + def execute + options = {} + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant origin-local-checkout [github username]" + o.separator "" + + o.on("-h", "--help", "Show this message") do |f| + options[:help] = f + end + end + + # Parse the options + argv = parse_options(opts) + if options[:help] || argv.size == 0 + @env.ui.info opts + exit + end + + actions = Vagrant::Openshift::Action.local_repo_checkout(options) + @env.action_runner.run actions, {:username => argv[0]} + 0 + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/command/openshift_init.rb b/lib/vagrant-openshift/command/openshift_init.rb new file mode 100644 index 00000000..2a61c58b --- /dev/null +++ b/lib/vagrant-openshift/command/openshift_init.rb @@ -0,0 +1,98 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require 'yaml' + +module Vagrant + module Openshift + module Commands + class OpenshiftInit < Vagrant.plugin(2, :command) + include CommandHelper + + def execute + options = {} + options[:no_base] = false + options[:help] = false + options[:provider] = "virtualbox" + options[:os] = "fedora" + + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant origin-init [machine-name]" + o.separator "" + + o.on("-n", "--no-base", "Start from a scratch (clean operating system image) rather than a prebuilt base box") do |f| + options[:no_base] = true + end + + o.on("-o", "--os [name]", String, "Operating system: fedora (default)") do |f| + options[:os] = f + end + + o.on("-h", "--help", "Show this message") do |f| + options[:help] = f + end + end + + # Parse the options + argv = parse_options(opts) + + if options[:help] + @env.ui.info opts + exit + end + + template_path = Pathname.new(File.expand_path("#{__FILE__}/../../templates/command/init-openshift/Vagrantfile.erb")) + box_info_path = Pathname.new(File.expand_path("#{__FILE__}/../../templates/command/init-openshift/box_info.yaml")) + + box_info_data = YAML.load(File.new(box_info_path)) + box_info = box_info_data[options[:os].to_sym][(options[:no_base] ? :os : :base)] + + box_info[:aws][:machine_name] = argv[0] unless argv[0].nil? + aws_creds = Pathname.new(File.expand_path("~/.awscred")) + box_info[:aws][:aws_access_key_id] = "AWS ACCESS KEY" + box_info[:aws][:aws_secret_access_key] = "AWS SECRET KEY" + box_info[:aws][:aws_keypair_name] = "AWS KEYPAIR NAME" + box_info[:aws][:aws_private_key_path] = "PATH TO AWS KEYPAIR PRIVATE KEY" + + if aws_creds.exist? + @env.ui.info "Reading aws credentials from #{aws_creds}" + File.open(aws_creds.to_s) do |file| + file.readlines.each do |line| + line = line.strip.split("=") + case line[0] + when "AWSAccessKeyId" + box_info[:aws][:aws_access_key_id] = line[1] + when "AWSSecretKey" + box_info[:aws][:aws_secret_access_key] = line[1] + when "AWSKeyPairName" + box_info[:aws][:aws_keypair_name] = line[1] + when "AWSPrivateKeyPath" + box_info[:aws][:aws_private_key_path] = line[1] + end + end + end + end + box_info[:os] = options[:os].to_sym + + contents = Vagrant::Util::TemplateRenderer.render(template_path.to_s[0..-5], box_info: box_info) + File.open("Vagrantfile", "w+") do |f| + f.write(contents) + end + 0 + end + end + end + end +end diff --git a/lib/vagrant-openshift/command/repo_sync.rb b/lib/vagrant-openshift/command/repo_sync.rb new file mode 100644 index 00000000..4fa8788e --- /dev/null +++ b/lib/vagrant-openshift/command/repo_sync.rb @@ -0,0 +1,72 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require_relative "../action" + +module Vagrant + module Openshift + module Commands + class RepoSync < Vagrant.plugin(2, :command) + include CommandHelper + + def execute + options = {} + options[:clean] = false + options[:local_source] = true + options[:no_build] = false + options[:deps] = false + + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant sync [vm-name]" + o.separator "" + + o.on("-c", "--clean", "Delete existing repo and uninstall all OpenShift RPMs before syncing") do |f| + options[:clean] = f + end + + o.on("-u", "--upstream", "Build base VM based on local source") do |f| + options[:local_source] = false + end + + o.on("--install-deps", "Install any missing dependencies") do |f| + options[:deps] = f + end + + o.on("-d", "--dont-install", "Dont build and install RPMs") do |f| + options[:no_build] = f + end + + o.on("-h", "--help", "Show this message") do |f| + options[:help] = f + end + end + + # Parse the options + argv = parse_options(opts) + with_target_vms(argv, :reverse => true) do |machine| + if options[:help] + machine.env.ui.info opts + exit + end + + actions = Vagrant::Openshift::Action.repo_sync(options) + @env.action_runner.run actions, {:machine => machine} + 0 + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/command/test.rb b/lib/vagrant-openshift/command/test.rb new file mode 100644 index 00000000..d6f75760 --- /dev/null +++ b/lib/vagrant-openshift/command/test.rb @@ -0,0 +1,83 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require_relative "../action" + +module Vagrant + module Openshift + module Commands + class Test < Vagrant.plugin(2, :command) + include CommandHelper + + def execute + options = {} + options[:help] = false + options[:node] = false + options[:broker] = false + options[:rhc] = false + options[:console] = false + options[:extended] = false + + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant test [machine-name]" + o.separator "" + + o.on("-n", "--node", String, "Run node tests") do |f| + options[:node] = true + end + + o.on("-b", "--broker", String, "Run broker tests") do |f| + options[:broker] = true + end + + o.on("-r", "--rhc", String, "Run CLI tests") do |f| + options[:rhc] = true + end + + o.on("-c", "--console", String, "Run console/web tests") do |f| + options[:console] = true + end + + o.on("-e", "--extended", String, "Run extended tests") do |f| + options[:extended] = true + end + + o.on("-a", "--all", String, "Run all tests") do |f| + options[:node] = options[:broker] = options[:console] = options[:rhc] = true + end + + o.on("-h", "--help", "Show this message") do |f| + options[:help] = true + end + end + + # Parse the options + argv = parse_options(opts) + + if options[:help] + @env.ui.info opts + exit + end + + with_target_vms(argv, :reverse => true) do |machine| + actions = Vagrant::Openshift::Action.run_tests(options) + @env.action_runner.run actions, {:machine => machine} + 0 + end + end + end + end + end +end diff --git a/lib/vagrant-openshift/commands/build_origin_base.rb b/lib/vagrant-openshift/commands/build_origin_base.rb deleted file mode 100644 index 06fd2b00..00000000 --- a/lib/vagrant-openshift/commands/build_origin_base.rb +++ /dev/null @@ -1,111 +0,0 @@ -#-- -# Copyright 2013 Red Hat, Inc. -# -# 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. -#++ - -module Vagrant - module Openshift - module Commands - class BuildOriginBase < Vagrant.plugin(2, :command) - include CommandHelper - - def execute - options = {} - options[:force] = false - options[:local_source] = false - - opts = OptionParser.new do |o| - o.banner = "Usage: vagrant build-origin-base [vm-name]" - o.separator "" - - o.on("-f", "--force", "Delete existing repo before syncing") do |f| - options[:force] = f - end - - o.on("-l", "--local-source", "Build base VM based on local source") do |f| - options[:local_source] = f - end - end - - # Parse the options - argv = parse_options(opts) - - with_target_vms(argv, :reverse => true) do |machine| - sudo machine, "yum -y update" - sudo machine, "yum erase -y epel-release activemq" - is_fedora = machine.communicate.test("test -e /etc/fedora-release") - - unless is_fedora - sudo(machine, "yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm") - remote_write(machine, "/etc/yum.repos.d/puppet.repo") { -%{[puppet] -name=Puppet -baseurl=http://yum.puppetlabs.com/el/6/products/x86_64/ -enabled=1 -gpgcheck=0 -exclude=mcollective* - -[puppet-deps] -name=Puppet-Deps -baseurl=http://yum.puppetlabs.com/el/6/dependencies/x86_64/ -enabled=1 -gpgcheck=0}} - end - - sudo(machine, "yum install -y puppet git tito yum-utils wget make tig mlocate") - deps_mirror_url = nil - if is_fedora - sudo(machine, "yum install -y rubygem-rake https://mirror.openshift.com/pub/origin-server/nightly/fedora-19/dependencies/x86_64/activemq-5.6.0-6.fc19.x86_64.rpm") - deps_mirror_url = "https://mirror.openshift.com/pub/origin-server/nightly/fedora-19/dependencies/x86_64/" - else - sudo(machine, "yum install -y ruby193-rubygem-rake https://mirror.openshift.com/pub/origin-server/nightly/rhel-6/dependencies/x86_64/activemq-5.6.0-6.fc19.x86_64.rpm") - deps_mirror_url = "https://mirror.openshift.com/pub/origin-server/nightly/rhel-6/dependencies/x86_64/" - end - - remote_write(machine, "/etc/yum.repos.d/openshift-origin-deps.repo") { -%{[openshift-origin-deps] -name=openshift-origin-deps -baseurl=#{deps_mirror_url} -gpgcheck=0 -enabled=1}} - - sudo(machine, "wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo") - sudo(machine, "rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key") - - remote_write(machine, "/root/.ssh/config", "root:root", "0600") { -%{Host github.com - StrictHostKeyChecking no - UserKnownHostsFile=/dev/null -}} - - ssh_user = machine.ssh_info[:username] - sudo(machine, "mkdir -p #{Constants.build_dir}") - machine.communicate.upload(File.expand_path("#{__FILE__}/../../../../builder"), Constants.build_dir.to_s ) - machine.communicate.upload(File.expand_path("#{__FILE__}/../../constants.rb"), (Constants.build_dir + "builder/lib/constants.rb").to_s ) - sudo(machine, "chmod +x #{Constants.build_dir + "builder/yum-listbuilddep"}; chown #{ssh_user}:#{ssh_user} -R #{Constants.build_dir}") - - require_relative "repo_sync" - sync_args = [] - sync_args << "-f" if options[:force] - sync_args << "-l" if options[:local_source] - RepoSync.new(sync_args, @env).execute - - sudo(machine, "cd #{Constants.build_dir + "builder"}; rake openshift:install_deps") - 0 - end - end - end - end - end -end \ No newline at end of file diff --git a/lib/vagrant-openshift/commands/repo_sync.rb b/lib/vagrant-openshift/commands/repo_sync.rb deleted file mode 100644 index f1003bc5..00000000 --- a/lib/vagrant-openshift/commands/repo_sync.rb +++ /dev/null @@ -1,176 +0,0 @@ -#-- -# Copyright 2013 Red Hat, Inc. -# -# 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. -#++ - -module Vagrant - module Openshift - module Commands - class RepoSync < Vagrant.plugin(2, :command) - include CommandHelper - - def execute - options = {} - options[:force] = false - options[:local_source] = false - - opts = OptionParser.new do |o| - o.banner = "Usage: vagrant reposync [vm-name]" - o.separator "" - - o.on("-f", "--force", "Delete existing repo before syncing") do |f| - options[:force] = f - end - - o.on("-l", "--local-source", "Build base VM based on local source") do |f| - options[:local_source] = f - end - end - - # Parse the options - argv = parse_options(opts) - - with_target_vms(argv, :reverse => true) do |machine| - machine.env.ui.info("Initializing repos from github.com") - init_repos(machine, options) - - if options[:local_source] - machine.env.ui.info("Sync'ing local sources") - sync_repos(machine) - end - - machine.env.ui.info("Checking out repos on build machine") - checkout_repos(machine) - - 0 - end - end - - private - - def checkout_repos(machine) - checkout_commands = "" - Constants.repos.each do |repo_name, url| - bare_repo_name = repo_name + "-bare" - bare_repo_path = Constants.build_dir + bare_repo_name - repo_path = Constants.build_dir + repo_name - - checkout_commands += "rm -rf #{repo_path}; git clone #{bare_repo_path} #{repo_path}; " - #checkout_commands += "pushd #{repo_name}; git checkout #{options.branch}; popd; " - end - - sudo machine, checkout_commands - end - - def init_repos(machine, options) - git_clone_commands = "" - Constants.repos.each do |repo_name, url| - bare_repo_name = repo_name + "-bare" - bare_repo_path = Constants.build_dir + bare_repo_name - - git_clone_commands += "if [ ! -d #{bare_repo_path} ]; then\n" unless options[:force] - git_clone_commands += "rm -rf #{bare_repo_path}; git clone --bare #{url} #{bare_repo_path};\n" - git_clone_commands += "fi\n" unless options[:force] - end - - sudo machine, git_clone_commands - end - - def sync_repos(machine) - Constants.repos.each do |repo_name, url| - local_repo = Pathname.new(File.expand_path(repo_name)) - require 'pry'; binding.pry; - raise "Missing local clone of repository #{local_repo}" unless local_repo.exist? - - FileUtils.cd(repo_name) do - sync_repo(machine, repo_name) - end - end - end - - def sync_repo(machine, repo_name) - begin - temp_commit - - # Get the current branch - branch = get_branch - - puts "Synchronizing local changes from branch #{branch} for repo #{repo_name} from #{File.basename(FileUtils.pwd)}..." - - ssh_user = machine.ssh_info[:username] - ssh_host = machine.ssh_info[:hostname] - ssh_port = machine.ssh_info[:port] - - exitcode = system(<<-"SHELL", :verbose => verbose) - ####### - # Start shell code - export GIT_SSH=#{Constants.git_ssh} - #{branch == 'origin/master' ? "git push -q #{ssh_user}@#{hostname}:#{remote_repo_parent_dir}/#{repo_name}-bare master:master --tags --force; " : ''} - git push -q #{ssh_user}@#{hostname}:#{remote_repo_parent_dir}/#{repo_name}-bare #{branch}:master --tags --force - - ####### - # End shell code - SHELL - - puts "Done" - ensure - reset_temp_commit - end - end - - def temp_commit - # Warn on uncommitted changes - `git diff-index --quiet HEAD` - - if $? != 0 - # Perform a temporary commit - puts "Creating temporary commit to build" - - begin - `git commit -m "Temporary commit #1 - index changes"` - ensure - (@temp_commit ||= []).push("git reset --soft HEAD^") if $? == 0 - end - - begin - `git commit -a -m "Temporary commit #2 - non-index changes"` - ensure - (@temp_commit ||= []).push("git reset --mixed HEAD^") if $? == 0 - end - - puts @temp_commit ? "No-op" : "Done" - end - end - - def reset_temp_commit - if @temp_commit - puts "Undoing temporary commit..." - while undo = @temp_commit.pop - `#{undo}` - end - @temp_commit = nil - puts "Done." - end - end - - def get_branch - branch_str = `git status | head -n1`.chomp - branch_str =~ /.*branch (.*)/ - branch = $1 ? $1 : 'origin/master' - return branch - end - end - end - end -end \ No newline at end of file diff --git a/lib/vagrant-openshift/config.rb b/lib/vagrant-openshift/config.rb new file mode 100644 index 00000000..63a8606d --- /dev/null +++ b/lib/vagrant-openshift/config.rb @@ -0,0 +1,41 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + class Config < Vagrant.plugin(2, :config) + attr_accessor :cloud_domain, :ignore_packages, :additional_services, :container, + :advanced_puppet_values + + def initialize + @ignore_packages = UNSET_VALUE + @cloud_domain = UNSET_VALUE + @additional_services = UNSET_VALUE + @container = UNSET_VALUE + @advanced_puppet_values = UNSET_VALUE + end + + def finalize! + @ignore_packages = [] if @ignore_packages == UNSET_VALUE + @cloud_domain = "example.com" if @cloud_domain == UNSET_VALUE + @additional_services = [] if @additional_services == UNSET_VALUE + @container = "selinux" if @container == UNSET_VALUE + @advanced_puppet_values = {} if @advanced_puppet_values == UNSET_VALUE + end + end + end +end + diff --git a/lib/vagrant-openshift/constants.rb b/lib/vagrant-openshift/constants.rb index 741ee4d5..82266c27 100644 --- a/lib/vagrant-openshift/constants.rb +++ b/lib/vagrant-openshift/constants.rb @@ -22,7 +22,6 @@ def self.repos { 'origin-server' => 'https://github.com/openshift/origin-server.git', 'rhc' => 'https://github.com/openshift/rhc.git', - #'origin-dev-tools' => 'https://github.com/openshift/origin-dev-tools.git', 'puppet-openshift_origin' => 'https://github.com/openshift/puppet-openshift_origin.git' } end @@ -31,9 +30,30 @@ def self.build_dir Pathname.new "/data" end - def git_ssh + def self.git_ssh "" end + + def self.restart_services_cmd + services = [ 'mongod', 'mcollective', 'activemq', 'cgconfig', 'cgred', 'named', + 'openshift-broker', 'openshift-console', 'openshift-node-web-proxy', + 'sshd', 'httpd' ] + cmd = [] + cmd += services.map do |service| + "/sbin/service #{service} stop;" + end + cmd += services.map do |service| + "/sbin/service #{service} start;" + end + cmd << "rm -rf /var/www/openshift/broker/tmp/cache/*;" + cmd << "/etc/cron.minutely/openshift-facts;" + cmd << "/sbin/service openshift-tc reload;" + cmd << "/sbin/service network restart;" + cmd << "/sbin/service messagebus restart;" + cmd << "/sbin/service oddjobd restart;" + + cmd + end end end end \ No newline at end of file diff --git a/lib/vagrant-openshift/helper/command_helper.rb b/lib/vagrant-openshift/helper/command_helper.rb new file mode 100644 index 00000000..c5b32b0e --- /dev/null +++ b/lib/vagrant-openshift/helper/command_helper.rb @@ -0,0 +1,101 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require "tempfile" +require "timeout" + +module Vagrant + module Openshift + module CommandHelper + def scl_wrapper(is_fedora, command) + is_fedora ? command : %{scl enable ruby193 "#{command}"} + end + + def sudo(machine, command, options={}) + stdout = [] + stderr = [] + rc = -1 + options[:timeout] ||= 60*10 + options[:retries] ||= 1 + + (1..options[:retries]).each do |retry_count| + begin + machine.env.ui.info "Running ssh/sudo command '#{command}' with timeout #{options[:timeout]}. Attempt ##{retry_count}" + Timeout::timeout(options[:timeout]) do + rc = machine.communicate.sudo(command) do |type, data| + if [:stderr, :stdout].include?(type) + if type == :stdout + color = :green + stdout << data + else + color = :red + stderr << data + end + machine.env.ui.info(data, :color => color, :new_line => false, :prefix => false) unless options[:buffered_output] == true + end + end + end + rescue Timeout::Error + machine.env.ui.warn "Timeout occured while running ssh/sudo command: #{command}" + rc = -1 + end + + break if rc == 0 + end + + [stdout, stderr, rc] + end + + def do_execute(machine, command) + stdout = [] + stderr = [] + rc = -1 + + rc = machine.communicate.execute(command) do |type, data| + if [:stderr, :stdout].include?(type) + if type == :stdout + color = :green + stdout << data + else + color = :red + stderr << data + end + machine.env.ui.info(data, :color => color, :new_line => false, :prefix => false) + end + end + + [stdout, stderr, rc] + end + + def remote_write(machine, dest, owner="root", perms="0644", &block) + file = Tempfile.new('file') + begin + file.write(block.yield) + file.flush + file.close + machine.communicate.upload(file.path, "/tmp/#{File.basename(file)}") + dest_dir = File.dirname(dest) + sudo(machine, +%{mkdir -p #{dest_dir}; +mv /tmp/#{File.basename(file)} #{dest} && +chown #{owner} #{dest} && +chmod #{perms} #{dest}}) + ensure + file.unlink + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/helpers/command_helper.rb b/lib/vagrant-openshift/helpers/command_helper.rb deleted file mode 100644 index f6a71920..00000000 --- a/lib/vagrant-openshift/helpers/command_helper.rb +++ /dev/null @@ -1,48 +0,0 @@ -#-- -# Copyright 2013 Red Hat, Inc. -# -# 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. -#++ - -module Vagrant - module Openshift - module CommandHelper - def sudo(machine, command) - machine.communicate.sudo(command) do |type, data| - if [:stderr, :stdout].include?(type) - color = type == :stdout ? :green : :red - machine.env.ui.info(data, :color => color, :new_line => false, :prefix => false) - end - end - end - - def remote_write(machine, dest, owner="root", perms="0644", &block) - file = Tempfile.new('file') - begin - file.write(block.yield) - file.flush - file.close - machine.communicate.upload(file.path, "/tmp/#{File.basename(file)}") - dest_dir = File.dirname(dest) - sudo(machine, -%{mkdir -p #{dest_dir}; -mv /tmp/#{File.basename(file)} #{dest} && -chown #{owner} #{dest} && -chmod #{perms} #{dest}}) - ensure - file.unlink - end - end - end - end -end \ No newline at end of file diff --git a/lib/vagrant-openshift/plugin.rb b/lib/vagrant-openshift/plugin.rb index f3e3649b..de041bd3 100644 --- a/lib/vagrant-openshift/plugin.rb +++ b/lib/vagrant-openshift/plugin.rb @@ -22,17 +22,40 @@ class Plugin < Vagrant.plugin("2") Plugin to build and manage OpenShift Origin environments } - command "reposync" do - require_relative "commands/repo_sync" + command "sync" do + require_relative "command/repo_sync" Commands::RepoSync end - command "build-origin-base" do - require_relative "commands/build_origin_base" + command "origin-build-base" do + require_relative "command/build_origin_base" Commands::BuildOriginBase end + command "origin-init" do + require_relative "command/openshift_init" + Commands::OpenshiftInit + end + + command "origin-local-checkout" do + require_relative "command/local_repo_setup" + Commands::LocalRepoSetup + end + + command "test" do + require_relative "command/test" + Commands::Test + end + + config "openshift" do + require_relative "config" + Config + end + provisioner "openshift" do + require_relative "provisioner" + Provisioner + end end end end \ No newline at end of file diff --git a/lib/vagrant-openshift/provisioner.rb b/lib/vagrant-openshift/provisioner.rb new file mode 100644 index 00000000..b5cb6c06 --- /dev/null +++ b/lib/vagrant-openshift/provisioner.rb @@ -0,0 +1,63 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +module Vagrant + module Openshift + class Provisioner < Vagrant.plugin(2, :provisioner) + include CommandHelper + + # Called with the root configuration of the machine so the provisioner + # can add some configuration on top of the machine. + # + # During this step, and this step only, the provisioner should modify + # the root machine configuration to add any additional features it + # may need. Examples include sharing folders, networking, and so on. + # This step is guaranteed to be called before any of those steps are + # done so the provisioner may do that. + # + # No return value is expected. + def configure(root_config) + + end + + # This is the method called when the actual provisioning should be + # done. The communicator is guaranteed to be ready at this point, + # and any shared folders or networks are already setup. + # + # No return value is expected. + def provision + #check if OpenShift has been installed + #reapply puppet configuration so that IPs and ifcfg-* file is correct + if @machine.communicate.test("test -d /etc/openshift") + @machine.ui.info("Reapplying puppet script to update changed IP values") + sudo(machine,"puppet apply --verbose #{Vagrant::Openshift::Constants.build_dir + 'configure_origin.pp'}") + sudo(machine,Constants.restart_services_cmd.join("\n")) + if @machine.config.openshift.additional_services.size > 0 + cmd = "" + @machine.config.openshift.additional_services.each do |service| + cmd += "service #{service} restart;" + end + sudo(machine,cmd) + end + else + @machine.ui.info("Preparing base environment") + require_relative "command/build_origin_base" + Vagrant::Openshift::Commands::BuildOriginBase.new([], @machine.env).execute + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/templates/builder/Rakefile b/lib/vagrant-openshift/templates/builder/Rakefile new file mode 100644 index 00000000..4a1e5704 --- /dev/null +++ b/lib/vagrant-openshift/templates/builder/Rakefile @@ -0,0 +1,189 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ + +require 'rubygems' +require 'pathname' +require 'yaml' +require 'tsort' +require_relative 'lib/constants' +require_relative 'lib/options' +require_relative 'lib/rpm' +require_relative 'lib/test' +$stdout.sync = true +$stderr.sync = true + +task :install_deps do + spec_files = RPM::get_packages(ignore_packages: OPTIONS[:ignore_packages], ignore_cache: true) + + all_build_dependencies = [] + all_inst_dependencies = [] + spec_files.each do |spec| + all_build_dependencies += spec[:build_deps] + all_inst_dependencies += spec[:deps] + end + + all_packages = all_build_dependencies + all_inst_dependencies + + all_packages.map! do |name| + m = name.match(/(ruby193-)?rubygem[(]([a-z\-_]*)[)]/) + if m.nil? + name.strip + else + scl_prefix = m[1].nil? ? "" : m[1] + "#{scl_prefix}rubygem-#{m[2]}".strip + end + end + + all_packages.delete_if { |name| name.match(/openshift/)} + + RPM::install_rpms(all_packages) +end + +task :build_all do + FileUtils.rm_rf("/tmp/tito/*") + spec_files = RPM::get_packages(remove_os_build_deps: true, ignore_packages: OPTIONS[:ignore_packages], ignore_cache: true) + RPM::build_packages(spec_files) +end + +task :clean_rpms do + FileUtils.rm_rf("/tmp/tito/*") + RPM::uninstall_openshift +end + +task :install_puppet do + Dir.chdir((Vagrant::Openshift::Constants.build_dir + "puppet-openshift_origin").to_s) do + FileUtils.rm_rf "pkg" + system("puppet module build") + pkg = Dir.glob((Vagrant::Openshift::Constants.build_dir + "puppet-openshift_origin/pkg/openshift-openshift_origin*.tar.gz").to_s).first + system("puppet module uninstall openshift-openshift_origin") + system("puppet module install #{pkg}") + system("rm -rf #{Vagrant::Openshift::Constants.build_dir + "puppet-openshift_origin/pkg"}") + end +end + +task :update_packages do + if (Vagrant::Openshift::Constants.build_dir + ".built_packages").exist? + print "Updating packages\n" + RPM::updated_packages + else + print "Building all packages\n" + Rake::Task['build_all'].invoke + print "Installing openshift puppet module\n" + Rake::Task['install_puppet'].invoke + print "Applying openshift puppet recipe\n" + system("puppet apply --verbose #{Vagrant::Openshift::Constants.build_dir + 'configure_origin.pp'}") + end + Rake::Task['restart_services'].invoke +end + +task :restart_services do + system(Vagrant::Openshift::Constants.restart_services_cmd.join("\n")) + cmd = "" + OPTIONS[:additional_services].each do |service| + cmd += "service #{service} restart;" + end + system(cmd) + + unless system("service openshift-tc status 2>/dev/null 1>/dev/null") + system("service openshift-tc start") + end +end + +task :checkout_tests do + print "Updating remote tests..." + system "rm -rf #{Vagrant::Openshift::Constants.build_dir}/openshift-test" + git_archive_commands = '' + Vagrant::Openshift::Constants.repos.each do |repo_name, url| + repo_dir = "#{Vagrant::Openshift::Constants.build_dir}/#{repo_name}-bare" + 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; " + end + 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; " + + system %{ +set -e; +sudo bash -c \"rm -rf #{Vagrant::Openshift::Constants.build_dir}/openshift-test\" +#{git_archive_commands} +sudo bash -c \"mkdir -p /tmp/rhc/junit\" + } + + system(%{ +rm -f #{Vagrant::Openshift::Constants.build_dir}/openshift-test/tests; +ln -s #{Vagrant::Openshift::Constants.build_dir}/openshift-test/controller/test/cucumber #{Vagrant::Openshift::Constants.build_dir}/openshift-test/tests +}) + print "done\n" +end + +task :create_test_users do + ['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| + unless system("/usr/bin/curl -f -k https://broker.example.com/broker/rest/user -u #{user}:test 2>/dev/null 1>/dev/null") + print "Creating test user: #{user}\n" + exitcode = system("/usr/bin/oo-register-user -l admin -p admin --username #{user} --userpass test") + if (!exitcode) || (! system("/usr/bin/curl -f -k https://broker.example.com/broker/rest/user -u #{user}:test 2>/dev/null 1>/dev/null")) + print "Unable to create #{user}\n" + exit 1 + end + else + print "#{user} already exists\n" + end + end + + # Create a known test user with medium-sized gears + # This must be done before the deployment of application templates! + exitcode = system("/usr/sbin/oo-admin-ctl-user -l user_with_multiple_gear_sizes@test.com --addgearsize medium") + if(!exitcode) + print "Unable to assign medium gear capability to user_with_multiple_gear_sizes@test.com" + exit 1 + end + + # Create a test user with additional storage capabilities + exitcode = system("/usr/sbin/oo-admin-ctl-user -l user_with_extra_storage@test.com --setmaxuntrackedstorage 5 --setmaxgears 10") + if(!exitcode) + print "Unable to assign additional storage to user_with_extra_storage@test.com" + exit 1 + end + + # Create a test user with ssl certificates capabilities + exitcode = system("/usr/sbin/oo-admin-ctl-user -l user_with_certificate_capabilities@test.com --allowprivatesslcertificates true") + if(!exitcode) + print "Unable to assign ssl certificates capabilities to user_with_certificate_capabilities@test.com" + exit 1 + end + + unless system("test -e /root/.ssh/id_rsa") + system("ssh-keygen -q -f /root/.ssh/id_rsa -P \"\" &1 1>/dev/null" } + is_spec_bad = false + if is_tagged + begin + spec[:build_deps] = YAML.load(`./yum-listbuilddep #{spec[:path]}`.split("\n").last) + raise "Bad spec" if spec[:build_deps].class == Hash + spec[:deps] = `rpm -q --specfile --requires #{spec[:path]}`.split("\n") + rescue Exception => e + next true + end + else + puts "\n\nSkipping '#{spec[:name]}' in '#{spec[:dir]}' since it is not tagged.\n" + next true + end + + options.has_key?(:ignore_packages) && options[:ignore_packages].include?(spec[:name]) + end + + if(options.has_key?(:remove_os_build_deps) && options[:remove_os_build_deps]) + #remove deps provided by OS and keep only the ones that will be built from source + spec_files.each do |spec| + spec[:build_deps].delete_if{ |dep| not source_package_names.include? dep } + end + end + + File.open(spec_cache.to_s, "w") do |file| + file.write(spec_files.to_yaml) + end + + spec_files + end + + def self.install_rpms(list) + print "Installing #{list.size} in chunks of 20 packages" + list.uniq.each_slice(20) do |sub_list| + system %{yum install -y --skip-broken "#{sub_list.join('" "')}"} + end + end + + def self.uninstall_openshift + #undo pam.d sshd modification + if system("grep -n 'pam_openshift' /etc/pam.d/sshd") + file = Tempfile.new('temp') + begin + file.write(%{ +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' +ins 01 before /files/etc/pam.d/sshd/*[argument='close'] +set /files/etc/pam.d/sshd/01/type session +set /files/etc/pam.d/sshd/01/control required +set /files/etc/pam.d/sshd/01/module pam_selinux.so +set /files/etc/pam.d/sshd/01/argument close + +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' +ins 02 before /files/etc/pam.d/sshd/*[argument='open'] +set /files/etc/pam.d/sshd/02/type session +set /files/etc/pam.d/sshd/02/control required +set /files/etc/pam.d/sshd/02/module pam_selinux.so +set /files/etc/pam.d/sshd/02/argument[1] open +set /files/etc/pam.d/sshd/02/argument[2] env_params + +rm /files/etc/pam.d/sshd/*[module='pam_openshift.so'] +rm /files/etc/pam.d/sshd/*[module='pam_namespace.so'] +rm /files/etc/pam.d/sshd/*[module='pam_cgroup.so'] +save + }) + file.close + system("augtool --file #{file.path}") + ensure + file.unlink + end + end + FileUtils.rm_rf("/etc/openshift") + + get_packages(ignore_cache: true).each_slice(10) do |spec_files_list| + sub_list = spec_files_list.map {|s| s[:name] } + system %{yum erase -y "#{sub_list.join('" "')}"} + end + end + + def self.build_packages(spec_files, opts={}) + built_specs = [] + + FileUtils.mkdir_p "/tmp/tito/noarch/" + FileUtils.mkdir_p (Vagrant::Openshift::Constants.build_dir + "origin-rpms").to_s + (1..3).each do |phase| + print "Build phase #{phase}\n" + buildable = [] + + #install pre reqs if thet have already been built + spec_files.each do |spec| + spec[:build_deps].delete_if do |dep| + if opts[:assume_deps_built] || built_specs.map{ |s| s[:name] }.include?(dep) + puts "\n Installing...#{dep}" + raise "Unable to install package #{package.name}" unless system("rpm -Uvh --force /tmp/tito/noarch/#{dep}*.rpm") + true + else + false + end + end + end + + buildable = spec_files.select{ |spec| spec[:build_deps].size == 0 } + + buildable.each do |spec| + Dir.chdir(spec[:dir]) do + puts "\n#{'-'*60}" + system "rm -f /tmp/tito/noarch/#{spec[:name]}*.rpm" + raise "Unable to build #{spec[:name]}" unless system("tito build --rpm --test") + + Dir.glob('/tmp/tito/x86_64/*.rpm').each {|file| + FileUtils.mv file, "/tmp/tito/noarch/" + } + Dir.glob("/tmp/tito/noarch/#{spec[:name]}*.rpm").each do |file| + FileUtils.cp file, (Vagrant::Openshift::Constants.build_dir + "origin-rpms/").to_s + end + + built_specs << spec + spec_files.delete(spec) + end + end + end + + File.open((Vagrant::Openshift::Constants.build_dir + ".built_packages").to_s, "w") do |file| + file.write(tito_report.to_yaml) + end + + print "Updating local repo for built sources" + Dir.chdir((Vagrant::Openshift::Constants.build_dir + "origin-rpms/").to_s) do + system("createrepo .") + system("yum clean all") + end + + built_specs + end + + def self.updated_packages + spec_files = get_updated_packages + built_packages = build_packages(spec_files, {assume_deps_built: true}) + built_packages.each do |spec| + unless system("rpm -Uvh --force #{Vagrant::Openshift::Constants.build_dir + "origin-rpms"}/#{spec[:name]}*.rpm") + unless system("rpm -e --justdb --nodeps #{spec[:name]}; yum install -y #{Vagrant::Openshift::Constants.build_dir + "origin-rpms"}/#{spec[:name]}*.rpm") + print "Unable to install updated package #{spec[:name]}" + exit 1 + end + end + end + end + + private + + def self.get_updated_packages + raise "Please perform full build with 'rake openshift:build_all' before running sync" unless (Vagrant::Openshift::Constants.build_dir + ".built_packages").exist? + + spec_files = get_packages(remove_os_build_deps: true) + cur_report = tito_report + old_report = YAML.load(File.new((Vagrant::Openshift::Constants.build_dir + ".built_packages").to_s)) + + updated_packages = [] + spec_files.each do |spec| + cur_package_report = cur_report[spec[:name]] + old_package_report = old_report[spec[:name]] + + if (old_package_report.nil? && !cur_package_report.nil?) || + (!cur_package_report.nil? && cur_package_report[:version] != old_package_report[:version]) || + (!cur_package_report.nil? && cur_package_report[:untagged_revisions] != old_package_report[:untagged_revisions]) + updated_packages << spec unless OPTIONS[:ignore_packages].include?(spec[:name]) + end + end + + updated_packages + end + + def self.tito_report + packages = {} + Vagrant::Openshift::Constants.repos.each do |name, url| + Dir.chdir((Vagrant::Openshift::Constants.build_dir + name).to_s) do + tito_report = `tito report --untagged-commits` + tito_report = tito_report.split(/[-]+{10,100}[\n]/) + tito_report.shift + + tito_report.each do |package_report| + package_report = package_report.split("\n") + m = package_report.shift.match(/([a-z\-]+)-([\d\.\-]+)..HEAD/) + packages[m[1]] = { + version: m[2], + untagged_revisions: package_report.map{ |line| line.split(" ")[0] } + } + end + end + end + packages + end +end diff --git a/lib/vagrant-openshift/templates/builder/lib/test.rb b/lib/vagrant-openshift/templates/builder/lib/test.rb new file mode 100644 index 00000000..9d4369d0 --- /dev/null +++ b/lib/vagrant-openshift/templates/builder/lib/test.rb @@ -0,0 +1,369 @@ +#-- +# Copyright 2013 Red Hat, Inc. +# +# 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. +#++ +require 'open3' +require 'securerandom' + +class Test + @@SSH_TIMEOUT = 4800 + + def test(options) + @is_fedora = system("test -e /etc/fedora-release") + reset_test_dir(false) + + test_queues = [[], [], [], []] + + if options[:broker_extended] + (1..4).each do |i| + test_queues[i-1] << build_cucumber_command("REST API Group #{i}", ["@broker_api#{i}"]) + end + test_queues[2] << build_rake_command("OpenShift Broker Functionals Ext", "cd /data/openshift-test/broker; rake test:functionals_ext") + end + + if options[:node_extended] + (1..3).each do |i| + test_queues[i-1] << build_cucumber_command("Extended Runtime Group #{i}", ["@runtime_extended#{i}"]) + end + end + + if options[:rhc_extended] + test_queues[0] << build_cucumber_command("RHC Extended", ["@rhc_extended"]) + test_queues[1] << build_cucumber_command("RHC Integration",[], + {"RHC_SERVER" => "broker.example.com", "RHC_DOMAIN" => "example.com"}, + nil,"/data/openshift-test/rhc/features") + end + + #timeout = @@SSH_TIMEOUT + #timeout = @@SSH_TIMEOUT_OVERRIDES[options.include_cucumber] if not @@SSH_TIMEOUT_OVERRIDES[options.include_cucumber].nil? + #test_queues[0] << build_cucumber_command(options.include_cucumber, [], {}, nil, nil, options.include_cucumber) + + unless options[:exclude_broker] + test_queues[3] << build_rake_command("OpenShift Broker Units", "cd /data/openshift-test/broker; rake test:units", {}, false) + test_queues[0] << build_rake_command("OpenShift Broker Integration", "cd /data/openshift-test/broker; rake test:integration", {}, false) + test_queues[2] << build_rake_command("OpenShift Broker Functional", "cd /data/openshift-test/broker; rake test:functionals", {}, false) + #test_queues[1] << build_rake_command("OpenShift Admin Console Functional", "cd /data/openshift-test/broker; rake test:admin_console_functionals", {}, false) + test_queues[3] << build_cucumber_command("Broker cucumber", ["@broker"]) + end + + unless options[:exclude_node] + test_queues[0] << build_rake_command("Runtime Functional", "cd /data/openshift-test/node; rake func_test", {}, false) + test_queues[0] << build_rake_command("Runtime Unit", "cd /data/openshift-test/node; rake unit_test", {}, false) + (1..4).each do |i| + test_queues[i-1] << build_cucumber_command("Runtime Group #{i.to_s}", ["@runtime#{i.to_s}"]) + end + end + + unless options[:exclude_rhc] + if @is_fedora + test_queues[0] << build_rake_command("RHC Spec", 'cd /data/openshift-test/rhc; bundle install --local && bundle exec rake spec', {"SKIP_RUNCON" => 1}, false) + else + test_queues[0] << build_rake_command("RHC Spec", 'cd /data/openshift-test/rhc; bundle install --path=/tmp/rhc_bundle && bundle exec rake spec', {}, false) + end + end + + run_tests_with_retry(test_queues) + + #These are special tests that cannot be written to work concurrently + singleton_queue = [] + + unless options[:exclude_node] + idle_all_gears + singleton_queue << build_cucumber_command("Runtime singletons", ["@singleton"]) + end + + run_tests_with_retry([singleton_queue]) + end + + def run_tests_with_retry(test_queues) + test_run_success = false + (1..3).each do |retry_cnt| + print "Test run ##{retry_cnt}\n\n\n" + failure_queue = run_tests(test_queues) + if failure_queue.empty? + test_run_success = true + break + else + reset_test_dir(true) + end + test_queues = [failure_queue] + end + exit 1 unless test_run_success + end + + def run_tests(test_queues) + threads = [] + failures = [] + + test_queues.each do |tqueue| + threads << Thread.new do + test_queue = tqueue + start_time = Time.new + test_queue.each do |test| + stdout_data = "" + stderr_data = "" + rc = -1 + + Open3.popen3(test[:command]) do |stdin, stdout, stderr, wait_thr| + pid = wait_thr.pid # pid of the started process. + stdin.close + + stdout_data = stdout.read.chomp + stderr_data = stderr.read.chomp + + stdout.close + stderr.close + rc = wait_thr.value # Process::Status object returned. + end + + print %{ +####################################################################################################################### +Test: #{test[:title]} +####################################################################################################################### + +#{test[:command]} + +#{stdout_data} +#{stderr_data} + +#######################################################################################################################\n} + + test[:output] = stdout_data + "\n" + stdout_data + test[:exit_code] = rc + test[:success] = rc == 0 + test[:completed] = true + + still_running_tests = test_queues.map do |q| + q.select{ |t| t[:completed] != true } + end + + if still_running_tests.length > 0 + mins, secs = (Time.new - start_time).abs.divmod(60) + print "\nStill Running Tests (#{mins}m #{secs.to_i}s):\n" + still_running_tests.each_index do |q_idx| + print "\t Queue #{q_idx}:\n" + print still_running_tests[q_idx].map{ |t| "\t\t#{t[:title]}" }.join("\n"), "\n" + end + print "\n\n\n" + end + end + end + end + + threads.each { |t| t.join } + + failures = test_queues.map{ |q| q.select{ |t| t[:success] == false }} + failures.flatten! + retry_queue = [] + if failures.length > 0 + idle_all_gears + print "Failures\n" + print failures.map{ |f| f[:title] }.join("\n") + print "\n\n\n" + + #process failures + failures.each do |failed_test| + if failed_test[:options].has_key?(:cucumber_rerun_file) + retry_queue << build_cucumber_command(failed_test[:title], [], failed_test[:options][:env], + failed_test[:options][:cucumber_rerun_file], + failed_test[:options][:test_dir], + "*.feature", + failed_test[:options][:require_gemfile_dir], + failed_test[:options][:other_outputs]) + elsif failed_test[:output] =~ /cucumber openshift-test\/tests\/.*\.feature:\d+/ + output.lines.each do |line| + if line =~ /cucumber openshift-test\/tests\/(.*\.feature):(\d+)/ + test = $1 + scenario = $2 + if failed_test[:options][:retry_indivigually] + retry_queue << build_cucumber_command(failed_test[:title], [], failed_test[:options][:env], + failed_test[:options][:cucumber_rerun_file], + failed_test[:options][:test_dir], + "#{test}:#{scenario}") + else + retry_queue << build_cucumber_command(failed_test[:title], [], failed_test[:options][:env], + failed_test[:options][:cucumber_rerun_file], + failed_test[:options][:test_dir], + "#{test}") + end + end + end + elsif failed_test[:options][:retry_indivigually] && failed_test[:output].include?("Failure:") && failed_test[:output].include?("rake_test_loader") + found_test = false + failed_test[:output].lines.each do |line| + if line =~ /\A(test_\w+)\((\w+Test)\) \[\/.*\/(test\/.*_test\.rb):(\d+)\]:/ + found_test = true + test_name = $1 + class_name = $2 + file_name = $3 + + # determine if the first part of the command is a directory change + # if so, include that in the retry command + chdir_command = "" + if cmd =~ /\A(cd .+?; )/ + chdir_command = $1 + end + retry_queue << build_rake_command("#{class_name} (#{test_name})", "#{chdir_command} ruby -Ilib:test #{file_name} -n #{test_name}", true) + end + end + retry_queue << { + :command => failed_test[:command], + :options => failed_test[:options], + :title => failed_test[:title] + } + else + retry_queue << { + :command => failed_test[:command], + :options => failed_test[:options], + :title => failed_test[:title] + } + end + end + end + retry_queue + end + + def build_cucumber_command(title="", tags=[], test_env = {}, old_rerun_file=nil, test_dir="/data/openshift-test/tests", + feature_file="*.feature", require_gemfile_dir=nil, other_outputs = nil) + + other_outputs ||= {:junit => '/tmp/rhc/cucumber_results'} + rerun_file = "/tmp/rerun_#{SecureRandom.hex}.txt" + opts = [] + opts << "--strict" + opts << "-f progress" + opts << "-f rerun --out #{rerun_file} " + other_outputs.each do |formatter, file| + opts << "-f #{formatter} --out #{file}" + end + if @is_fedora + tags += ["~@fedora-18-only", "~@rhel-only", "~@not-fedora-19", "~@jboss", "~@not-origin"] + else + tags += ["~@fedora-18-only", "~@fedora-19-only", "~@not-rhel", "~@jboss", "~@not-origin"] + end + opts += tags.map{ |t| "-t #{t}"} + opts << "-r #{test_dir}" + if old_rerun_file.nil? + opts << "#{test_dir}/#{feature_file}" + else + opts << "@#{old_rerun_file}" + end + if not require_gemfile_dir.nil? + {:command => wrap_test_command("cd #{require_gemfile_dir}; bundle install --path=gems; bundle exec \"cucumber #{opts.join(' ')}\"", test_env), + :options => + {:cucumber_rerun_file => rerun_file, + :timeout => @@SSH_TIMEOUT, + :test_dir => test_dir, + :env => test_env, + :require_gemfile_dir => require_gemfile_dir, + :other_outputs => other_outputs + }, + :title => title + } + else + {:command => wrap_test_command("cucumber #{opts.join(' ')}", test_env), + :options => { + :cucumber_rerun_file => rerun_file, + :timeout => @@SSH_TIMEOUT, + :test_dir => test_dir, + :env => test_env, + :other_outputs => other_outputs + }, + :title => title} + end + end + + def build_rake_command(title="", cmd="", test_env = {}, retry_indivigually=true) + {:command => wrap_test_command(cmd, test_env), :options => {:retry_indivigually => retry_indivigually, :timeout => @@SSH_TIMEOUT, :env => test_env}, :title => title} + end + + def wrap_test_command(command, test_env={}) + env_str = "" + unless test_env.nil? + test_env.each do |k,v| + env_str += "export #{k}=#{v}; " + end + end + if @is_fedora + if test_env["SKIP_RUNCON"] + "export REGISTER_USER=1 ; #{env_str} #{command}" + else + %{runcon -t openshift_initrc_t bash -c \"export REGISTER_USER=1 ; #{env_str} #{command}"} + end + else + %{/usr/bin/scl enable ruby193 "export LANG=en_US.UTF-8 ; export REGISTER_USER=1; #{env_str} #{command}"} + end + end + + def reset_test_dir(backup=false) + File.open('/tmp/reset_test_dir.sh', "w") do |file| + file.write(%{ +if [ -d /tmp/rhc ] +then + if #{backup} + then + if \$(ls /tmp/rhc/run_* > /dev/null 2>&1) + then + rm -rf /tmp/rhc_previous_runs + mkdir -p /tmp/rhc_previous_runs + mv /tmp/rhc/run_* /tmp/rhc_previous_runs + fi + if \$(ls /tmp/rhc/* > /dev/null 2>&1) + then + for i in {1..100} + do + if ! [ -d /tmp/rhc_previous_runs/run_$i ] + then + mkdir -p /tmp/rhc_previous_runs/run_$i + mv /tmp/rhc/* /tmp/rhc_previous_runs/run_$i + break + fi + done + fi + if \$(ls /tmp/rhc_previous_runs/run_* > /dev/null 2>&1) + then + mv /tmp/rhc_previous_runs/run_* /tmp/rhc/ + rm -rf /tmp/rhc_previous_runs + fi + else + rm -rf /tmp/rhc + fi +fi +mkdir -p /tmp/rhc/junit +}) + end + + system 'chmod +x /tmp/reset_test_dir.sh' + system '/tmp/reset_test_dir.sh' + system 'rm -rf /var/www/openshift/broker/tmp/cache/*' + end + + def idle_all_gears + is_fedora = system("test -e /etc/fedora-release") + + print "Idling all gears on remote instance\n" + system('/sbin/service mcollective stop; /sbin/service mcollective start; /sbin/service openshift-port-proxy restart;') + system(%{ + for gear in `oo-admin-ctl-gears list`; do + oo-admin-ctl-gears idlegear $gear; + done; + }) + if is_fedora + system('/sbin/service httpd reload') + else + system('/sbin/service httpd graceful') + end + + print "Done\n" + end +end \ No newline at end of file diff --git a/builder/yum-listbuilddep b/lib/vagrant-openshift/templates/builder/yum-listbuilddep similarity index 100% rename from builder/yum-listbuilddep rename to lib/vagrant-openshift/templates/builder/yum-listbuilddep diff --git a/lib/vagrant-openshift/templates/command/init-openshift/Vagrantfile.erb b/lib/vagrant-openshift/templates/command/init-openshift/Vagrantfile.erb new file mode 100644 index 00000000..132e40de --- /dev/null +++ b/lib/vagrant-openshift/templates/command/init-openshift/Vagrantfile.erb @@ -0,0 +1,124 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +VAGRANTFILE_API_VERSION = "2" +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + # All Vagrant configuration is done here. The most common configuration + # options are documented and commented below. For a complete reference, + # please see the online documentation at vagrantup.com. + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network :private_network, ip: "192.168.33.10" + + # If true, then any SSH connections made will enable agent forwarding. + # Default value: false + # config.ssh.forward_agent = true + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Box to load when booting the vagrant VM. This section applicable only to VirtualBox. + # Other providers may override this value + config.vm.box = "<%= box_info[:virtualbox][:box_name] %>" + config.vm.box_url = "<%= box_info[:virtualbox][:box_url] %>" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + config.vm.provider :virtualbox do |vb| + # Don't boot with headless mode + vb.gui = true + + # Use VBoxManage to customize the VM. For example to change memory: + vb.customize ["modifyvm", :id, "--memory", "2048"] + #vb.customize ["modifyvm", :id, "--cpus", "2"] + end + + config.vm.provider :aws do |aws, override| + # You will need the latest AWS plugin for vagrant + # https://github.com/mitchellh/vagrant-aws + + override.vm.box = "dummy" + override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box" + aws.access_key_id = "<%= box_info[:aws][:aws_access_key_id] %>" + aws.secret_access_key = "<%= box_info[:aws][:aws_secret_access_key] %>" + aws.keypair_name = "<%= box_info[:aws][:aws_keypair_name] %>" + override.ssh.private_key_path = "<%= box_info[:aws][:aws_private_key_path] %>" + + aws.ami = "<%= box_info[:aws][:ami] %>" + aws.region = "<%= box_info[:aws][:ami_region] %>" + override.ssh.username = "<%= box_info[:aws][:ami_ssh_user] %>" + aws.instance_type = "m1.large" + aws.tags = { "Name" => "<%= box_info[:aws][:machine_name] %>" } + aws.user_data = %{ +#cloud-config + +growpart: + mode: auto + devices: ['/'] +runcmd: +- [ sh, -xc, "echo 'Defaults:<%= box_info[:aws][:ami_ssh_user] %> \!requiretty' >> /etc/sudoers"] + } + aws.block_device_mapping = [ + { + "DeviceName" => "/dev/sda1", + "Ebs.VolumeSize" => 10 + } + ] + end + + config.vm.provider :managed do |managed, override| + # You will need the latest managed-servers plugin for vagrant + # https://github.com/tknerr/vagrant-managed-servers + + override.vm.box = "dummy" + override.vm.box_url = "https://github.com/tknerr/vagrant-managed-servers/raw/master/dummy.box" + managed.server = "ip-or-hostname" + override.ssh.username = "root" + override.ssh.private_key_path = "~/.ssh/id_rsa" + end + + config.vm.hostname = 'broker.example.com' + config.vm.provision :openshift + config.vm.guest = :fedora + + # Domain zone under which application will be created. Eg: appname.namespace.example.com + config.openshift.cloud_domain = "example.com" + + # Pakages that are part of OpenShift Origin code but should not be compiled or installed +<% if box_info[:os] == :fedora %> + config.openshift.ignore_packages = [ + 'openshift-origin-util-scl', + 'rubygem-openshift-origin-container-libvirt', + 'openshift-origin-cartridge-jbosseap', + 'openshift-origin-cartridge-jbossews', + ] +<% else %> + config.openshift.ignore_packages = [ + 'openshift-origin-util', + 'rubygem-openshift-origin-container-libvirt', + 'openshift-origin-cartridge-jbosseap', + 'openshift-origin-cartridge-jbossews', + + 'avahi-cname-manager', + 'rubygem-openshift-origin-dns-avahi', + ] +<% end %> + +# Any additional services on the machine which should be restarted after installing OpenShift packages +# config.openshift.additional_services = [ +# 'libvirtd', +# ] + +# The container type to configure the machine with. Options: selinux (default), or libvirt +# config.openshift.container = 'libvirt' + +# Advanced settings to be copied into puppet manifest +# config.openshift.advanced_puppet_values = { +# } +end \ No newline at end of file diff --git a/lib/vagrant-openshift/templates/command/init-openshift/box_info.yaml b/lib/vagrant-openshift/templates/command/init-openshift/box_info.yaml new file mode 100644 index 00000000..d53a42d3 --- /dev/null +++ b/lib/vagrant-openshift/templates/command/init-openshift/box_info.yaml @@ -0,0 +1,58 @@ +--- +:fedora: + :os: + :virtualbox: + :box_name: f19 + :box_url: http://www.krishnaraman.net/downloads/f19.box + :aws: + :ami: ami-b22e5cdb + :ami_region: us-east-1 + :ami_ssh_user: fedora + :machine_name: oso-vagrant-dev + :base: + :virtualbox: + :box_name: f19-base + :box_url: http://www.krishnaraman.net/downloads/f19-base.box + :aws: + :ami: ami-45632e2c + :ami_region: us-east-1 + :ami_ssh_user: fedora + :machine_name: oso-vagrant-dev +:rhel: + :os: + :virtualbox: + :box_name: rhel_64 + :box_url: '' + :aws: + :ami: ami-a25415cb + :ami_region: us-east-1 + :ami_ssh_user: ec2-user + :machine_name: oso-vagrant-rhel-dev + :base: + :virtualbox: + :box_name: rhel_64 + :box_url: '' + :aws: + :ami: ami-654a030c + :ami_region: us-east-1 + :ami_ssh_user: ec2-user + :machine_name: oso-vagrant-rhel-dev +:centos: + :os: + :virtualbox: + :box_name: centos_64 + :box_url: http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130309.box + :aws: + :ami: '' + :ami_region: us-east-1 + :ami_ssh_user: ec2-user + :machine_name: oso-vagrant-centos-dev + :base: + :virtualbox: + :box_name: centos_64 + :box_url: http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130309.box + :aws: + :ami: '' + :ami_region: us-east-1 + :ami_ssh_user: ec2-user + :machine_name: oso-vagrant-centos-dev \ No newline at end of file