ruby_yacht 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rdoc_options +8 -2
  4. data/.rspec +1 -0
  5. data/.travis.yml +17 -1
  6. data/Gemfile.lock +18 -2
  7. data/README.md +28 -10
  8. data/bin/ruby_yacht +5 -0
  9. data/doc/TODO.md +1 -20
  10. data/doc/configuration.md +104 -21
  11. data/doc/configuration_sample.rb +19 -8
  12. data/doc/contributing.md +28 -5
  13. data/doc/plugins.md +105 -45
  14. data/lib/ruby_yacht/dsl/app.rb +14 -18
  15. data/lib/ruby_yacht/dsl/configuration.rb +51 -32
  16. data/lib/ruby_yacht/dsl/database.rb +24 -8
  17. data/lib/ruby_yacht/dsl/dsl.rb +32 -4
  18. data/lib/ruby_yacht/dsl/hook.rb +182 -48
  19. data/lib/ruby_yacht/dsl/project.rb +20 -14
  20. data/lib/ruby_yacht/dsl/server_type.rb +14 -31
  21. data/lib/ruby_yacht/dsl/web_server.rb +87 -0
  22. data/lib/ruby_yacht/dsl.rb +1 -0
  23. data/lib/ruby_yacht/images/app/Dockerfile.erb +17 -6
  24. data/lib/ruby_yacht/images/app/before_startup.bash.erb +5 -3
  25. data/lib/ruby_yacht/images/app/startup.bash.erb +5 -2
  26. data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +7 -11
  27. data/lib/ruby_yacht/images/database/Dockerfile.erb +7 -18
  28. data/lib/ruby_yacht/images/database/startup.bash.erb +1 -1
  29. data/lib/ruby_yacht/images/web/Dockerfile.erb +25 -19
  30. data/lib/ruby_yacht/plugins/mysql.rb +18 -8
  31. data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/add_app.rb +5 -5
  32. data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/add_project.rb +3 -3
  33. data/lib/ruby_yacht/plugins/nginx.rb +28 -0
  34. data/lib/ruby_yacht/plugins/rails/scripts/build_new_app.rb +10 -0
  35. data/lib/ruby_yacht/plugins/rails/scripts/update_rails_config.rb +6 -1
  36. data/lib/ruby_yacht/plugins/rails.rb +34 -19
  37. data/lib/ruby_yacht/plugins.rb +2 -1
  38. data/lib/ruby_yacht/runner/build_images.rb +87 -73
  39. data/lib/ruby_yacht/runner/checkout.rb +1 -1
  40. data/lib/ruby_yacht/runner/command.rb +13 -1
  41. data/lib/ruby_yacht/runner/create_new_project.rb +91 -0
  42. data/lib/ruby_yacht/runner/help.rb +1 -1
  43. data/lib/ruby_yacht/runner/run_containers.rb +17 -21
  44. data/lib/ruby_yacht/runner/runner.rb +27 -2
  45. data/lib/ruby_yacht/runner/services.rb +15 -10
  46. data/lib/ruby_yacht/runner/shell.rb +1 -1
  47. data/lib/ruby_yacht/runner/update_hosts.rb +16 -11
  48. data/lib/ruby_yacht/runner.rb +1 -0
  49. data/log/.gitkeep +0 -0
  50. data/ruby_yacht.gemspec +4 -2
  51. data/spec/docker/Dockerfile +19 -3
  52. data/spec/docker/install_gems.bash +5 -0
  53. data/spec/docker/run.bash +44 -0
  54. data/spec/docker/startup.bash +10 -0
  55. data/spec/dsl/app_spec.rb +66 -38
  56. data/spec/dsl/configuration_spec.rb +236 -30
  57. data/spec/dsl/database_spec.rb +103 -4
  58. data/spec/dsl/dsl_spec.rb +46 -3
  59. data/spec/dsl/hook_spec.rb +278 -57
  60. data/spec/dsl/project_spec.rb +75 -45
  61. data/spec/dsl/server_type_spec.rb +52 -12
  62. data/spec/dsl/web_server_spec.rb +160 -0
  63. data/spec/fixtures/apollo-new-project-config +20 -0
  64. data/spec/fixtures/app-dependencies-dockerfile-generic +4 -7
  65. data/spec/fixtures/app-dependencies-dockerfile-generic-with-library-install +6 -10
  66. data/spec/fixtures/app-dependencies-dockerfile-rails +9 -11
  67. data/spec/fixtures/app-dependencies-dockerfile-with-no-repository +20 -0
  68. data/spec/fixtures/database-dockerfile +1 -1
  69. data/spec/fixtures/database-dockerfile-mysql +3 -3
  70. data/spec/fixtures/database-dockerfile-rails +5 -4
  71. data/spec/fixtures/database-dockerfile-rails-with-no-repository +27 -0
  72. data/spec/fixtures/database-dockerfile-with-seed-hooks +3 -3
  73. data/spec/fixtures/database-startup-mysql +2 -1
  74. data/spec/fixtures/mars-before-startup +2 -2
  75. data/spec/fixtures/mars-before-startup-rails +5 -4
  76. data/spec/fixtures/mars-before-startup-with-before-startup-hooks +5 -4
  77. data/spec/fixtures/mars-before-startup-with-custom-file-copy +3 -3
  78. data/spec/fixtures/mars-before-startup-with-no-repository +3 -0
  79. data/spec/fixtures/mars-dockerfile +3 -2
  80. data/spec/fixtures/mars-dockerfile-rails +6 -5
  81. data/spec/fixtures/mars-dockerfile-rails-with-no-repository +32 -0
  82. data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +5 -4
  83. data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +5 -4
  84. data/spec/fixtures/mars-dockerfile-with-custom-file-copy +4 -3
  85. data/spec/fixtures/mars-dockerfile-with-local-database +4 -2
  86. data/spec/fixtures/mars-dockerfile-with-no-repository +22 -0
  87. data/spec/fixtures/mars-dockerfile-with-remote-database +4 -2
  88. data/spec/fixtures/mars-startup +2 -2
  89. data/spec/fixtures/mars-startup-rails +2 -2
  90. data/spec/fixtures/mars-startup-rails-with-no-repository +5 -0
  91. data/spec/fixtures/mars-startup-with-no-repository +4 -0
  92. data/spec/fixtures/web-dockerfile +18 -11
  93. data/spec/fixtures/web-dockerfile-jupiter +28 -0
  94. data/spec/fixtures/web-dockerfile-nginx +38 -0
  95. data/spec/fixtures/web-dockerfile-with-eponymous-app +16 -10
  96. data/spec/fixtures/web-dockerfile-with-primary-app +16 -10
  97. data/spec/integration/build_images_spec.rb +210 -0
  98. data/spec/integration/build_spec.rb +23 -0
  99. data/spec/integration/checkout_spec.rb +94 -0
  100. data/spec/integration/create_new_project_spec.rb +50 -0
  101. data/spec/integration/implode_spec.rb +20 -0
  102. data/spec/integration/run.rb +93 -0
  103. data/spec/integration/run_containers_spec.rb +279 -0
  104. data/spec/integration/services_spec.rb +99 -0
  105. data/spec/integration/shell_spec.rb +31 -0
  106. data/spec/integration/update_hosts_spec.rb +35 -0
  107. data/spec/plugins/mysql_spec.rb +18 -1
  108. data/spec/plugins/nginx_spec.rb +66 -0
  109. data/spec/plugins/rails_spec.rb +61 -89
  110. data/spec/runner/build_images_spec.rb +111 -58
  111. data/spec/runner/command_spec.rb +55 -3
  112. data/spec/runner/create_new_project_spec.rb +93 -0
  113. data/spec/runner/help_spec.rb +5 -1
  114. data/spec/runner/run_containers_spec.rb +22 -10
  115. data/spec/runner/runner_spec.rb +31 -4
  116. data/spec/runner/services_spec.rb +32 -4
  117. data/spec/runner/update_hosts_spec.rb +2 -1
  118. data/spec/spec_helper.rb +16 -1
  119. data/spec/support/integration_helpers.rb +76 -0
  120. data/spec/support/test_project.rb +15 -3
  121. metadata +97 -14
  122. data/spec/docker/build.bash +0 -10
  123. data/spec/fixtures/deploy-dockerfile +0 -2
  124. data/spec/fixtures/multi-project-web-dockerfile +0 -25
  125. /data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/app_config.erb +0 -0
  126. /data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/index.html.erb +0 -0
  127. /data/lib/ruby_yacht/{images/web → plugins/nginx/scripts}/index_config.erb +0 -0
