diff --git a/hack/test.sh b/hack/test.sh index bd02b7f7..b880642d 100755 --- a/hack/test.sh +++ b/hack/test.sh @@ -122,18 +122,13 @@ test_vagrant install-docker --docker.version=1.12.6 \ --repo='oso-rhui-rhel-server-*' validate_version 'docker' '1.12.6' -test_vagrant clone-upstream-repos --clean --repo origin-web-console -test_vagrant checkout-repos --repo origin-web-console +test_vagrant clone-upstream-repos --clean +test_vagrant checkout-repos +test_vagrant build-origin-base-images test_vagrant install-origin-assets-base -test_vagrant clone-upstream-repos --clean --repo origin -test_vagrant checkout-repos --repo origin -test_vagrant build-origin-base-images test_vagrant install-origin test_vagrant build-origin --images - -test_vagrant clone-upstream-repos --clean --repo source-to-image -test_vagrant checkout-repos --repo source-to-image test_vagrant build-sti --binary-only popd diff --git a/lib/vagrant-openshift/action.rb b/lib/vagrant-openshift/action.rb index 4517cde7..3a0a1ddd 100644 --- a/lib/vagrant-openshift/action.rb +++ b/lib/vagrant-openshift/action.rb @@ -395,7 +395,9 @@ def self.install_rhc(options) autoload :BuildStiBaseWindows, action_root.join("build_sti_base_windows") autoload :PrepareSshConfig, action_root.join("prepare_ssh_config") autoload :SyncLocalRepository, action_root.join("sync_local_repository") + autoload :SyncUpstreamRepository, action_root.join("sync_upstream_repository") autoload :LocalOriginCheckout, action_root.join("local_origin_checkout") + autoload :CreateBareRepoPlaceholders, action_root.join("create_bare_repo_placeholders") autoload :RunOriginTests, action_root.join("run_origin_tests") autoload :RunOriginAssetTests, action_root.join("run_origin_asset_tests") autoload :RunStiTests, action_root.join("run_sti_tests") diff --git a/lib/vagrant-openshift/action/checkout_repositories.rb b/lib/vagrant-openshift/action/checkout_repositories.rb index 89ae642b..1925ed32 100644 --- a/lib/vagrant-openshift/action/checkout_repositories.rb +++ b/lib/vagrant-openshift/action/checkout_repositories.rb @@ -28,26 +28,27 @@ def initialize(app, env, options={}) def call(env) git_clone_commands = "set -e\n" - repo_name = @options[:repo] - bare_repo_name = repo_name + "-bare" - bare_repo_path = Constants.build_dir + bare_repo_name - repo_path = Constants.build_dir + repo_name + Constants.repos_for_name(@options[:repo]).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 += %{ + git_clone_commands += %{ if [ -d #{bare_repo_path} ]; then rm -rf #{repo_path} echo 'Cloning #{repo_name} ...' git clone --quiet --recurse-submodules #{bare_repo_path} #{repo_path} } - if @options[:branch] && @options[:branch][repo_name] - git_clone_commands += "cd #{repo_path}; git checkout --quiet #{@options[:branch][repo_name]}; cd #{Constants.build_dir};\n" - end - git_clone_commands += %{ + if @options[:branch] && @options[:branch][repo_name] + git_clone_commands += "cd #{repo_path}; git checkout --quiet #{@options[:branch][repo_name]}; cd #{Constants.build_dir};\n" + end + git_clone_commands += %{ else MISSING_REPO+='#{bare_repo_name}' fi } + end git_clone_commands += %{ if [ -n \"$MISSING_REPO\" ]; then diff --git a/lib/vagrant-openshift/action/clean.rb b/lib/vagrant-openshift/action/clean.rb index ca06476f..b23d7683 100644 --- a/lib/vagrant-openshift/action/clean.rb +++ b/lib/vagrant-openshift/action/clean.rb @@ -28,14 +28,15 @@ def initialize(app, env, options={}) def call(env) git_clone_commands = "" - repo_name = @options[:repo] - bare_repo_name = repo_name + "-bare" - wc_repo_name = repo_name + "-bare-working_copy" - bare_repo_path = Constants.build_dir + bare_repo_name - repo_path = Constants.build_dir + repo_name - wc_repo_path = Constants.build_dir + wc_repo_name + Constants.repos_for_name(@options[:repo]).each do |repo_name, url| + bare_repo_name = repo_name + "-bare" + wc_repo_name = repo_name + "-bare-working_copy" + bare_repo_path = Constants.build_dir + bare_repo_name + repo_path = Constants.build_dir + repo_name + wc_repo_path = Constants.build_dir + wc_repo_name - git_clone_commands += "rm -rf #{bare_repo_path}; \n" + git_clone_commands += "rm -rf #{bare_repo_path}; \n" + end do_execute env[:machine], git_clone_commands @app.call(env) diff --git a/lib/vagrant-openshift/action/clone_upstream_repositories.rb b/lib/vagrant-openshift/action/clone_upstream_repositories.rb index ea4ae891..b505ac84 100644 --- a/lib/vagrant-openshift/action/clone_upstream_repositories.rb +++ b/lib/vagrant-openshift/action/clone_upstream_repositories.rb @@ -36,19 +36,20 @@ def call(env) }} git_clone_commands = "set -e\n" - repo_name = @options[:repo] - bare_repo_name = repo_name + "-bare" - bare_repo_path = Constants.build_dir + bare_repo_name + Constants.repos_for_name(@options[:repo]).each do |repo_name, url| + bare_repo_name = repo_name + "-bare" + bare_repo_path = Constants.build_dir + bare_repo_name - if @options[:clean] - git_clone_commands += "rm -fr #{bare_repo_path};\n" - end + if @options[:clean] + git_clone_commands += "rm -fr #{bare_repo_path};\n" + end - git_clone_commands += %{ + git_clone_commands += %{ if [ ! -d #{bare_repo_path} ]; then -git clone --quiet --bare #{Constants.repo_url_for_name(repo_name)} #{bare_repo_path} >/dev/null +git clone --quiet --bare #{url} #{bare_repo_path} >/dev/null fi } + end sudo(env[:machine], "mkdir -p #{Constants.build_dir}") sudo(env[:machine], "mkdir -p #{Constants.build_dir + "builder"} && chown -R #{ssh_user}:#{ssh_group} #{Constants.build_dir}") 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..573eb873 --- /dev/null +++ b/lib/vagrant-openshift/action/create_bare_repo_placeholders.rb @@ -0,0 +1,53 @@ +#-- +# 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(env).each do |repo_name, url| + bare_repo_name = repo_name + "-bare" + bare_repo_path = Constants.build_dir + bare_repo_name + + git_clone_commands += "[ ! -d #{bare_repo_path} ] && git init --bare #{bare_repo_path};\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 diff --git a/lib/vagrant-openshift/action/local_origin_checkout.rb b/lib/vagrant-openshift/action/local_origin_checkout.rb index e8a73df1..1876431c 100644 --- a/lib/vagrant-openshift/action/local_origin_checkout.rb +++ b/lib/vagrant-openshift/action/local_origin_checkout.rb @@ -38,7 +38,9 @@ def call(env) end Dir.chdir(go_path) do commands = "echo 'Waiting for the cloning process to finish'\n" - commands += repo_checkout_bash_command(@options[:repo], Constants.repo_url_for_name(@options[:repo])) + Constants.repos_for_name(@options[:repo]).each do |repo, url| + commands += repo_checkout_bash_command(repo, url) + end system(commands) puts "Origin repositories cloned into #{Dir.pwd}" diff --git a/lib/vagrant-openshift/action/sync_local_repository.rb b/lib/vagrant-openshift/action/sync_local_repository.rb index cf019378..ead168f1 100644 --- a/lib/vagrant-openshift/action/sync_local_repository.rb +++ b/lib/vagrant-openshift/action/sync_local_repository.rb @@ -29,17 +29,18 @@ def initialize(app, env, options={}) def call(env) env[:machine].env.ui.info("Synchronizing local sources") - repo_name = @options[:repo] - local_repo = Pathname.new(File.expand_path(File.join(env[:machine].env.root_path, "..", repo_name))) - unless local_repo.exist? - local_repo = Pathname.new(File.expand_path(File.join(env[:machine].env.root_path, repo_name))) + Constants.repos_for_name(@options[:repo]).each do |repo_name, url| + local_repo = Pathname.new(File.expand_path(File.join(env[:machine].env.root_path, "..", repo_name))) unless local_repo.exist? - env[:machine].ui.warn "Missing local clone of repository #{repo_name}" - next + local_repo = Pathname.new(File.expand_path(File.join(env[:machine].env.root_path, repo_name))) + unless local_repo.exist? + env[:machine].ui.warn "Missing local clone of repository #{repo_name}" + next + end end - end - Dir.chdir(local_repo) { sync_repo(env[:machine], repo_name) } + Dir.chdir(local_repo) { sync_repo(env[:machine], repo_name) } + end @app.call(env) end diff --git a/lib/vagrant-openshift/action/sync_upstream_repository.rb b/lib/vagrant-openshift/action/sync_upstream_repository.rb new file mode 100644 index 00000000..5be5b4d8 --- /dev/null +++ b/lib/vagrant-openshift/action/sync_upstream_repository.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 SyncUpstreamRepository + include CommandHelper + + def initialize(app, env) + @app = app + @env = env + end + + def call(env) + env[:machine].env.ui.info("Synchronizing upstream sources\n") + command = "set -e\n" + + Constants.repos(env).each do |repo_name, url| + + branch="master" + + bare_repo_name = repo_name + "-bare" + bare_repo_wc_name = repo_name + "-bare-working_copy" + bare_repo_path = Constants.build_dir + bare_repo_name + bare_repo_wc_path = Constants.build_dir + bare_repo_wc_name + + command += "export GIT_SSH=#{Constants.git_ssh};\n" unless Constants.git_ssh.nil? or Constants.git_ssh.empty? + command += %{ +if [ ! -d #{bare_repo_wc_path} ]; then +echo 'Cloning #{repo_name} ...' +git clone -l --quiet #{bare_repo_path} #{bare_repo_wc_path} +fi + +cd #{bare_repo_wc_path} +git remote add upstream #{url} +git fetch upstream +git checkout master +git reset --hard upstream/#{branch} +git push origin master -f +} + end + + do_execute(env[:machine], command) + + env[:machine].env.ui.info("Done") + @app.call(env) + end + + end + end + end +end diff --git a/lib/vagrant-openshift/command/clone_upstream_repositories.rb b/lib/vagrant-openshift/command/clone_upstream_repositories.rb index bb9d5f3f..0c7fbc6e 100644 --- a/lib/vagrant-openshift/command/clone_upstream_repositories.rb +++ b/lib/vagrant-openshift/command/clone_upstream_repositories.rb @@ -28,7 +28,6 @@ def self.synopsis def execute options = {} options[:clean] = false - options[:repo] = 'origin' opts = OptionParser.new do |o| o.banner = "Usage: vagrant clone-upstream-repositories" @@ -37,10 +36,6 @@ def execute o.on("-c", "--clean", "Remove the current bare repositories on disk if present") do |c| options[:clean] = true end - - o.on("-r [repo-name]", "--repo [repo-name]", String, "Clone the specified repo. Default is 'origin'.") do |f| - options[:repo] = f - end end # Parse the options diff --git a/lib/vagrant-openshift/constants.rb b/lib/vagrant-openshift/constants.rb index c32f00c9..7e03cf73 100644 --- a/lib/vagrant-openshift/constants.rb +++ b/lib/vagrant-openshift/constants.rb @@ -19,8 +19,47 @@ module Vagrant module Openshift class Constants - def self.repo_url_for_name(name) - "https://github.com/openshift/#{name}.git" + def self.repos(env) + openshift_repos + end + + def self.logging_repos(env) + aggregated_logging_repos + end + + def self.openshift_repos + { + 'origin' => 'https://github.com/openshift/origin.git', + 'source-to-image' => 'https://github.com/openshift/source-to-image.git', + 'origin-web-console' => 'https://github.com/openshift/origin-web-console.git' + } + end + + def self.console_repos + { + 'origin-web-console' => 'https://github.com/openshift/origin-web-console.git' + } + end + + def self.aggregated_logging_repos + { + 'origin-aggregated-logging' => 'https://github.com/openshift/origin-aggregated-logging.git' + } + end + + def self.repos_for_name(reponame) + { + 'origin' => openshift_repos, + nil => openshift_repos, + 'origin-console' => console_repos, + 'origin-aggregated-logging' => aggregated_logging_repos, + 'origin-metrics' => { + 'origin-metrics' => 'https://github.com/openshift/origin-metrics.git' + }, + 'openshift-ansible' => { + 'openshift-ansible' => 'https://github.com/openshift/openshift-ansible.git' + } + }[reponame] end def self.git_branch_current