ruby_yacht 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -5
- data/doc/TODO.md +1 -5
- data/doc/configuration.md +51 -0
- data/doc/plugins.md +4 -0
- data/lib/ruby_yacht/dsl/configuration.rb +26 -1
- data/lib/ruby_yacht/dsl/dsl.rb +35 -3
- data/lib/ruby_yacht/dsl/hook.rb +4 -0
- data/lib/ruby_yacht/dsl/project.rb +11 -0
- data/lib/ruby_yacht/images/app/Dockerfile.erb +2 -1
- data/lib/ruby_yacht/images/app/checkout.bash +1 -1
- data/lib/ruby_yacht/images/app-dependencies/Dockerfile.erb +7 -1
- data/lib/ruby_yacht/images/database/Dockerfile.erb +3 -1
- data/lib/ruby_yacht/images/database/checkout.bash +3 -4
- data/lib/ruby_yacht/images/web/Dockerfile.erb +2 -0
- data/lib/ruby_yacht/plugins/nginx.rb +5 -0
- data/lib/ruby_yacht/plugins/rails/scripts/load_seeds.rb +10 -1
- data/lib/ruby_yacht/plugins/rails/scripts/prepare_rails_for_launch.rb +1 -1
- data/lib/ruby_yacht/plugins/rails/scripts/update_rails_config.rb +6 -4
- data/lib/ruby_yacht/plugins/rails.rb +30 -17
- data/lib/ruby_yacht/plugins.rb +1 -1
- data/lib/ruby_yacht/runner/build_images.rb +5 -7
- data/lib/ruby_yacht/runner/run_containers.rb +1 -2
- data/ruby_yacht.gemspec +2 -2
- data/spec/docker/run.bash +4 -0
- data/spec/dsl/configuration_spec.rb +29 -0
- data/spec/dsl/dsl_spec.rb +56 -0
- data/spec/dsl/hook_spec.rb +28 -5
- data/spec/dsl/project_spec.rb +46 -0
- data/spec/dsl/server_type_spec.rb +3 -0
- data/spec/fixtures/app-dependencies-dockerfile-generic +3 -1
- data/spec/fixtures/app-dependencies-dockerfile-generic-with-library-install +3 -1
- data/spec/fixtures/app-dependencies-dockerfile-rails +4 -3
- data/spec/fixtures/app-dependencies-dockerfile-rails-production +35 -0
- data/spec/fixtures/app-dependencies-dockerfile-with-https-repository +25 -0
- data/spec/fixtures/app-dependencies-dockerfile-with-no-repository +2 -0
- data/spec/fixtures/database-dockerfile +1 -1
- data/spec/fixtures/database-dockerfile-mysql +1 -1
- data/spec/fixtures/database-dockerfile-rails +2 -6
- data/spec/fixtures/database-dockerfile-rails-mysql +38 -0
- data/spec/fixtures/database-dockerfile-rails-with-no-repository +1 -3
- data/spec/fixtures/database-dockerfile-with-seed-hooks +1 -1
- data/spec/fixtures/local_config.yml +8 -0
- data/spec/fixtures/mars-dockerfile +0 -1
- data/spec/fixtures/mars-dockerfile-rails +0 -1
- data/spec/fixtures/mars-dockerfile-rails-with-no-repository +0 -1
- data/spec/fixtures/mars-dockerfile-with-after-checkout-hooks +0 -1
- data/spec/fixtures/mars-dockerfile-with-before-startup-hooks +0 -1
- data/spec/fixtures/mars-dockerfile-with-custom-file-copy +0 -1
- data/spec/fixtures/mars-dockerfile-with-local-database +0 -1
- data/spec/fixtures/mars-dockerfile-with-no-repository +0 -1
- data/spec/fixtures/mars-dockerfile-with-remote-database +0 -1
- data/spec/fixtures/mars-startup-rails +1 -1
- data/spec/fixtures/mars-startup-rails-with-no-repository +1 -1
- data/spec/fixtures/web-dockerfile-nginx +3 -0
- data/spec/integration/01_normal_config_spec.rb +352 -0
- data/spec/integration/{create_new_project_spec.rb → 02_creating_new_project_spec.rb} +2 -2
- data/spec/integration/03_no_repository_spec.rb +56 -0
- data/spec/integration/04_no_database_spec.rb +58 -0
- data/spec/integration/05_https_repository_spec.rb +52 -0
- data/spec/integration/06_production_environment_spec.rb +72 -0
- data/spec/integration/07_local_checkout_spec.rb +52 -0
- data/spec/integration/08_multiple_projects_spec.rb +46 -0
- data/spec/integration/09_titular_app_spec.rb +53 -0
- data/spec/integration/10_misc_scenarios_spec.rb +97 -0
- data/spec/integration/run.rb +18 -2
- data/spec/plugins/rails_spec.rb +73 -16
- data/spec/runner/build_images_spec.rb +17 -1
- data/spec/runner/run_containers_spec.rb +3 -3
- data/spec/support/integration_helpers.rb +18 -4
- metadata +30 -20
- data/spec/integration/build_images_spec.rb +0 -210
- data/spec/integration/build_spec.rb +0 -23
- data/spec/integration/checkout_spec.rb +0 -94
- data/spec/integration/implode_spec.rb +0 -20
- data/spec/integration/run_containers_spec.rb +0 -279
- data/spec/integration/services_spec.rb +0 -99
- data/spec/integration/shell_spec.rb +0 -31
- data/spec/integration/update_hosts_spec.rb +0 -35
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
FROM ubuntu
|
8
8
|
|
9
|
+
ENV REPOSITORY_HOST ssh://git@github.com
|
10
|
+
|
9
11
|
RUN mkdir -p /root/.ssh
|
10
12
|
COPY id_rsa /root/.ssh
|
11
13
|
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
|
@@ -15,7 +17,7 @@ RUN mkdir -p /var/code/
|
|
15
17
|
|
16
18
|
RUN apt-get update && apt-get upgrade -y
|
17
19
|
|
18
|
-
RUN git clone
|
20
|
+
RUN git clone $REPOSITORY_HOST/brownleej/mars /var/code/mars
|
19
21
|
WORKDIR /var/code/mars
|
20
22
|
|
21
23
|
RUN rm -f /var/docker/*
|
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
FROM ubuntu
|
8
8
|
|
9
|
+
ENV REPOSITORY_HOST ssh://git@github.com
|
10
|
+
|
9
11
|
RUN mkdir -p /root/.ssh
|
10
12
|
COPY id_rsa /root/.ssh
|
11
13
|
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
|
@@ -15,7 +17,7 @@ RUN mkdir -p /var/code/
|
|
15
17
|
|
16
18
|
RUN apt-get update && apt-get upgrade -y
|
17
19
|
|
18
|
-
RUN git clone
|
20
|
+
RUN git clone $REPOSITORY_HOST/brownleej/mars /var/code/mars
|
19
21
|
WORKDIR /var/code/mars
|
20
22
|
COPY hook2.rb /var/docker/
|
21
23
|
RUN ruby /var/docker/hook2.rb
|
@@ -6,7 +6,8 @@
|
|
6
6
|
|
7
7
|
FROM ruby:2.3
|
8
8
|
|
9
|
-
ENV
|
9
|
+
ENV REPOSITORY_HOST ssh://git@github.com
|
10
|
+
|
10
11
|
ENV SECRET_KEY_BASE abc
|
11
12
|
ENV EXCLUDED_GEM_GROUPS ""
|
12
13
|
|
@@ -19,12 +20,12 @@ RUN mkdir -p /var/code/
|
|
19
20
|
|
20
21
|
RUN apt-get update && apt-get upgrade -y
|
21
22
|
|
22
|
-
RUN git clone
|
23
|
+
RUN git clone $REPOSITORY_HOST/brownleej/mars /var/code/mars
|
23
24
|
WORKDIR /var/code/mars
|
24
25
|
COPY install_gems.rb /var/docker/
|
25
26
|
RUN ruby /var/docker/install_gems.rb
|
26
27
|
|
27
|
-
RUN git clone
|
28
|
+
RUN git clone $REPOSITORY_HOST/brownleej/saturn /var/code/saturn
|
28
29
|
WORKDIR /var/code/saturn
|
29
30
|
COPY install_gems.rb /var/docker/
|
30
31
|
RUN ruby /var/docker/install_gems.rb
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This Dockerfile creates an image for installing all of the dependencies
|
2
|
+
# for all of the apps.
|
3
|
+
#
|
4
|
+
# This is a slow process, so this should be kept as simple as possible so that
|
5
|
+
# it can remain unchanged.
|
6
|
+
|
7
|
+
FROM ruby:2.3
|
8
|
+
|
9
|
+
ENV REPOSITORY_HOST ssh://git@github.com
|
10
|
+
ENV RAILS_ENV production
|
11
|
+
ENV SECRET_KEY_BASE abc
|
12
|
+
ENV EXCLUDED_GEM_GROUPS ""
|
13
|
+
|
14
|
+
RUN mkdir -p /root/.ssh
|
15
|
+
COPY id_rsa /root/.ssh
|
16
|
+
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
|
17
|
+
|
18
|
+
RUN mkdir -p /var/docker/
|
19
|
+
RUN mkdir -p /var/code/
|
20
|
+
|
21
|
+
RUN apt-get update && apt-get upgrade -y
|
22
|
+
|
23
|
+
RUN git clone $REPOSITORY_HOST/brownleej/mars /var/code/mars
|
24
|
+
WORKDIR /var/code/mars
|
25
|
+
COPY install_gems.rb /var/docker/
|
26
|
+
RUN ruby /var/docker/install_gems.rb
|
27
|
+
|
28
|
+
RUN git clone $REPOSITORY_HOST/brownleej/saturn /var/code/saturn
|
29
|
+
WORKDIR /var/code/saturn
|
30
|
+
COPY install_gems.rb /var/docker/
|
31
|
+
RUN ruby /var/docker/install_gems.rb
|
32
|
+
|
33
|
+
RUN rm -f /var/docker/*
|
34
|
+
|
35
|
+
WORKDIR /
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# This Dockerfile creates an image for installing all of the dependencies
|
2
|
+
# for all of the apps.
|
3
|
+
#
|
4
|
+
# This is a slow process, so this should be kept as simple as possible so that
|
5
|
+
# it can remain unchanged.
|
6
|
+
|
7
|
+
FROM ubuntu
|
8
|
+
|
9
|
+
ENV REPOSITORY_HOST https://github.com
|
10
|
+
|
11
|
+
RUN mkdir -p /root/.ssh
|
12
|
+
COPY id_rsa /root/.ssh
|
13
|
+
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
|
14
|
+
|
15
|
+
RUN mkdir -p /var/docker/
|
16
|
+
RUN mkdir -p /var/code/
|
17
|
+
|
18
|
+
RUN apt-get update && apt-get upgrade -y
|
19
|
+
|
20
|
+
RUN git clone $REPOSITORY_HOST/brownleej/mars /var/code/mars
|
21
|
+
WORKDIR /var/code/mars
|
22
|
+
|
23
|
+
RUN rm -f /var/docker/*
|
24
|
+
|
25
|
+
WORKDIR /
|
@@ -16,7 +16,7 @@ RUN apt-get install -y mysql-server
|
|
16
16
|
COPY setup.bash /var/docker/
|
17
17
|
RUN bash /var/docker/setup.bash
|
18
18
|
|
19
|
-
RUN /var/docker/checkout.bash
|
19
|
+
RUN /var/docker/checkout.bash mars brownleej/mars
|
20
20
|
WORKDIR /var/code/mars
|
21
21
|
|
22
22
|
RUN rm -r /var/code
|
@@ -10,15 +10,11 @@ COPY startup.bash /var/docker/startup.bash
|
|
10
10
|
|
11
11
|
RUN chmod u+x /var/docker/*
|
12
12
|
|
13
|
-
RUN /var/docker/checkout.bash
|
13
|
+
RUN /var/docker/checkout.bash mars brownleej/mars
|
14
14
|
WORKDIR /var/code/mars
|
15
|
-
COPY load_seeds.rb /var/docker/
|
16
|
-
RUN ruby /var/docker/load_seeds.rb
|
17
15
|
|
18
|
-
RUN /var/docker/checkout.bash
|
16
|
+
RUN /var/docker/checkout.bash saturn brownleej/saturn
|
19
17
|
WORKDIR /var/code/saturn
|
20
|
-
COPY load_seeds.rb /var/docker/
|
21
|
-
RUN ruby /var/docker/load_seeds.rb
|
22
18
|
|
23
19
|
RUN rm -r /var/code
|
24
20
|
WORKDIR /
|
@@ -0,0 +1,38 @@
|
|
1
|
+
FROM apollo-rails-app-dependencies
|
2
|
+
|
3
|
+
ENV DATABASE_USERNAME apollo
|
4
|
+
ENV DATABASE_PASSWORD test
|
5
|
+
ENV DATABASE_NAME apollo
|
6
|
+
ENV DATABASE_TYPE mysql
|
7
|
+
|
8
|
+
COPY checkout.bash /var/docker/checkout.bash
|
9
|
+
COPY startup.bash /var/docker/startup.bash
|
10
|
+
|
11
|
+
RUN chmod u+x /var/docker/*
|
12
|
+
|
13
|
+
ENV DEBIAN_FRONTEND noninteractive
|
14
|
+
RUN apt-get install -y mysql-server
|
15
|
+
|
16
|
+
COPY setup.bash /var/docker/
|
17
|
+
RUN bash /var/docker/setup.bash
|
18
|
+
|
19
|
+
RUN /var/docker/checkout.bash mars brownleej/mars
|
20
|
+
WORKDIR /var/code/mars
|
21
|
+
COPY load_seeds.rb /var/docker/
|
22
|
+
RUN ruby /var/docker/load_seeds.rb
|
23
|
+
|
24
|
+
RUN /var/docker/checkout.bash saturn brownleej/saturn
|
25
|
+
WORKDIR /var/code/saturn
|
26
|
+
COPY load_seeds.rb /var/docker/
|
27
|
+
RUN ruby /var/docker/load_seeds.rb
|
28
|
+
|
29
|
+
RUN rm -r /var/code
|
30
|
+
WORKDIR /
|
31
|
+
|
32
|
+
ENV DATABASE_USERNAME ''
|
33
|
+
ENV DATABASE_PASSWORD ''
|
34
|
+
ENV DATABASE_NAME ''
|
35
|
+
|
36
|
+
EXPOSE 1234
|
37
|
+
|
38
|
+
CMD /var/docker/startup.bash
|
@@ -10,10 +10,8 @@ COPY startup.bash /var/docker/startup.bash
|
|
10
10
|
|
11
11
|
RUN chmod u+x /var/docker/*
|
12
12
|
|
13
|
-
RUN /var/docker/checkout.bash
|
13
|
+
RUN /var/docker/checkout.bash saturn brownleej/saturn
|
14
14
|
WORKDIR /var/code/saturn
|
15
|
-
COPY load_seeds.rb /var/docker/
|
16
|
-
RUN ruby /var/docker/load_seeds.rb
|
17
15
|
|
18
16
|
RUN rm -r /var/code
|
19
17
|
WORKDIR /
|
@@ -10,7 +10,7 @@ COPY startup.bash /var/docker/startup.bash
|
|
10
10
|
|
11
11
|
RUN chmod u+x /var/docker/*
|
12
12
|
|
13
|
-
RUN /var/docker/checkout.bash
|
13
|
+
RUN /var/docker/checkout.bash mars brownleej/mars
|
14
14
|
WORKDIR /var/code/mars
|
15
15
|
COPY hook1.rb /var/docker/
|
16
16
|
RUN ruby /var/docker/hook1.rb
|
@@ -0,0 +1,352 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'normal config', :integration do
|
4
|
+
include IntegrationHelpers
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
run_command 'build_images'
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
IntegrationHelpers.clear_docker_containers
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'building images' do
|
15
|
+
after do
|
16
|
+
system 'docker rm -f apollo-database 1> /dev/null 2> /dev/null'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "creates images for the app, dependencies, database, and web server" do
|
20
|
+
expect(images).to eq ['apollo-database', 'apollo-mars', 'apollo-rails-app-dependencies', 'apollo-saturn', 'apollo-web']
|
21
|
+
end
|
22
|
+
|
23
|
+
it "populates the tables in the database image" do
|
24
|
+
start_database
|
25
|
+
|
26
|
+
results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database -e "use apollo; show tables"'
|
27
|
+
results = results.split("\n").collect { |line| line.delete('|').strip }.sort
|
28
|
+
results.shift
|
29
|
+
expect(results).to eq %w(clients posts schema_migrations users)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "populates the seed data in the database image" do
|
33
|
+
start_database
|
34
|
+
|
35
|
+
results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database -e "select count(*) FROM apollo.users"'
|
36
|
+
results = results.split("\n").collect { |line| line.delete('|').strip }
|
37
|
+
results.shift
|
38
|
+
expect(results).to eq ['1']
|
39
|
+
|
40
|
+
results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database -e "select name FROM apollo.clients"'
|
41
|
+
results = results.split("\n").collect { |line| line.delete('|').strip }
|
42
|
+
results.shift
|
43
|
+
expect(results).to eq ['Test Client']
|
44
|
+
end
|
45
|
+
|
46
|
+
it "creates a test database" do
|
47
|
+
start_database
|
48
|
+
|
49
|
+
results = run_command_in_docker :mars, 'mysql -uapollo -ptestpass -hapollo-database apollo_test 2>&1'
|
50
|
+
expect(results).not_to include 'ERROR'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "installs the gems on the app dependency image" do
|
54
|
+
results = run_command_in_docker 'rails-app-dependencies', 'gem list'
|
55
|
+
expect(results).to include 'mysql2'
|
56
|
+
expect(results).to include 'sass-rails'
|
57
|
+
expect(results).to include 'byebug'
|
58
|
+
expect(results).to include 'factory_girl'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "leaves all the apps checked out on the app dependency image" do
|
62
|
+
results = run_command_in_docker 'rails-app-dependencies', 'ls /var/code'
|
63
|
+
folders = results.split("\n")
|
64
|
+
expect(folders).to include 'mars'
|
65
|
+
expect(folders).to include 'saturn'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "installs the gems on the app images" do
|
69
|
+
results = run_command_in_docker :mars, 'gem list'
|
70
|
+
expect(results).to include 'mysql2'
|
71
|
+
expect(results).not_to include 'sass-rails'
|
72
|
+
expect(results).to include 'byebug'
|
73
|
+
expect(results).to include 'factory_girl'
|
74
|
+
|
75
|
+
results = run_command_in_docker :saturn, 'gem list'
|
76
|
+
expect(results).to include 'mysql2'
|
77
|
+
expect(results).to include 'sass-rails'
|
78
|
+
expect(results).not_to include 'byebug'
|
79
|
+
expect(results).not_to include 'factory_girl'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'installs mysql on the app images' do
|
83
|
+
results = run_command_in_docker :mars, 'which mysql'
|
84
|
+
expect(results).to eq "/usr/bin/mysql\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "checks out just the single app on the app image" do
|
88
|
+
results = run_command_in_docker :mars, 'ls /var/code'
|
89
|
+
folders = results.split("\n")
|
90
|
+
expect(folders).to include 'app'
|
91
|
+
expect(folders).to include 'db'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "installs the scripts in the /var/docker folder in the app image" do
|
95
|
+
results = run_command_in_docker :mars, 'ls /var/docker'
|
96
|
+
files = results.split("\n")
|
97
|
+
expect(files).to include 'checkout.bash'
|
98
|
+
expect(files).to include 'before_startup.bash'
|
99
|
+
expect(files).to include 'startup.bash'
|
100
|
+
expect(files).to include 'update_rails_config.rb'
|
101
|
+
expect(files).to include 'prepare_rails_for_launch.rb'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'leaves the RAILS_ENV empty' do
|
105
|
+
results = run_command_in_docker :mars, 'env'
|
106
|
+
expect(results).not_to include 'RAILS_ENV'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'running containers' do
|
111
|
+
before :all do
|
112
|
+
run_command 'run_containers'
|
113
|
+
|
114
|
+
wait_on_command_success 'curl localhost'
|
115
|
+
wait_on_command_result 'curl -I -H Host:mars.apollo.johnbrownlee.com localhost', contains: '200 OK'
|
116
|
+
wait_on_command_result 'curl -I -H Host:saturn.apollo.johnbrownlee.com localhost', contains: '200 OK'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "starts all the containers" do
|
120
|
+
expect(containers).to eq %w(apollo-database apollo-mars apollo-saturn apollo-web)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "makes the app servers accessible from the web server" do
|
124
|
+
results = run_command_in_docker :web, 'bash -c "apt-get install -y curl 2>&1; curl apollo-mars:8080/users 2>&1"'
|
125
|
+
expect(results).to include 'test_user@mars.apollo.johnbrownlee.com'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "makes the web server accessible from the host machine" do
|
129
|
+
results = `curl -H Host:apollo.johnbrownlee.com localhost 2>&1`
|
130
|
+
expect(results).to include '<a href="http://mars.apollo.johnbrownlee.com/">'
|
131
|
+
end
|
132
|
+
|
133
|
+
it "makes the app servers accessible from the host machine through the web server" do
|
134
|
+
results = `curl -H Host:mars.apollo.johnbrownlee.com localhost/users 2>&1`
|
135
|
+
expect(results).to include 'test_user@mars.apollo.johnbrownlee.com'
|
136
|
+
|
137
|
+
results = `curl -H Host:saturn.apollo.johnbrownlee.com localhost 2>&1`
|
138
|
+
expect(results).to include 'Welcome to Saturn'
|
139
|
+
end
|
140
|
+
|
141
|
+
it "does not generate static assets" do
|
142
|
+
results = `docker exec -it apollo-mars ls /var/code/public`
|
143
|
+
expect(results).not_to include 'assets'
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'starts the server in development mode' do
|
147
|
+
results = `curl -H Host:mars.apollo.johnbrownlee.com localhost/bad/path 2>&1`
|
148
|
+
expect(results).to include '<title>Action Controller: Exception caught</title>'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'build command' do
|
153
|
+
before :all do
|
154
|
+
run_command 'build'
|
155
|
+
wait_on_command_success 'curl apollo.johnbrownlee.com'
|
156
|
+
end
|
157
|
+
|
158
|
+
after :all do
|
159
|
+
restore_hosts_file
|
160
|
+
end
|
161
|
+
|
162
|
+
it "allows accessing the containers through their hostnames" do
|
163
|
+
results = `curl apollo.johnbrownlee.com 2>&1`
|
164
|
+
expect(results).to include '<a href="http://mars.apollo.johnbrownlee.com/">'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'checking out new branches' do
|
169
|
+
before :all do
|
170
|
+
run_command 'run_containers'
|
171
|
+
wait_on_command_result 'curl -I -H Host:mars.apollo.johnbrownlee.com localhost', contains: '200 OK'
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'with a valid command' do
|
175
|
+
before :all do
|
176
|
+
@result = run_command 'checkout mars checkout-test-branch'
|
177
|
+
wait_on_command_result 'curl -H Host:mars.apollo.johnbrownlee.com localhost/posts -d ""', contains: '"tag":null'
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'returns true' do
|
181
|
+
expect(@result).to be_truthy
|
182
|
+
end
|
183
|
+
|
184
|
+
it "updates the code from the server" do
|
185
|
+
results = `docker exec apollo-mars ls app/controllers`.split("\n")
|
186
|
+
expect(results).to include 'users_controller.rb'
|
187
|
+
expect(results).to include 'posts_controller.rb'
|
188
|
+
end
|
189
|
+
|
190
|
+
it "runs new database migrations" do
|
191
|
+
results = run_command_in_docker(:mars, 'mysql -uapollo -ptestpass -hapollo-database -e "show fields from apollo.posts"').split("\n")
|
192
|
+
expect(results).to include "tag\tvarchar(255)\tYES\t\tNULL\t"
|
193
|
+
end
|
194
|
+
|
195
|
+
it "starts the server with the new code base" do
|
196
|
+
results = `docker exec apollo-mars curl localhost:8080/posts -d "user_id=1&title=First%20Post&contents=Hello,%20World&tag=party" 2>&1`
|
197
|
+
expect(results).to include '"tag":"party"'
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context 'with no branch' do
|
202
|
+
it 'returns false' do
|
203
|
+
result = run_command 'checkout mars'
|
204
|
+
expect(result).to be_falsey
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'with no app name' do
|
209
|
+
it 'returns false' do
|
210
|
+
result = run_command 'checkout'
|
211
|
+
expect(result).to be_falsey
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe 'starting and stopping services' do
|
217
|
+
before :all do
|
218
|
+
run_command 'run_containers'
|
219
|
+
end
|
220
|
+
|
221
|
+
context "with the start command" do
|
222
|
+
before :all do
|
223
|
+
IntegrationHelpers.image_names.each do |image|
|
224
|
+
system "docker stop #{image} 1> /dev/null 2> /dev/null"
|
225
|
+
end
|
226
|
+
|
227
|
+
@result = run_command 'services start'
|
228
|
+
end
|
229
|
+
|
230
|
+
it "returns a success" do
|
231
|
+
expect(@result).to be_truthy
|
232
|
+
end
|
233
|
+
|
234
|
+
it "starts the containers" do
|
235
|
+
results = `docker ps | grep apollo`.split("\n")
|
236
|
+
results = results.collect { |line| line.split(/\s+/).last }
|
237
|
+
results.sort!
|
238
|
+
|
239
|
+
expect(results).to eq %w(apollo-database apollo-mars apollo-saturn apollo-web)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "with the stop command" do
|
244
|
+
before :all do
|
245
|
+
IntegrationHelpers.image_names.each do |image|
|
246
|
+
system "docker start #{image} 1> /dev/null 2> /dev/null"
|
247
|
+
end
|
248
|
+
|
249
|
+
@result = run_command 'services stop'
|
250
|
+
end
|
251
|
+
|
252
|
+
it "returns a success" do
|
253
|
+
expect(@result).to be_truthy
|
254
|
+
end
|
255
|
+
|
256
|
+
it "stops the containers" do
|
257
|
+
results = `docker ps | grep apollo`
|
258
|
+
expect(results).to eq ''
|
259
|
+
|
260
|
+
results = `docker ps -a | grep apollo`.split("\n")
|
261
|
+
results = results.collect { |line| line.split(/\s+/).last }
|
262
|
+
results.sort!
|
263
|
+
|
264
|
+
expect(results).to eq %w(apollo-database apollo-mars apollo-saturn apollo-web)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context "with an invalid command" do
|
269
|
+
before :all do
|
270
|
+
@result = run_command 'services crash'
|
271
|
+
end
|
272
|
+
|
273
|
+
it "returns a failure" do
|
274
|
+
expect(@result).to be_falsey
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context "with no command" do
|
279
|
+
before :all do
|
280
|
+
@result = run_command 'services'
|
281
|
+
end
|
282
|
+
|
283
|
+
it "returns a failure" do
|
284
|
+
expect(@result).to be_falsey
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe 'shell' do
|
290
|
+
before :all do
|
291
|
+
run_command 'run_containers'
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'with a normal command' do
|
295
|
+
it "returns the results of running that command" do
|
296
|
+
results = run_command 'shell mars ls', capture_output: true
|
297
|
+
results = results.split(/\s+/)
|
298
|
+
expect(results).to include "app"
|
299
|
+
expect(results).to include "db"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context 'with no app name' do
|
304
|
+
it 'returns a failure' do
|
305
|
+
results = run_command 'shell'
|
306
|
+
expect(results).to be_falsey
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe 'update_hosts' do
|
312
|
+
before :all do
|
313
|
+
run_command 'update_hosts'
|
314
|
+
end
|
315
|
+
|
316
|
+
after :all do
|
317
|
+
restore_hosts_file
|
318
|
+
end
|
319
|
+
|
320
|
+
it "puts the domains for the apps in the hosts file" do
|
321
|
+
results = File.read('/etc/hosts').split("\n")
|
322
|
+
expect(results).to include '127.0.0.1 apollo.johnbrownlee.com'
|
323
|
+
expect(results).to include '127.0.0.1 mars.apollo.johnbrownlee.com'
|
324
|
+
expect(results).to include '127.0.0.1 saturn.apollo.johnbrownlee.com'
|
325
|
+
end
|
326
|
+
|
327
|
+
it "puts an old copy in the backup" do
|
328
|
+
file = Dir["/etc/hosts.*.backup"].last
|
329
|
+
expect(file).not_to be_nil
|
330
|
+
results = File.read(file).split("\n")
|
331
|
+
expect(results.count).to be > 0
|
332
|
+
expect(results).not_to include 'apollo.johnbrownlee.com'
|
333
|
+
expect(results).not_to include 'mars.apollo.johnbrownlee.com'
|
334
|
+
expect(results).not_to include 'saturn.apollo.johnbrownlee.com'
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
describe 'imploding' do
|
339
|
+
before :all do
|
340
|
+
run_command 'run_containers'
|
341
|
+
run_command 'implode'
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'removes all the images and containers' do
|
345
|
+
containers = `docker ps -a | grep apollo`
|
346
|
+
expect(containers).to eq ''
|
347
|
+
|
348
|
+
images = `docker images -a | grep apollo`
|
349
|
+
expect(images).to eq ''
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|