@@ -52,9 +52,61 @@ describe RubyYacht::Runner::Command do
52
52
  end
53
53
 
54
54
  describe "get_machine_info" do
55
- it "gets the property from docker" do
56
- allow(subject).to receive(:backtick).with("docker-machine inspect default -f {{System.Name}}").and_return("Jimmy\n")
57
- expect(subject.get_machine_info('System.Name')).to eq 'Jimmy'
55
+ before do
56
+ allow(subject).to receive(:backtick).with("/usr/local/bin/docker-machine inspect default -f {{System.Name}}").and_return("Jimmy\n")
57
+ end
58
+
59
+ context "with a docker machine" do
60
+ it "gets the property from docker" do
61
+ allow(subject).to receive(:docker_machine).and_return('/usr/local/bin/docker-machine')
62
+ expect(subject.get_machine_info('System.Name')).to eq 'Jimmy'
63
+ end
64
+ end
65
+
66
+ context "with no docker machine" do
67
+ it "returns an empty string" do
68
+ allow(subject).to receive(:docker_machine).and_return('')
69
+ expect(subject.get_machine_info('System.Name')).to eq ''
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'docker_machine' do
75
+ let(:docker_machine) { subject.docker_machine }
76
+
77
+ before do
78
+ RubyYacht.configuration.clear
79
+ end
80
+
81
+ context 'with docker-machine installed' do
82
+ before do
83
+ allow(subject).to receive(:backtick).with('which docker-machine').and_return("/usr/bin/docker-machine\n")
84
+ end
85
+
86
+ it 'is the path to docker-machine' do
87
+ expect(docker_machine).to eq '/usr/bin/docker-machine'
88
+ end
89
+ end
90
+
91
+ context 'with docker-machine not installed' do
92
+ before do
93
+ allow(subject).to receive(:backtick).with('which docker-machine').and_return('')
94
+ end
95
+
96
+ it 'is an empty string' do
97
+ expect(docker_machine).to eq ''
98
+ end
99
+ end
100
+
101
+ context 'with docker-machine disabled' do
102
+ before do
103
+ allow(subject).to receive(:backtick).with('which docker-machine').and_return('/usr/bin/docker-machine')
104
+ RubyYacht.configuration.disable_docker_machine = true
105
+ end
106
+
107
+ it 'is an empty string' do
108
+ expect(docker_machine).to eq ''
109
+ end
58
110
  end
