Skip to content

Commit 80bf8aa

Browse files
committed
Update installing of dependencies
* config-server and bosh-agent repos are now required to be cloned at the same level as the bosh repo * Services and binaries are only compiled once Signed-off-by: Aram Price <[email protected]>
1 parent a297fa5 commit 80bf8aa

File tree

12 files changed

+78
-83
lines changed

12 files changed

+78
-83
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ dev_releases
1414
releases/*.tgz
1515
releases/**/*.tgz
1616

17-
src/bosh-agent/
1817
src/postgresql.dump.sql
1918
src/postgresql.tables.txt
2019
src/parallel_runtime_rspec.log

ci/tasks/test-integration.sh

-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ start_db "${DB}"
1010

1111
install bosh-cli/*bosh-cli-*-linux-amd64 "/usr/local/bin/bosh"
1212

13-
cp -r bosh-agent "${BOSH_REPO}/src/"
14-
15-
pushd config-server
16-
go build .
17-
export CONFIG_SERVER_BINARY=$(realpath config-server)
18-
popd
19-
2013
pushd "${BOSH_REPO}/src"
2114
print_git_state
2215
print_ruby_info

src/bosh-director/lib/cloud/dummy.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ module Clouds
99
class Dummy
1010
class NotImplemented < StandardError; end
1111

12+
BOSH_REPO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..'))
13+
1214
attr_reader :commands
1315
attr_accessor :options
1416

@@ -525,7 +527,7 @@ def write_agent_default_network(agent_id, ip_address)
525527

526528
def agent_cmd(agent_id, legacy_agent_path)
527529
if legacy_agent_path.nil?
528-
go_agent_exe = File.expand_path('../../../../bosh-agent/out/bosh-agent', __FILE__)
530+
go_agent_exe = File.join(BOSH_REPO_ROOT, 'src', 'tmp', 'bin', 'bosh-agent')
529531
else
530532
go_agent_exe = legacy_agent_path
531533
end
+17-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1+
require 'integration_support/constants'
2+
13
module IntegrationSupport
24
module BoshAgent
3-
BOSH_REPO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..')).freeze
4-
BOSH_AGENT_SRC = File.join(BOSH_REPO_ROOT, 'src/bosh-agent')
5-
COMPILED_BOSH_AGENT = File.join(BOSH_AGENT_SRC, 'out', 'bosh-agent')
5+
SOURCE_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_PARENT_DIR, 'bosh-agent')
6+
COMPILED_BOSH_AGENT = File.join(SOURCE_DIR, 'out', 'bosh-agent')
7+
8+
def self.install
9+
return if File.exist?(executable_path)
610

7-
def self.ensure_agent_exists!
8-
unless File.exist?(COMPILED_BOSH_AGENT) || ENV['TEST_ENV_NUMBER']
9-
puts "Building agent in #{COMPILED_BOSH_AGENT}..."
11+
raise "The bosh-agent source must be a sibling to the BOSH Director repo" unless File.exist?(SOURCE_DIR)
1012

11-
raise 'Bosh agent build failed' unless system(File.join(BOSH_AGENT_SRC, 'bin', 'build'))
13+
Dir.chdir(SOURCE_DIR) do
14+
system('bin/build') || raise('Unable to build bosh-agent')
1215
end
16+
raise 'Expected bosh-agent binary to exist, but it does not' unless File.exist?(COMPILED_BOSH_AGENT)
17+
18+
FileUtils.cp(COMPILED_BOSH_AGENT, executable_path)
1319
end
14-
end
15-
end
1620

17-
RSpec.configure do |c|
18-
c.before(:suite) do
19-
IntegrationSupport::BoshAgent.ensure_agent_exists!
21+
def self.executable_path
22+
File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, 'bosh-agent')
23+
end
2024
end
2125
end
26+

src/spec/integration_support/config_server_service.rb

+21-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ConfigServerService
66

77
LOCAL_CONFIG_SERVER_FILE_NAME = "bosh-config-server-executable"
88

9-
INSTALL_DIR = File.join('tmp', 'integration-config-server')
9+
SOURCE_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_PARENT_DIR, 'config-server')
1010

1111
# Keys and Certs
1212
CERTS_DIR = File.join(IntegrationSupport::Constants::SANDBOX_ASSETS_DIR, 'config_server', 'certs')
@@ -23,7 +23,7 @@ def initialize(port_provider, base_log_path, logger, test_env_number)
2323
@port = port_provider.get_port(:config_server_port)
2424
@logger = logger
2525
@log_location = "#{base_log_path}.config-server.out"
26-
@config_server_config_file= File.join(INSTALL_DIR, "config-server-config#{test_env_number}.json")
26+
@config_server_config_file= File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, "config-server-config#{test_env_number}.json")
2727
@config_server_socket_connector = SocketConnector.new('config-server', 'localhost', @port, @log_location, logger)
2828

2929
@config_server_process = IntegrationSupport::Service.new(
@@ -36,12 +36,25 @@ def initialize(port_provider, base_log_path, logger, test_env_number)
3636
end
3737

3838
def self.install
39-
binary_file_path = ENV.fetch('CONFIG_SERVER_BINARY')
39+
return if File.exist?(executable_path)
4040

41-
FileUtils.mkdir_p(INSTALL_DIR)
42-
executable_file_path = File.join(INSTALL_DIR, LOCAL_CONFIG_SERVER_FILE_NAME)
43-
FileUtils.copy(binary_file_path, executable_file_path)
44-
File.chmod(0777, executable_file_path)
41+
binary_file_path = self.build_binary
42+
FileUtils.copy(binary_file_path, executable_path)
43+
end
44+
45+
def self.executable_path
46+
File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, LOCAL_CONFIG_SERVER_FILE_NAME)
47+
end
48+
49+
def self.build_binary
50+
raise "The config-server source must be a sibling to the BOSH Director repo" unless File.exist?(SOURCE_DIR)
51+
52+
Dir.chdir(SOURCE_DIR) do
53+
system('go build .') || raise('Unable to build config-server')
54+
end
55+
binary_file_path = File.join(SOURCE_DIR, 'config-server')
56+
raise 'Expected config-server binary to exist, but it does not' unless File.exist?(binary_file_path)
57+
binary_file_path
4558
end
4659

4760
def start(with_trusted_certs)
@@ -68,7 +81,7 @@ def restart(with_trusted_certs)
6881
private
6982

7083
def executable_path
71-
File.join(INSTALL_DIR, LOCAL_CONFIG_SERVER_FILE_NAME)
84+
File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, LOCAL_CONFIG_SERVER_FILE_NAME)
7285
end
7386

7487
def setup_config_file(with_trusted_certs = true)

src/spec/integration_support/constants.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module IntegrationSupport
22
module Constants
33
BOSH_REPO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
4+
BOSH_REPO_PARENT_DIR = File.expand_path(File.join(BOSH_REPO_ROOT, '..'))
45
BOSH_REPO_SRC_DIR = File.join(BOSH_REPO_ROOT, 'src')
6+
INTEGRATION_BIN_DIR = File.join(BOSH_REPO_SRC_DIR, 'tmp', 'bin')
57

68
SANDBOX_ASSETS_DIR = File.join(BOSH_REPO_SRC_DIR, 'spec', 'assets', 'sandbox')
79
SANDBOX_CERTS_DIR = File.join(SANDBOX_ASSETS_DIR, 'ca', 'certs')

src/spec/integration_support/gnatsd_manager.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'integration_support/constants'
2+
13
module IntegrationSupport
24
class GnatsdManager
35
def self.install
@@ -16,11 +18,10 @@ def self.installer
1618
end
1719

1820
class NatsServerBlobInstaller
19-
INSTALL_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_DIR, 'tmp', 'integration-nats')
20-
2121
def install
22+
return if File.exist?(executable_path)
23+
2224
Dir.chdir(IntegrationSupport::Constants::BOSH_REPO_ROOT) do
23-
run_command("mkdir -p #{INSTALL_DIR}")
2425
run_command('bosh sync-blobs')
2526
run_command('tar -zxvf blobs/nats/nats-server-*.tar.gz -C /tmp')
2627
run_command("cp /tmp/nats-server-*/nats-server #{executable_path}")
@@ -29,7 +30,7 @@ def install
2930
end
3031

