diff --git a/lib/vagrant-openshift/action.rb b/lib/vagrant-openshift/action.rb index 69f09253..ad35c393 100644 --- a/lib/vagrant-openshift/action.rb +++ b/lib/vagrant-openshift/action.rb @@ -76,6 +76,12 @@ def self.build_origin(options) end end + def self.setup_openshift_mirrors(options) + Vagrant::Action::Builder.new.tap do |b| + b.use SetupOpenShiftMirrors, options + end + end + def self.push_openshift_images(options) Vagrant::Action::Builder.new.tap do |b| b.use PushOpenshiftImages, options @@ -374,6 +380,7 @@ def self.install_rhc(options) autoload :BuildOriginRpmTest, action_root.join("build_origin_rpm_test") autoload :CreateLocalYumRepo, action_root.join("create_local_yum_repo") autoload :BuildOriginImages, action_root.join("build_origin_images") + autoload :SetupOpenShiftMirrors, action_root.join("setup_openshift_mirrors") end end end diff --git a/lib/vagrant-openshift/action/setup_openshift_mirrors.rb b/lib/vagrant-openshift/action/setup_openshift_mirrors.rb new file mode 100644 index 00000000..358218be --- /dev/null +++ b/lib/vagrant-openshift/action/setup_openshift_mirrors.rb @@ -0,0 +1,47 @@ +#-- +# Copyright 2014 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 SetupOpenShiftMirrors + include CommandHelper + + def initialize(app, env, options) + @app = app + @env = env + @options = options + end + + def call(env) + do_execute(env[:machine], %{ +echo "Setting up 'mirror.openshift.com' for EPEL ..." +set -e +rm -f /tmp/epel-mirror.repo /tmp/set-build-image-args.sh +curl -s https://mirror.openshift.com/mirror/epel/epel7.repo | sed "s/^\\[epel/[epel-openshift/" > /tmp/epel-mirror.repo +echo 'export OS_BUILD_IMAGE_ARGS="--mount /etc/yum.repos.d/epel-mirror.repo:/etc/yum.repos.d/epel.repo"' > /tmp/set-build-image-args.sh + +sudo mv /tmp/epel-mirror.repo /etc/yum.repos.d/epel-mirror.repo +sudo mv /tmp/set-build-image-args.sh /etc/profile.d/set-build-image-args.sh +}, + { :timeout => 60*60*2, :verbose => false }) + @app.call(env) + end + + end + end + end +end diff --git a/lib/vagrant-openshift/command/setup_mirrors.rb b/lib/vagrant-openshift/command/setup_mirrors.rb new file mode 100644 index 00000000..fdb4d0f1 --- /dev/null +++ b/lib/vagrant-openshift/command/setup_mirrors.rb @@ -0,0 +1,50 @@ +#-- +# 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 SetupMirrors < Vagrant.plugin(2, :command) + include CommandHelper + + def self.synopsis + "setup OpenShift repository mirrors" + end + + def execute + options = {} + options[:clean] = false + + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant setup-mirrors [vm-name]" + o.separator "" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + + with_target_vms(argv, :reverse => true) do |machine| + actions = Vagrant::Openshift::Action.setup_openshift_mirrors(options) + @env.action_runner.run actions, {:machine => machine} + 0 + end + end + end + end + end +end diff --git a/lib/vagrant-openshift/plugin.rb b/lib/vagrant-openshift/plugin.rb index f8c72ac1..aec94522 100644 --- a/lib/vagrant-openshift/plugin.rb +++ b/lib/vagrant-openshift/plugin.rb @@ -212,6 +212,11 @@ class Plugin < Vagrant.plugin("2") Commands::RepoSyncOriginMetrics end + command "setup-openshift-mirrors" do + require_relative "command/setup_mirrors" + Commands::SetupMirrors + end + provisioner(:openshift) do require_relative "provisioner" Provisioner