59
111
  end
60
112
 
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyYacht::Runner::CreateNewProject do
4
+ include DockerCommandSpec
5
+
6
+ describe 'command information' do
7
+ specify { expect(described_class.command).to eq 'new' }
8
+ specify { expect(described_class.description).to eq 'Create a new ruby-yacht project' }
9
+
10
+ describe 'command-line parsing' do
11
+ let(:options) { subject.option_parser }
12
+
13
+ it 'gives a summary in the banner' do
14
+ expect(options.banner).to eq "Usage: rspec new [PROJECT] [DIRECTORY]\n\nCreate a new ruby-yacht project"
15
+ end
16
+
17
+ it 'takes the project and directory from the command line' do
18
+ subject.parse_positional_arguments(['apollo', 'apollo-config'])
19
+ expect(subject.project).to eq 'apollo'
20
+ expect(subject.directory).to eq 'apollo-config'
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "run behavior" do
26
+ before do
27
+ subject.project = 'apollo'
28
+ subject.directory = 'apollo-config'
29
+ end
30
+
31
+ after do
32
+ FileUtils.rm_rf('apollo-config')
33
+ end
34
+
35
+ it 'creates a project file' do
36
+ subject.run
37
+ path = './apollo-config/run.rb'
38
+ expect(File.exist?(path)).to be_truthy
39
+ contents = File.read(path)
40
+ expected = File.read('spec/fixtures/apollo-new-project-config')
41
+ expect(contents).to eq expected
42
+ end
43
+
44
+ it 'logs a message about the results' do
45
+ subject.run
46
+ expect(@log_entries).to eq [
47
+ 'Your project has been created in apollo-config/run.rb.',
48
+ 'You can go to apollo-config and run `ruby run.rb build` to create your docker containers.',
49
+ 'Your initial app will be created in the apollo directory.'
50
+ ]
51
+ end
52
+
53
+ it "returns true" do
54
+ expect(subject.run).to be_truthy
55
+ end
56
+
57
+ context 'with no project' do
58
+ before do
59
+ subject.project = nil
60
+ end
61
+
62
+ it 'logs an error' do
63
+ subject.run
64
+ expect(@log_entries).to eq [
65
+ 'You must provide a project',
66
+ 'Run rspec help new for more information'
67
+ ]
68
+ end
69
+
70
+ it 'returns false' do
71
+ expect(subject.run).to be_falsey
72
+ end
73
+ end
74
+
75
+ context 'with no directory' do
76
+ before do
77
+ subject.directory = nil
78
+ end
79
+
80
+ it 'logs an error' do
81
+ subject.run
82
+ expect(@log_entries).to eq [
83
+ 'You must provide a directory',
84
+ 'Run rspec help new for more information'
85
+ ]
86
+ end
87
+
88
+ it 'returns false' do
89
+ expect(subject.run).to be_falsey
90
+ end
91
+ end
92
+ end
93
+ end
@@ -23,11 +23,15 @@ describe RubyYacht::Runner::Help do
23
23
  end