3132
def executable_path
32-
File.join(INSTALL_DIR, 'nats-server')
33+
File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, 'nats-server')
3334
end
3435

3536
private

src/spec/integration_support/nginx_service.rb

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class NginxService
66
CONFIG_TEMPLATE = File.join(IntegrationSupport::Constants::SANDBOX_ASSETS_DIR, 'nginx.conf.erb')
77

88
def self.install
9+
return if File.exist?(NginxInstaller::EXECUTABLE_PATH)
10+
911
installer = NginxInstaller.new
1012
installer.prepare
1113

@@ -90,8 +92,7 @@ def logfile_path(base_log_path)
9092

9193
class NginxInstaller
9294
WORKING_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_DIR, 'tmp', 'integration-nginx-work')
93-
INSTALL_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_DIR, 'tmp', 'integration-nginx')
94-
EXECUTABLE_PATH = File.join(INSTALL_DIR, 'sbin', 'nginx')
95+
EXECUTABLE_PATH = File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, 'sbin', 'nginx')
9596

9697
def prepare
9798
Dir.chdir(IntegrationSupport::Constants::BOSH_REPO_ROOT) do
@@ -109,20 +110,18 @@ def should_compile?
109110
def compile
110111
# Clean up old compiled nginx bits to stay up-to-date
111112
FileUtils.rm_rf(WORKING_DIR)
112-
FileUtils.rm_rf(INSTALL_DIR)
113113

