From fd593d8bfde61804b94c9587fb97c7b7c85a7a0d Mon Sep 17 00:00:00 2001 From: Krishna Raman Date: Fri, 23 Aug 2013 00:18:36 -0700 Subject: [PATCH] Initial commit --- .gitignore | 17 + .idea/.name | 1 + .idea/.rakeTasks | 7 + .idea/encodings.xml | 5 + .idea/misc.xml | 5 + .idea/modules.xml | 9 + .idea/scopes/scope_settings.xml | 5 + .idea/vagrant-openshift.iml | 24 + .idea/vcs.xml | 7 + .idea/workspace.xml | 619 ++++++++++++++++++ Gemfile | 4 + LICENSE.txt | 13 + README.md | 21 + Rakefile | 35 + builder/Rakefile | 51 ++ builder/lib/.gitkeep | 0 builder/yum-listbuilddep | 124 ++++ lib/vagrant-openshift.rb | 34 + .../commands/build_origin_base.rb | 111 ++++ lib/vagrant-openshift/commands/repo_sync.rb | 176 +++++ lib/vagrant-openshift/constants.rb | 39 ++ .../helpers/command_helper.rb | 48 ++ lib/vagrant-openshift/plugin.rb | 38 ++ lib/vagrant-openshift/version.rb | 21 + vagrant-openshift.gemspec | 38 ++ 25 files changed, 1452 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.name create mode 100644 .idea/.rakeTasks create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vagrant-openshift.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Gemfile create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100644 builder/Rakefile create mode 100644 builder/lib/.gitkeep create mode 100755 builder/yum-listbuilddep create mode 100644 lib/vagrant-openshift.rb create mode 100644 lib/vagrant-openshift/commands/build_origin_base.rb create mode 100644 lib/vagrant-openshift/commands/repo_sync.rb create mode 100644 lib/vagrant-openshift/constants.rb create mode 100644 lib/vagrant-openshift/helpers/command_helper.rb create mode 100644 lib/vagrant-openshift/plugin.rb create mode 100644 lib/vagrant-openshift/version.rb create mode 100644 vagrant-openshift.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d87d4be6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..20010064 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +vagrant-openshift \ No newline at end of file diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks new file mode 100644 index 00000000..ffccf7c9 --- /dev/null +++ b/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..e206d70d --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..e092a087 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..0900b2cb --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 00000000..922003b8 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vagrant-openshift.iml b/.idea/vagrant-openshift.iml new file mode 100644 index 00000000..b655da14 --- /dev/null +++ b/.idea/vagrant-openshift.iml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..c80f2198 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..5c9df800 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,619 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1377192074240 + 1377192074240 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..63587390 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in vagrant-openshift.gemspec +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..c9806e04 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,13 @@ +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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..ec769752 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# @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 new file mode 100644 index 00000000..1787426e --- /dev/null +++ b/Rakefile @@ -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. +#++ + +require 'rubygems' +require 'bundler/setup' +require 'pry' +$stdout.sync = true +$stderr.sync = true + +namespace :vagrant do + + desc "Install plugin into Vagrant" + task :install 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") + end +end + +Bundler::GemHelper.install_tasks +task :default => "vagrant:install" \ No newline at end of file diff --git a/builder/Rakefile b/builder/Rakefile new file mode 100644 index 00000000..c4caf497 --- /dev/null +++ b/builder/Rakefile @@ -0,0 +1,51 @@ +#-- +# 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/builder/lib/.gitkeep b/builder/lib/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/builder/yum-listbuilddep b/builder/yum-listbuilddep new file mode 100755 index 00000000..86c6a8cd --- /dev/null +++ b/builder/yum-listbuilddep @@ -0,0 +1,124 @@ +#!/usr/bin/python -tt + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import sys +sys.path.insert(0,'/usr/share/yum-cli') + +import yum +from yum.misc import setup_locale +from yum.i18n import exception2msg +import yum.Errors +from utils import YumUtilBase + +import logging +import rpmUtils +import rpm + +rhn_source_repos = False + + + +class YumBuildDep(YumUtilBase): + NAME = 'yum-listbuilddep' + VERSION = '1.0' + USAGE = 'yum-listbuilddep package1.spec [package2.spec] [...]' + + def __init__(self): + YumUtilBase.__init__(self, + YumBuildDep.NAME, + YumBuildDep.VERSION, + YumBuildDep.USAGE) + self.logger = logging.getLogger("yum.verbose.cli.yumbuildep") + # Add util commandline options to the yum-cli ones + self.optparser = self.getOptionParser() + if hasattr(rpm, 'reloadConfig'): + self.optparser.add_option("--target", + help="set target architecture for spec parsing") + self.main() + + def main(self): + # Parse the commandline option and setup the basics. + try: + opts = self.doUtilConfigSetup() + except yum.Errors.RepoError, e: + self.logger.error("Cannot handle specific enablerepo/disablerepo options.") + sys.exit(50) + + # turn of our local gpg checking for opening the srpm if it is turned + # off for repos :) + if (opts.nogpgcheck or + not self.conf.localpkg_gpgcheck or not self.conf.gpgcheck): + self.ts.pushVSFlags((rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)) + + # Check if there is anything to do. + if len(self.cmds) < 1: + print self.optparser.format_help() + sys.exit(0) + + try: + self.get_build_deps(opts) + except yum.Errors.MiscError, e: + msg = "There was a problem getting the build deps, exiting:\n %s" % e + self.logger.error(msg) + sys.exit(1) + sys.exit() + + def get_build_deps(self,opts): + srcnames = [] + specnames = [] + srpms = [] + specworks = False + reloadworks = False + + # See if we can use spec files for buildrequires + if hasattr(rpm, 'spec') and hasattr(rpm.spec, 'sourceHeader'): + specworks = True + # See if we can reload rpm configuration + if hasattr(rpm, 'reloadConfig'): + reloadworks = True + + for arg in self.cmds: + if specworks and arg.endswith('.spec'): + specnames.append(arg) + + toActOn = [] + for name in specnames: + # (re)load rpm config for target if set + if reloadworks and opts.target: + rpm.reloadConfig(opts.target) + + try: + spec = rpm.spec(name) + except ValueError: + self.logger.error("Bad spec: %s" % name) + continue + + # reset default rpm config after each parse to avoid side-effects + if reloadworks: + rpm.reloadConfig() + + buildreqs = [] + for d in rpm.ds(spec.sourceHeader, 'requires'): + buildreqs.append(d.DNEVR()[2:]) + + if len(buildreqs) > 0: + self.logger.info('["%s"]' % '","'.join(buildreqs)) + else: + self.logger.info('[]') + +if __name__ == '__main__': + setup_locale() + util = YumBuildDep() \ No newline at end of file diff --git a/lib/vagrant-openshift.rb b/lib/vagrant-openshift.rb new file mode 100644 index 00000000..b1b7ed52 --- /dev/null +++ b/lib/vagrant-openshift.rb @@ -0,0 +1,34 @@ +#-- +# 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-openshift/version" +require "pathname" + +begin + require "vagrant" +rescue LoadError + raise "Not running in vagrant environment" +end + +module Vagrant + module Openshift + plugin_path = Pathname.new(File.expand_path("#{__FILE__}/../vagrant-openshift/")) + + autoload :CommandHelper, plugin_path + "helpers/command_helper" + autoload :Constants, plugin_path + "constants" + end +end + +require "vagrant-openshift/plugin" \ No newline at end of file diff --git a/lib/vagrant-openshift/commands/build_origin_base.rb b/lib/vagrant-openshift/commands/build_origin_base.rb new file mode 100644 index 00000000..06fd2b00 --- /dev/null +++ b/lib/vagrant-openshift/commands/build_origin_base.rb @@ -0,0 +1,111 @@ +#-- +# 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 new file mode 100644 index 00000000..f1003bc5 --- /dev/null +++ b/lib/vagrant-openshift/commands/repo_sync.rb @@ -0,0 +1,176 @@ +#-- +# 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/constants.rb b/lib/vagrant-openshift/constants.rb new file mode 100644 index 00000000..741ee4d5 --- /dev/null +++ b/lib/vagrant-openshift/constants.rb @@ -0,0 +1,39 @@ +#-- +# 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 'pathname' + +module Vagrant + module Openshift + class Constants + 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 + + def self.build_dir + Pathname.new "/data" + end + + def git_ssh + "" + 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 new file mode 100644 index 00000000..f6a71920 --- /dev/null +++ b/lib/vagrant-openshift/helpers/command_helper.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 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 new file mode 100644 index 00000000..f3e3649b --- /dev/null +++ b/lib/vagrant-openshift/plugin.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 + class Plugin < Vagrant.plugin("2") + name "OpenShift" + description %{ + Plugin to build and manage OpenShift Origin environments + } + + command "reposync" do + require_relative "commands/repo_sync" + Commands::RepoSync + end + + command "build-origin-base" do + require_relative "commands/build_origin_base" + Commands::BuildOriginBase + end + + + end + end +end \ No newline at end of file diff --git a/lib/vagrant-openshift/version.rb b/lib/vagrant-openshift/version.rb new file mode 100644 index 00000000..5f870038 --- /dev/null +++ b/lib/vagrant-openshift/version.rb @@ -0,0 +1,21 @@ +#-- +# 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 + VERSION = "0.0.1" + end +end diff --git a/vagrant-openshift.gemspec b/vagrant-openshift.gemspec new file mode 100644 index 00000000..a0d48a33 --- /dev/null +++ b/vagrant-openshift.gemspec @@ -0,0 +1,38 @@ +# -*- encoding: utf-8 -*- +#-- +# 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. +#++ + +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'vagrant-openshift/version' + +Gem::Specification.new do |gem| + gem.name = "vagrant-openshift" + gem.version = Vagrant::Openshift::VERSION + gem.authors = ["Krishna Raman"] + gem.email = ["kraman@gmail.com"] + gem.description = %q{Vagrant plugin to manage OpenShift Origin environments} + gem.summary = %q{Vagrant plugin to manage OpenShift Origin environments} + gem.homepage = "http://openshift.github.io" + + gem.files = `git ls-files`.split($/) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.require_paths = ["lib"] + + gem.add_development_dependency("rake") + gem.add_dependency("pry") +end