24
24
 
25
25
  describe "run behavior" do
26
+ before do
27
+ RubyYacht::Runner.load_default_commands
28
+ end
29
+
26
30
  context "with no command" do
27
31
  it "prints the available commands" do
28
32
  subject.run
29
33
  expected = ["Available commands: \n\n"]
30
- expected += RubyYacht::Runner.commands.map { |c| "#{c.name}: #{c.description}" }
34
+ expected += RubyYacht::Runner.commands.map { |c| "#{c.command}: #{c.description}" }
31
35
  expected << "\nRun rspec help [command] for more information on a command"
32
36
  expect(@log_entries).to eq expected
33
37
  end
@@ -17,7 +17,7 @@ describe RubyYacht::Runner::RunContainers do
17
17
  docker.fail_unexpected_commands!
18
18
  docker.expect 'run -d --net=apollo --net-alias=apollo-mars --name=apollo-mars apollo-mars'
19
19
  docker.expect 'run -d --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
20
- docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-web --name=apollo-web apollo-web'
20
+ docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-nginx --name=apollo-nginx apollo-nginx'
21
21
  subject.run
22
22
  end
23
23
 
@@ -25,7 +25,7 @@ describe RubyYacht::Runner::RunContainers do
25
25
  subject.run
26
26
  expect(subject).to have_received(:remove_container).with('apollo-mars')
27
27
  expect(subject).to have_received(:remove_container).with('apollo-saturn')
28
- expect(subject).to have_received(:remove_container).with('apollo-web')
28
+ expect(subject).to have_received(:remove_container).with('apollo-nginx')
29
29
  end
30
30
 
31
31
  it "returns true" do
@@ -58,13 +58,14 @@ describe RubyYacht::Runner::RunContainers do
58
58
  end
59
59
 
60
60
  it "runs the containers for both projects" do
61
- docker.fail_unexpected_commands!
62
- docker.expect 'run -d --net=apollo --net-alias=apollo-mars --name=apollo-mars apollo-mars'
63
- docker.expect 'run -d --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
64
- docker.expect 'run -d --net=apollo --net-alias=jupiter-venus --name=jupiter-venus jupiter-venus'
65
- docker.expect 'run -d --net=apollo --net-alias=jupiter-saturn --name=jupiter-saturn jupiter-saturn'
66
- docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-web --name=apollo-web apollo-web'
67
- subject.run
61
+ docker.fail_unexpected_commands!
62
+ docker.expect 'run -d --net=apollo --net-alias=apollo-mars --name=apollo-mars apollo-mars'
63
+ docker.expect 'run -d --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
64
+ docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-nginx --name=apollo-nginx apollo-nginx'
65
+ docker.expect 'run -d --net=apollo --net-alias=jupiter-venus --name=jupiter-venus jupiter-venus'
66
+ docker.expect 'run -d --net=apollo --net-alias=jupiter-saturn --name=jupiter-saturn jupiter-saturn'
67
+ docker.expect 'run -d -p 80:80 --net=apollo --net-alias=jupiter-web --name=jupiter-web jupiter-web'
68
+ subject.run
68
69
  end