114114
FileUtils.mkdir_p(WORKING_DIR)
115-
FileUtils.mkdir_p(INSTALL_DIR)
116115

117-
run_command("echo '#{RUBY_PLATFORM}' > #{INSTALL_DIR}/platform")
116+
run_command("echo '#{RUBY_PLATFORM}' > #{IntegrationSupport::Constants::INTEGRATION_BIN_DIR}/platform")
118117

119118
# Make sure packaging script has its own blob copies so that blobs/ directory is not affected
120119
nginx_blobs_path = File.join(IntegrationSupport::Constants::BOSH_REPO_ROOT, 'packages', 'nginx')
121120
run_command("cp -R #{nginx_blobs_path}/. #{File.join(WORKING_DIR)}")
122121

123122
Dir.chdir(WORKING_DIR) do
124123
packaging_script_path = File.join(IntegrationSupport::Constants::BOSH_REPO_ROOT, 'packages', 'nginx', 'packaging')
125-
run_command("bash #{packaging_script_path}", { 'BOSH_INSTALL_TARGET' => INSTALL_DIR })
124+
run_command("bash #{packaging_script_path}", { 'BOSH_INSTALL_TARGET' => IntegrationSupport::Constants::INTEGRATION_BIN_DIR })
126125
end
127126
end
128127

@@ -150,7 +149,7 @@ def blob_has_changed?
150149
end
151150

152151
def platform_has_changed?
153-
output = run_command("cat #{INSTALL_DIR}/platform || true")
152+
output = run_command("cat #{IntegrationSupport::Constants::INTEGRATION_BIN_DIR}/platform || true")
154153
output != RUBY_PLATFORM
155154
end
156155

src/spec/integration_support/sandbox.rb

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
require 'integration_support/director_service'
1616
require 'integration_support/nginx_service'
1717
require 'integration_support/gnatsd_manager'
18+
require 'integration_support/bosh_agent'
19+
require 'integration_support/uaa_service'
20+
require 'integration_support/verify_multidigest_manager'
1821

1922
module IntegrationSupport
2023
class Sandbox
@@ -73,6 +76,17 @@ def self.from_env
7376
)
7477
end
7578

79+
def self.install_dependencies
80+
FileUtils.mkdir_p(IntegrationSupport::Constants::INTEGRATION_BIN_DIR)
81+
IntegrationSupport::BoshAgent.install
82+
IntegrationSupport::NginxService.install
83+
IntegrationSupport::UaaService.install
84+
IntegrationSupport::ConfigServerService.install
85+
IntegrationSupport::VerifyMultidigestManager.install
86+
IntegrationSupport::GnatsdManager.install
87+
end
88+
89+
7690
def initialize(db_opts, debug, test_env_number)
7791
@debug = debug
7892
@name = SecureRandom.uuid.gsub('-', '')

