docker-rails 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/README.md +190 -74
- data/Rakefile +7 -1
- data/bin/docker-rails +3 -133
- data/docker-rails.gemspec +5 -3
- data/lib/docker/rails.rb +11 -1
- data/lib/docker/rails/CLI/db_check.rb +67 -0
- data/lib/docker/rails/CLI/gems_volume.rb +27 -0
- data/lib/docker/rails/CLI/main.rb +117 -0
- data/lib/docker/rails/app.rb +176 -0
- data/lib/docker/rails/config.rb +40 -0
- data/lib/docker/rails/version.rb +1 -1
- data/spec/docker/rails/config_spec.rb +95 -0
- data/spec/docker/rails/docker-rails.yml +159 -0
- data/spec/spec_helper.rb +11 -0
- metadata +64 -12
- data/bin/docker-rails-db-check +0 -38
data/lib/docker/rails/version.rb
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Docker::Rails::Config do
|
4
|
+
|
5
|
+
subject(:options) { {} }
|
6
|
+
subject(:config) { Docker::Rails::Config.new }
|
7
|
+
|
8
|
+
it 'should not raise error when key is not found' do
|
9
|
+
config.clear
|
10
|
+
expect(config.foo).to be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should provide seed configuration' do
|
14
|
+
config.clear
|
15
|
+
assert_common_seed_settings
|
16
|
+
|
17
|
+
# ensure no unnecessary environments make it into the resolved configuration
|
18
|
+
expect(config.development).to be_nil
|
19
|
+
expect(config.production).to be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should read default env and file' do
|
23
|
+
Dir.chdir(File.dirname(__FILE__)) do
|
24
|
+
config.clear
|
25
|
+
config.load!(nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
assert_common_top_level_settings
|
29
|
+
|
30
|
+
# ensure no unnecessary environments make it into the resolved configuration
|
31
|
+
expect(config.development).to be_nil
|
32
|
+
expect(config.production).to be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
context ':development' do
|
36
|
+
|
37
|
+
before(:each){
|
38
|
+
Dir.chdir(File.dirname(__FILE__)) do
|
39
|
+
config.clear
|
40
|
+
config.load!(:development)
|
41
|
+
end
|
42
|
+
}
|
43
|
+
|
44
|
+
it 'should read default file' do
|
45
|
+
assert_common_top_level_settings
|
46
|
+
|
47
|
+
web = config[:'docker-compose'][:web]
|
48
|
+
expect(web[:links]).to match_array %w(elasticsearch db)
|
49
|
+
expect(web[:ports]).to match_array ['3000']
|
50
|
+
|
51
|
+
elasticsearch = config[:'docker-compose'][:elasticsearch]
|
52
|
+
expect(elasticsearch[:ports]).to match_array ['9200']
|
53
|
+
|
54
|
+
# ensure no unnecessary environments make it into the resolved configuration
|
55
|
+
expect(config.development).to be_nil
|
56
|
+
expect(config.production).to be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should write a docker-compose file' do
|
60
|
+
file = tmp_file
|
61
|
+
config.write_docker_compose_file(file)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should manipulate command to yaml single line' do
|
65
|
+
yaml = config.to_yaml
|
66
|
+
expect(yaml).to include 'command: >'
|
67
|
+
expect(yaml).not_to include 'command: |'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# it 'should read specific file' do
|
72
|
+
# config.clear
|
73
|
+
# config.load!(nil, config_file_path)
|
74
|
+
# end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def assert_common_seed_settings
|
79
|
+
expect(config[:verbose]).to eql false
|
80
|
+
end
|
81
|
+
|
82
|
+
def assert_common_top_level_settings
|
83
|
+
expect(config[:verbose]).to eql true
|
84
|
+
end
|
85
|
+
|
86
|
+
def tmp_file(name = 'foo')
|
87
|
+
file = File.expand_path("../../../../tmp/#{name}-docker-rails.yml", __FILE__)
|
88
|
+
FileUtils.mkdir_p File.dirname file
|
89
|
+
file
|
90
|
+
end
|
91
|
+
|
92
|
+
def config_file_path
|
93
|
+
File.expand_path('../sample-docker-rails.yml', __FILE__)
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
verbose: true
|
2
|
+
|
3
|
+
# local environments need elasticsearch, staging/production connects to existing running instance.
|
4
|
+
elasticsearch: &elasticsearch
|
5
|
+
elasticsearch:
|
6
|
+
image: library/elasticsearch:1.7
|
7
|
+
ports:
|
8
|
+
- "9200"
|
9
|
+
|
10
|
+
development:
|
11
|
+
docker-compose:
|
12
|
+
<<: *elasticsearch
|
13
|
+
web:
|
14
|
+
links:
|
15
|
+
- elasticsearch # standard yaml doesn't merge arrays so we have to add this explicitly
|
16
|
+
environment:
|
17
|
+
- RAILS_ENV=development
|
18
|
+
command: >
|
19
|
+
bash -c "
|
20
|
+
|
21
|
+
echo 'Bundling gems'
|
22
|
+
&& bundle install --jobs 4 --retry 3
|
23
|
+
|
24
|
+
&& echo 'Generating Spring binstubs'
|
25
|
+
&& bundle exec spring binstub --all
|
26
|
+
|
27
|
+
&& echo 'Clearing logs and tmp dirs'
|
28
|
+
&& bundle exec rake log:clear tmp:clear
|
29
|
+
|
30
|
+
&& echo 'Check and wait for database connection'
|
31
|
+
&& bundle exec docker-rails db_check mysql
|
32
|
+
|
33
|
+
&& echo 'Setting up new db if one doesn't exist'
|
34
|
+
&& bundle exec rake db:version || { bundle exec rake db:setup; }
|
35
|
+
|
36
|
+
&& echo "Starting app server"
|
37
|
+
&& bundle exec rails s -p 3000
|
38
|
+
|
39
|
+
&& echo 'Setup and start foreman'
|
40
|
+
&& gem install foreman
|
41
|
+
&& foreman start
|
42
|
+
"
|
43
|
+
|
44
|
+
test:
|
45
|
+
before_command: rm -Rf target
|
46
|
+
docker-compose:
|
47
|
+
<<: *elasticsearch
|
48
|
+
web:
|
49
|
+
links:
|
50
|
+
- elasticsearch # standard yaml doesn't merge arrays so we have to add this explicitly
|
51
|
+
environment:
|
52
|
+
- RAILS_ENV=test
|
53
|
+
command: >
|
54
|
+
bash -c "
|
55
|
+
echo 'Bundling gems'
|
56
|
+
&& bundle install --jobs 4 --retry 3
|
57
|
+
|
58
|
+
&& echo 'Clearing logs and tmp dirs'
|
59
|
+
&& bundle exec rake log:clear tmp:clear
|
60
|
+
|
61
|
+
&& echo 'Check and wait for database connection'
|
62
|
+
&& bundle exec docker-rails db_check mysql
|
63
|
+
|
64
|
+
&& echo 'Setting up new db if one doesn't exist'
|
65
|
+
&& bundle exec rake db:version || { bundle exec rake db:setup; }
|
66
|
+
|
67
|
+
&& echo 'Tests'
|
68
|
+
&& cd ../..
|
69
|
+
&& xvfb-run -a bundle exec rake spec cucumber
|
70
|
+
"
|
71
|
+
|
72
|
+
parallel_tests:
|
73
|
+
before_command: rm -Rf target
|
74
|
+
docker-compose:
|
75
|
+
<<: *elasticsearch
|
76
|
+
web:
|
77
|
+
links:
|
78
|
+
- elasticsearch # standard yaml doesn't merge arrays so we have to add this explicitly
|
79
|
+
environment:
|
80
|
+
- RAILS_ENV=test
|
81
|
+
command: >
|
82
|
+
bash -c "
|
83
|
+
|
84
|
+
echo 'Bundling gems'
|
85
|
+
&& bundle install --jobs 4 --retry 3
|
86
|
+
|
87
|
+
&& echo 'Clearing logs and tmp dirs'
|
88
|
+
&& bundle exec rake log:clear tmp:clear
|
89
|
+
|
90
|
+
&& echo 'Check and wait for database connection'
|
91
|
+
&& bundle exec docker-rails db_check mysql
|
92
|
+
|
93
|
+
&& echo 'Setting up new db if one doesn't exist'
|
94
|
+
&& bundle exec rake parallel:drop parallel:create parallel:migrate parallel:seed
|
95
|
+
|
96
|
+
&& echo 'Tests'
|
97
|
+
&& cd ../..
|
98
|
+
&& xvfb-run -a bundle exec rake parallel:spec parallel:features
|
99
|
+
"
|
100
|
+
|
101
|
+
staging:
|
102
|
+
docker-compose:
|
103
|
+
web:
|
104
|
+
environment:
|
105
|
+
- RAILS_ENV=staging
|
106
|
+
command: >
|
107
|
+
bash -c "
|
108
|
+
|
109
|
+
echo 'Bundling gems'
|
110
|
+
&& bundle install --jobs 4 --retry 3
|
111
|
+
|
112
|
+
&& echo 'Clearing logs and tmp dirs'
|
113
|
+
&& bundle exec rake log:clear tmp:clear
|
114
|
+
|
115
|
+
&& echo 'Check and wait for database connection'
|
116
|
+
&& bundle exec docker-rails db_check mysql
|
117
|
+
|
118
|
+
&& echo 'Setting up new db if one doesn't exist'
|
119
|
+
&& bundle exec rake db:migrate
|
120
|
+
|
121
|
+
&& echo "Starting app server"
|
122
|
+
&& bundle exec rails s -p 3000
|
123
|
+
|
124
|
+
&& echo 'Setup and start foreman'
|
125
|
+
&& gem install foreman
|
126
|
+
&& foreman start
|
127
|
+
"
|
128
|
+
|
129
|
+
docker-compose:
|
130
|
+
web:
|
131
|
+
build: .
|
132
|
+
working_dir: /project/spec/dummy
|
133
|
+
ports:
|
134
|
+
- "3000"
|
135
|
+
|
136
|
+
links:
|
137
|
+
- db
|
138
|
+
|
139
|
+
volumes:
|
140
|
+
- .:/project
|
141
|
+
|
142
|
+
volumes_from:
|
143
|
+
# Mount the gems data volume container for cached bundler gem files
|
144
|
+
- #{GEMS_VOLUME_NAME}
|
145
|
+
|
146
|
+
# https://docs.docker.com/v1.6/docker-compose/cli/#environment-variables
|
147
|
+
environment:
|
148
|
+
# Tell bundler where to get the files
|
149
|
+
- GEM_HOME=#{GEMS_VOLUME_PATH}
|
150
|
+
|
151
|
+
db:
|
152
|
+
# https://github.com/docker-library/docs/tree/master/mysql
|
153
|
+
image: library/mysql:5.7.6
|
154
|
+
ports:
|
155
|
+
- "3306"
|
156
|
+
|
157
|
+
# https://github.com/docker-library/docs/tree/master/mysql#environment-variables
|
158
|
+
environment:
|
159
|
+
- MYSQL_ALLOW_EMPTY_PASSWORD=true
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.3.18
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.3.18
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: docker-api
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,38 +100,38 @@ dependencies:
|
|
58
100
|
requirements:
|
59
101
|
- - ">="
|
60
102
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
103
|
+
version: 1.2.6
|
62
104
|
type: :runtime
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
108
|
- - ">="
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
110
|
+
version: 1.2.6
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
112
|
+
name: thor
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
|
-
- - "
|
115
|
+
- - ">="
|
74
116
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0
|
117
|
+
version: '0'
|
76
118
|
type: :runtime
|
77
119
|
prerelease: false
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
80
|
-
- - "
|
122
|
+
- - ">="
|
81
123
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0
|
124
|
+
version: '0'
|
83
125
|
description: ''
|
84
126
|
email:
|
85
127
|
- kevin.ross@alienfast.com
|
86
128
|
executables:
|
87
129
|
- docker-rails
|
88
|
-
- docker-rails-db-check
|
89
130
|
extensions: []
|
90
131
|
extra_rdoc_files: []
|
91
132
|
files:
|
92
133
|
- ".gitignore"
|
134
|
+
- ".rspec"
|
93
135
|
- ".ruby-gemset"
|
94
136
|
- ".ruby-version"
|
95
137
|
- Gemfile
|
@@ -97,11 +139,18 @@ files:
|
|
97
139
|
- README.md
|
98
140
|
- Rakefile
|
99
141
|
- bin/docker-rails
|
100
|
-
- bin/docker-rails-db-check
|
101
142
|
- docker-rails.gemspec
|
102
143
|
- lib/docker/rails.rb
|
144
|
+
- lib/docker/rails/CLI/db_check.rb
|
145
|
+
- lib/docker/rails/CLI/gems_volume.rb
|
146
|
+
- lib/docker/rails/CLI/main.rb
|
147
|
+
- lib/docker/rails/app.rb
|
103
148
|
- lib/docker/rails/compose_config.rb
|
149
|
+
- lib/docker/rails/config.rb
|
104
150
|
- lib/docker/rails/version.rb
|
151
|
+
- spec/docker/rails/config_spec.rb
|
152
|
+
- spec/docker/rails/docker-rails.yml
|
153
|
+
- spec/spec_helper.rb
|
105
154
|
homepage: ''
|
106
155
|
licenses:
|
107
156
|
- MIT
|
@@ -127,4 +176,7 @@ signing_key:
|
|
127
176
|
specification_version: 4
|
128
177
|
summary: A simplified pattern to execute rails applications within Docker (with a
|
129
178
|
CI build emphasis)
|
130
|
-
test_files:
|
179
|
+
test_files:
|
180
|
+
- spec/docker/rails/config_spec.rb
|
181
|
+
- spec/docker/rails/docker-rails.yml
|
182
|
+
- spec/spec_helper.rb
|
data/bin/docker-rails-db-check
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# TODO: make docker-rails CLI and put this in the lib, add optional ! method to raise if failed
|
4
|
-
|
5
|
-
# ping db to see if it is ready before continuing
|
6
|
-
require 'rubygems'
|
7
|
-
require 'active_record'
|
8
|
-
require 'mysql2'
|
9
|
-
|
10
|
-
LOOP_LIMIT=60
|
11
|
-
puts "\n"
|
12
|
-
printf 'Waiting for confirmation of db service startup...'
|
13
|
-
LOOP_LIMIT.times do |i|
|
14
|
-
if i == LOOP_LIMIT - 1
|
15
|
-
printf 'failed to connect.'
|
16
|
-
raise 'Failed to connect to db service.'
|
17
|
-
end
|
18
|
-
|
19
|
-
ActiveRecord::Base.establish_connection ({
|
20
|
-
adapter: 'mysql2',
|
21
|
-
host: 'db',
|
22
|
-
port: 3306,
|
23
|
-
username: 'root'})
|
24
|
-
connected =
|
25
|
-
begin
|
26
|
-
ActiveRecord::Base.connection_pool.with_connection { |con| con.active? }
|
27
|
-
rescue => e
|
28
|
-
# puts "#{e.class.name}: #{e.message}"
|
29
|
-
false
|
30
|
-
end
|
31
|
-
printf '.'
|
32
|
-
if connected
|
33
|
-
printf 'connected.'
|
34
|
-
break
|
35
|
-
end
|
36
|
-
sleep 1
|
37
|
-
end
|
38
|
-
puts "\n"
|