69
70
 
70
71
  it "returns true" do
@@ -115,7 +116,18 @@ describe RubyYacht::Runner::RunContainers do
115
116
  docker.fail_unexpected_commands!
116
117
  docker.expect 'run -d --net=apollo --net-alias=apollo --name=apollo apollo'
117
118
  docker.expect 'run -d --net=apollo --net-alias=apollo-saturn --name=apollo-saturn apollo-saturn'
118
- docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-web --name=apollo-web apollo-web'
119
+ docker.expect 'run -d -p 80:80 --net=apollo --net-alias=apollo-nginx --name=apollo-nginx apollo-nginx'
120
+ subject.run
121
+ end
122
+ end
123
+
124
+ context 'with a special port for the web server' do
125
+ before do
126
+ RubyYacht.configuration.projects.first.web_servers.first.port = 3000
127
+ end
128
+
129
+ it 'maps the specified port on the host to port 80 in the container' do
130
+ docker.expect 'run -d -p 3000:80 --net=apollo --net-alias=apollo-nginx --name=apollo-nginx apollo-nginx'
119
131
  subject.run
120
132
  end
121
133
  end
@@ -6,10 +6,37 @@ describe RubyYacht::Runner do
6
6
  allow(described_class).to receive(:exit)
7
7
  end
8
8
 
9
- describe "commands" do
10
- it "contains all the defined commands" do
11
- commands = ObjectSpace.each_object(Class).select { |klass| klass < RubyYacht::Runner::Command && klass.inspect =~ /^RubyYacht::Runner/ }.uniq
12
- expect(described_class.commands.sort_by(&:name)).to eq commands.sort_by(&:name)
9
+ describe "load_default_commands" do
10
+ before do
11
+ RubyYacht::Runner.clear_commands
12
+ end
13
+
14
+ after do
15
+ RubyYacht::Runner.clear_commands
16
+ end
17
+
18
+ context 'with the in_project flag set to true' do
19
+ before do
20
+ RubyYacht::Runner.load_default_commands(true)
21
+ end
22
+
23
+ it 'contains all the defined commands' do
24
+ classes = %w(Help Build BuildImages RunContainers Services Checkout Shell UpdateHosts Implode)
25
+ classes = classes.map { |klass| "RubyYacht::Runner::#{klass}" }
26
+ expect(described_class.commands.map(&:name)).to eq classes
27
+ end
28
+ end
29
+
30
+ context 'with the in_project flag set to false' do
31
+ before do
32
+ RubyYacht::Runner.load_default_commands(false)
33
+ end
34
+
35
+ it 'contains all the defined commands' do
36
+ classes = %w(Help CreateNewProject)
37
+ classes = classes.map { |klass| "RubyYacht::Runner::#{klass}" }
38
+ expect(described_class.commands.map(&:name)).to eq classes
39
+ end
13
40
  end
14
41
  end
15
42
 
@@ -29,7 +29,7 @@ describe RubyYacht::Runner::Services do
29
29
  docker.fail_unexpected_commands!
30
30
  docker.expect 'stop apollo-mars'
31
31
  docker.expect 'stop apollo-saturn'
32
- docker.expect 'stop apollo-web'
32
+ docker.expect 'stop apollo-nginx'
33
33
  subject.run
34
34
  end
35
35
 
@@ -59,8 +59,8 @@ describe RubyYacht::Runner::Services do
59
59
 
60
60
  context "with a docker machine" do
61
61
  before do