src/spec/integration_support/uaa_service.rb

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def initialize(sandbox_root, base_log_path)
3838
end
3939

4040
def self.install
41+
return if File.exist?(File.join(UAA_BIN_PATH, 'uaa'))
42+
4143
%w{
4244
/var/vcap/sys/run/uaa
4345
/var/vcap/sys/log/uaa

src/spec/integration_support/verify_multidigest_manager.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'integration_support/constants'
2+
13
module IntegrationSupport
24
class VerifyMultidigestManager
35
def self.install
@@ -16,19 +18,18 @@ def self.installer
1618
end
1719

1820
class VerifyMultidigestBlobInstaller
19-
INSTALL_DIR = File.join(IntegrationSupport::Constants::BOSH_REPO_SRC_DIR, 'tmp', 'integration-verify-multidigest')
20-
2121
def install
22+
return if File.exist?(executable_path)
23+
2224
Dir.chdir(IntegrationSupport::Constants::BOSH_REPO_ROOT) do
23-
run_command("mkdir -p #{INSTALL_DIR}")
2425
run_command('bosh sync-blobs')
2526
run_command("cp blobs/verify-multidigest/verify-multidigest-*-linux-amd64 #{executable_path}")
2627
run_command("chmod +x #{executable_path}")
2728
end
2829
end
2930

3031
def executable_path
31-
File.join(INSTALL_DIR, 'verify-multidigest')
32+
File.join(IntegrationSupport::Constants::INTEGRATION_BIN_DIR, 'verify-multidigest')
3233
end
3334

3435
private

src/tasks/spec.rake

+3-39
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,10 @@ require 'parallel_tests/tasks'
55
namespace :spec do
66
namespace :integration do
77
require 'integration_support/workspace'
8-
require 'integration_support/config_server_service'
9-
require 'integration_support/nginx_service'
10-
require 'integration_support/uaa_service'
11-
require 'integration_support/verify_multidigest_manager'
12-
require 'integration_support/gnatsd_manager'
13-
14-
desc 'Run health monitor integration tests against a local sandbox'
15-
task health_monitor: :install_dependencies do
16-
run_integration_specs(tags: 'hm')
17-
end
18-
19-
desc 'Install BOSH integration test dependencies (currently Nginx, UAA, and Config Server)'
20-
task :install_dependencies do
21-
unless ENV['SKIP_DEPS'] == 'true'
22-
IntegrationSupport::NginxService.install unless ENV['SKIP_NGINX'] == 'true'
23-
24-
IntegrationSupport::UaaService.install unless ENV['SKIP_UAA'] == 'true'
25-
26-
IntegrationSupport::ConfigServerService.install unless ENV['SKIP_CONFIG_SERVER'] == 'true'
27-
28-
IntegrationSupport::VerifyMultidigestManager.install unless ENV['SKIP_VERIFY_MULTIDIGEST'] == 'true'
29-
30-
IntegrationSupport::GnatsdManager.install unless ENV['SKIP_GNATSD'] == 'true'
31-
end
32-
33-
compile_dependencies
34-
end
35-
36-
desc 'Download BOSH Agent. Use only for local dev environment'
37-
task :download_bosh_agent do
38-
trap('INT') { exit }
39-
sh('rm -rf bosh-agent && git clone https://github.com/cloudfoundry/bosh-agent.git')
40-
end
8+
require 'integration_support/sandbox'
419

4210
def run_integration_specs(tags: nil)
11+
IntegrationSupport::Sandbox.install_dependencies
4312
IntegrationSupport::Workspace.clean
4413
IntegrationSupport::Workspace.uaa_service.start
4514

@@ -63,15 +32,10 @@ namespace :spec do
6332
ensure
6433
IntegrationSupport::Workspace.uaa_service.stop
6534
end
66-
67-
def compile_dependencies
68-
puts 'If this fails you may want to run rake spec:integration:download_bosh_agent'
69-
sh('cd bosh-agent && bin/build && cd -')
70-
end
7135
end
7236

7337
desc 'Run all integration tests against a local sandbox'
74-
task integration: %w[spec:integration:install_dependencies] do
38+
task :integration do
7539
run_integration_specs
7640
end
7741

0 commit comments

Comments
 (0)