62
- allow(subject).to receive(:backtick).with('which docker-machine').and_return '/usr/bin/docker-machine'
63
- allow(subject).to receive(:backtick).with('docker-machine env default').and_return "# Test\nexport TEST_VAL=\"123\""
62
+ allow(subject).to receive(:docker_machine).and_return '/usr/bin/docker-machine'
63
+ allow(subject).to receive(:backtick).with('/usr/bin/docker-machine env default').and_return "# Test\nexport TEST_VAL=\"123\""
64
64
  ENV.delete('TEST_VAL')
65
65
  end
66
66
 
@@ -75,7 +75,7 @@ describe RubyYacht::Runner::Services do
75
75
 
76
76
  it "starts the docker machine" do
77
77
  subject.run
78
- expect(@system_commands).to eq ['docker-machine start default']
78
+ expect(@system_commands).to eq ['/usr/bin/docker-machine start default']
79
79
  expect(ENV['TEST_VAL']).to eq '123'
80
80
  end
81
81
 
@@ -101,6 +101,34 @@ describe RubyYacht::Runner::Services do
101
101
  end
102
102
  end
103
103
 
104
+ context "with no docker machine" do
105
+ before do
106
+ allow(subject).to receive(:docker_machine).and_return ''
107
+ allow(subject).to receive(:backtick).with('docker-machine env default').and_return "# Test\nexport TEST_VAL=\"123\""
108
+ ENV.delete('TEST_VAL')
109
+ end
110
+
111
+ after do
112
+ ENV.delete('TEST_VAL')
113
+ end
114
+
115
+ context "with the start command" do
116
+ before do
117
+ subject.command = 'start'
118
+ end
119
+
120
+ it "does not start the docker machine" do
121
+ subject.run
122
+ expect(@system_commands).to eq []
123
+ expect(ENV['TEST_VAL']).to be_nil
124
+ end
125
+
126
+ it "returns true" do
127
+ expect(subject.run).to be_truthy
128
+ end
129
+ end
130
+ end
131
+
104
132
  context "with no command" do
105
133
  before do
106
134
  subject.command = nil
@@ -59,8 +59,9 @@ describe RubyYacht::Runner::UpdateHosts do
59
59
 
60
60
  it "copies the hosts file to a backup, and the tmp hosts file to the hosts file" do
61
61
  timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
62
+ allow(subject).to receive(:backtick).with('which sudo').and_return('/usr/bin/sudo')
62
63
  subject.run
63
- expect(@system_commands).to eq ["sudo cp /etc/hosts /etc/hosts.#{timestamp}.backup", "sudo mv tmp/hosts /etc/hosts"]
64
+ expect(@system_commands).to eq ["/usr/bin/sudo cp /etc/hosts /etc/hosts.#{timestamp}.backup", "/usr/bin/sudo cat tmp/hosts > /etc/hosts"]
64
65
  end
65
66
 
66
67
  it "returns true" do
data/spec/spec_helper.rb CHANGED
@@ -6,5 +6,20 @@ SimpleCov.start do
6
6
  end
7
7
 
8
8
  require 'ruby_yacht'
9
+ require 'byebug'
10
+ require 'timecop'
9
11
 
10
- Dir[File.join('.', 'spec', 'support', '**', '*.rb')].each { |f| require f }
12
+ Dir[File.join('.', 'spec', 'support', '**', '*.rb')].each { |f| require f }
13
+
14
+ unless File.exist?("~/.ssh/id_rsa")
15
+ system "touch ~/.ssh/id_rsa"
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ if ENV['PRESERVE_IMAGES'] != '1'
20
+ config.after :suite do
21
+ IntegrationHelpers.clear_docker_containers
22
+ IntegrationHelpers.clear_docker_images
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,76 @@
1
+ module IntegrationHelpers
2
+ def configure_project
3
+ IntegrationHelpers.clear_docker_containers
4
+ system "docker network rm apollo 1> /dev/null 2> /dev/null"
5
+ end
6
+
7
+ def run_command(command, environment: {}, capture_output: false)
8
+ full_command = "ruby spec/integration/run.rb #{command}"
9
+ environment.each do |key, value|
10
+ full_command = "#{key}=#{value} #{full_command}"
11
+ end
12
+ if capture_output
13
+ `#{full_command}`
14
+ else
15
+ system "#{full_command} 1> log/integration_stdout.txt 2> log/integration_stderr.txt"
16
+ end
17
+ end
18
+
19
+ def run_command_in_docker(image, command)
20
+ `docker run --net=apollo --rm apollo-#{image} #{command}`
21
+ end
22
+
23
+ def wait_on_command_success(command)
24
+ Timeout::timeout(60) do
25
+ found = false
26
+ while !found
27
+ result = system "#{command} 1> /dev/null 2> /dev/null"
28
+ found ||= !result.nil?
29
+ break if found
30
+ sleep 0.1
31
+ end
32
+ end
33
+ end
34
+
35
+ def wait_on_command_result(command, matchers)
36
+ timeout = matchers.delete(:timeout) || 60
37
+ Timeout::timeout(timeout) do
38
+ found = false
39
+ while !found
40
+ result = `#{command} 2>&1`
41
+ found ||= matchers[:contains] && result.include?(matchers[:contains])
42
+ found ||= matchers[:does_not_contain] && !result.include?(matchers[:does_not_contain])
43
+ break if found
44
+ sleep 0.1
45
+ end
46
+ end
47
+ end
48
+
49
+ def restore_hosts_file
50
+ backup_path = Dir["/etc/hosts*.backup"].last
51
+ if backup_path == nil
52
+ raise "Missing backup file"
53
+ end
54
+ system "cat #{backup_path} > /etc/hosts"
55
+ system "rm #{backup_path}"
56
+ end
57
+
58
+ def self.image_names
59
+ images = %w(rails-app-dependencies saturn mars database web).map { |n| "apollo-#{n}"}
60
+ images += %w(rails-app-dependencies saturn database web).map { |n| "jupiter-#{n}"}
61
+ images += %w(apollo)
62
+ images
63
+ end
64
+
65
+ def self.clear_docker_images
66
+ image_names.each { |name| system "docker rmi #{name} 1> /dev/null 2> /dev/null" }
67
+ end
68
+
69
+ def self.clear_docker_containers
70
+ image_names.each { |name| system "docker rm -f #{name} 1> /dev/null 2> /dev/null" }
71
+ end
72
+
73
+ def self.clear_checkout_folders
74
+ `docker run --rm -v $PWD/..:/var/code ruby:2.3 bash -c 'rm -r /var/code/mars; rm -r /var/code/saturn'`
75
+ end
76
+ end
@@ -10,11 +10,17 @@ module RubyYacht
10
10
  container_type :app
11
11
  baseline_image 'debian'
12
12
  end
13
+
14
+ server_type :nginx do
15
+ container_type :web
16
+ baseline_image 'ubuntu'
17
+ end
13
18
  end
14
19
 
15
20
  RubyYacht.configure do
16
21
  during :startup do
17
- server_type :generic
22
+ app_server_type :generic
23
+ container_type :app
18
24
  command '/var/docker/start_app.bash'
19
25
  end
20
26
  end
@@ -26,7 +32,6 @@ module RubyYacht
26
32
  RubyYacht.configure do
27
33
  project :apollo do
28
34
  system_prefix :apollo
29
- domain "apollo.test.com"
30
35
  repository "github.com"
31
36
 
32
37
  generic_app :mars do
@@ -36,6 +41,10 @@ module RubyYacht
36
41
  debian_app :saturn do
37
42
  repository_name 'brownleej/saturn'
38
43
  end
44
+
45
+ nginx_web_server :nginx do
46
+ domain 'apollo.test.com'
47
+ end
39
48
  end
40
49
  end
41
50
  end
@@ -44,7 +53,6 @@ module RubyYacht
44
53
  RubyYacht.configure do
45
54
  project :jupiter do
46
55
  system_prefix :jupiter
47
- domain "jupiter.test.com"
48
56
  repository "github.com"
49
57
 
50
58
  debian_app :venus do
@@ -54,6 +62,10 @@ module RubyYacht
54
62
  debian_app :saturn do
55
63
  repository_name 'brownleej/saturn'
56
64
  end
65
+
66
+ nginx_web_server do
67
+ domain 'jupiter.test.com'
68
+ end
57
69
  end
58
70
  end
59
71
  end