docker-rails 0.5.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ffcac9672d5ba6fa9dbc6dfe46fcd5bc1c59e12
4
- data.tar.gz: 6b99bcd91aeb6f31749204808501ba4c8904afeb
3
+ metadata.gz: 29eddb9dd688e2781429ec0fa43faa2eb5797a60
4
+ data.tar.gz: fbcb78c9a799b9a7bae895a5727904d344f7a9a1
5
5
  SHA512:
6
- metadata.gz: 1d9b1f9dc1f4f504581cdcd176562e8d636ce3c8ac85001e2ab3d3a83dd7973a7cce9f201a6a9fd4b21dd321c586c4f73c92372149ed6edc30497f0eae7b3c75
7
- data.tar.gz: f3a0e5b27b2d01ee13677c14d1a80dd88fabeb4e4c81471bd3617c87a0e34a738e297835d6409a7129876ce3e8f31c631f7c3f6a439f991b1da8f24cf3393a0b
6
+ metadata.gz: ee49cf865269e985ba43848ec8cfe3ceeac29fc58802d4b44b0631ac5065e1f22d26767aff4abaf6619f5a804a0f7baeb1437711d85860c75ab31b7c54e28837
7
+ data.tar.gz: 44911f7657c234530b003e41f46435862a832ba024553cf8e19bb4869e19ddd2c33a9c159cc7c163a8937fd76b6d134c4f9c8ce3e845d9e91221274747f75bc8
data/README.md CHANGED
@@ -9,7 +9,7 @@ A simplified pattern to execute rails applications within Docker (with a CI buil
9
9
  - DRY declarative `docker-rails.yml` allowing multiple environments to be defined with an inherited docker `compose` configuration
10
10
  - Provides individual convenience functions `up | bash | stop | extract | cleanup` to easily work with target environment (even in a concurrent situation)
11
11
  - Full workflow for CI usage with automated container, volume, and image cleanup.
12
- - Automated cached global gems data volume based on ruby version
12
+ - Automated cached global gemset data volume (sets up GEM_HOME and `volumes_from` in all targeted containers)
13
13
  - Interpolates variables `docker-compose.yml` making CI builds much easier
14
14
  - DB check CLI function provided for docker-compose `command` to check if db is ready
15
15
  - Configurable exit_code for `ci` - determine which container's exit code will be the result of the process (useful for CI tests)
@@ -28,7 +28,7 @@ CI, the reason this is built. Do it all, do it consistently, do it concurrently,
28
28
 
29
29
  1. `before_command` - run anything on the host prior to building the docker image e.g. `rm -Rf target`
30
30
  2. `compose` - create the resolved `docker-compose.yml`
31
- 3. `gems_volume` - find or create the shared global gems volume for this ruby version
31
+ 3. `gemset_volume` - find or create the shared global gems volume for this ruby version
32
32
  4. `build` - `docker-compose build` the configuration
33
33
  5. `up` - `docker-compose up` the configuration
34
34
  6. `cleanup`
@@ -79,7 +79,7 @@ Commands:
79
79
  docker-rails compose <target> # Writes a resolved docker-compose.yml file e.g. bundle exec docker-rails compose --build=222 test
80
80
  docker-rails db_check <db> # Runs db_check e.g. bundle exec docker-rails db_check mysql
81
81
  docker-rails exec <target> <service_name> <command> # Run an arbitrary command on a given service container e.g. bundle exec docker-rails exec --build=222 development db bash
82
- docker-rails gems_volume <command> # Gems volume management e.g. bundle exec docker-rails gems_volume create
82
+ docker-rails gemset_volume <command> # Gems volume management e.g. bundle exec docker-rails gemset_volume create
83
83
  docker-rails help [COMMAND] # Describe available commands or one specific command
84
84
  docker-rails ps <target> # List containers for the target compose configuration e.g. bundle exec docker-rails ps --build=222 development
85
85
  docker-rails ps_all # List all remaining containers regardless of state e.g. bundle exec docker-rails ps_all
@@ -148,6 +148,13 @@ verbose: true
148
148
  exit_code: web
149
149
  before_command: bash -c "rm -Rf target && rm -Rf spec/dummy/log"
150
150
 
151
+ # create a global gemset to be shared amongst all ruby 2.2.2 containers.
152
+ gemset:
153
+ name: 2.2.2
154
+ # setup GEM_HOME environment variable and `volumes_from` to mount the global gemset container
155
+ containers:
156
+ - web
157
+
151
158
  extractions: &extractions
152
159
  web:
153
160
  extract:
@@ -295,15 +302,6 @@ compose:
295
302
  links:
296
303
  - db
297
304
 
298
- volumes_from:
299
- # Mount the gems data volume container for cached bundler gem files
300
- - #{DOCKER_RAILS_GEMS_VOLUME_NAME}
301
-
302
- # https://docs.docker.com/v1.6/docker-compose/cli/#environment-variables
303
- environment:
304
- # Tell bundler where to get the files
305
- - GEM_HOME=#{DOCKER_RAILS_GEMS_VOLUME_PATH}
306
-
307
305
  db:
308
306
  # https://github.com/docker-library/docs/tree/master/mysql
309
307
  image: library/mysql:5.7.6
@@ -17,6 +17,6 @@ require 'docker/rails/compose_config'
17
17
  require 'docker/rails/app'
18
18
 
19
19
  require 'docker/rails/cli/db_check'
20
- require 'docker/rails/cli/gems_volume'
20
+ require 'docker/rails/cli/gemset_volume'
21
21
 
22
22
  require 'docker/rails/cli/main'
@@ -9,8 +9,8 @@ module Docker
9
9
  :build, # given build, usually a number
10
10
  :project_name, # resolved compose project name
11
11
  :target,
12
- :gems_volume_path,
13
- :gems_volume_name,
12
+ :gemset_volume_path,
13
+ :gemset_volume_name,
14
14
  :compose_filename,
15
15
  :exit_code
16
16
 
@@ -27,8 +27,6 @@ module Docker
27
27
  end
28
28
 
29
29
  def initialize
30
- discover_ruby_version
31
- set_gems_volume_vars
32
30
  end
33
31
 
34
32
  def configure(options)
@@ -51,9 +49,32 @@ module Docker
51
49
  @config = Docker::Rails::Config.new
52
50
  @config.load!(@target)
53
51
 
52
+ # these are generated/resolved in the config#load, grab them for convenience
53
+ @gemset_volume_path = ENV['DOCKER_RAILS_GEMSET_VOLUME_PATH']
54
+ @gemset_volume_name = ENV['DOCKER_RAILS_GEMSET_VOLUME_NAME']
55
+
54
56
  @is_configured = true
55
57
  end
56
58
 
59
+ def compose
60
+ # Write a docker-compose.yml with interpolated variables
61
+ @compose_filename = compose_filename_from @project_name
62
+
63
+ rm_compose
64
+
65
+ @config.write_docker_compose_file(@compose_filename)
66
+
67
+ @compose_config = Docker::Rails::ComposeConfig.new
68
+ @compose_config.load!(nil, @compose_filename)
69
+
70
+ # check the exit_code
71
+ if @config['exit_code'].nil?
72
+ first_defined_service = @compose_config.keys[0]
73
+ puts "exit_code not set in configuration, using exit code from first defined service: #{first_defined_service}"
74
+ @config['exit_code'] = first_defined_service
75
+ end
76
+ end
77
+
57
78
  def is_configured?
58
79
  @is_configured || false
59
80
  end
@@ -105,25 +126,6 @@ module Docker
105
126
  end
106
127
  end
107
128
 
108
- def compose
109
- # Write a docker-compose.yml with interpolated variables
110
- @compose_filename = compose_filename_from @project_name
111
-
112
- rm_compose
113
-
114
- @config.write_docker_compose_file(@compose_filename)
115
-
116
- @compose_config = Docker::Rails::ComposeConfig.new
117
- @compose_config.load!(nil, @compose_filename)
118
-
119
- # check the exit_code
120
- if @config['exit_code'].nil?
121
- first_defined_service = @compose_config.keys[0]
122
- puts "exit_code not set in configuration, using exit code from first defined service: #{first_defined_service}"
123
- @config['exit_code'] = first_defined_service
124
- end
125
- end
126
-
127
129
  def rm_compose
128
130
  # Delete old docker compose files
129
131
  exec "rm #{compose_filename_from '*'}" rescue ''
@@ -250,7 +252,7 @@ module Docker
250
252
  puts '-----------------------------'
251
253
 
252
254
  list_images_cmd = 'docker images --filter dangling=true -q'
253
- output = exec( list_images_cmd, true)
255
+ output = exec(list_images_cmd, true)
254
256
 
255
257
  # if there are any dangling, let's clean them up.
256
258
  exec("#{list_images_cmd} | xargs docker rmi", false, true) if !output.nil? && output.length > 0
@@ -259,7 +261,7 @@ module Docker
259
261
 
260
262
  def run_service_command(service_name, command)
261
263
  # Run the compose configuration
262
- exec_compose "run #{service_name} #{command}"
264
+ exec_compose("run #{service_name} #{command}", false, '', true)
263
265
  end
264
266
 
265
267
  def bash_connect(service_name)
@@ -278,12 +280,12 @@ module Docker
278
280
  # https://docs.docker.com/userguide/dockervolumes/
279
281
  def create_gems_volume
280
282
  begin
281
- Docker::Container.get(@gems_volume_name)
282
- puts "Gem data volume container #{@gems_volume_name} already exists."
283
+ Docker::Container.get(@gemset_volume_name)
284
+ puts "Gem data volume container #{@gemset_volume_name} already exists."
283
285
  rescue Docker::Error::NotFoundError => e
284
286
 
285
- exec "docker create -v #{@gems_volume_path} --name #{@gems_volume_name} busybox"
286
- puts "Gem data volume container #{@gems_volume_name} created."
287
+ exec "docker create -v #{@gemset_volume_path} --name #{@gemset_volume_name} busybox"
288
+ puts "Gem data volume container #{@gemset_volume_name} created."
287
289
  end
288
290
  end
289
291
 
@@ -302,8 +304,11 @@ module Docker
302
304
  end
303
305
 
304
306
  # convenience to execute docker-compose with file and project params
305
- def exec_compose(cmd, capture = false, options = '')
306
- exec("docker-compose -f #{@compose_filename} -p #{@project_name} #{cmd} #{options}", capture)
307
+ def exec_compose(cmd, capture = false, options = '', ignore_errors = false)
308
+ # in the case of running a bash session, this file may dissappear, just make sure it is there.
309
+ compose unless File.exists?(@compose_filename)
310
+
311
+ exec("docker-compose -f #{@compose_filename} -p #{@project_name} #{cmd} #{options}", capture, ignore_errors)
307
312
  end
308
313
 
309
314
  def get_container(service_name)
@@ -330,18 +335,6 @@ module Docker
330
335
  @verbose ||= (@config['verbose'] unless @config.nil?) || false
331
336
  end
332
337
 
333
- def set_gems_volume_vars
334
- # Set as variable for interpolation
335
- ENV['DOCKER_RAILS_GEMS_VOLUME_PATH'] = @gems_volume_path = "/gems/#{@ruby_version}"
336
- ENV['DOCKER_RAILS_GEMS_VOLUME_NAME'] = @gems_volume_name = "gems-#{@ruby_version}"
337
- end
338
-
339
- def discover_ruby_version
340
- # Discover ruby version from the Dockerfile image
341
- IO.read('Dockerfile') =~ /^FROM \w+\/ruby:(\d+.\d+(?:.\d+))/
342
- @ruby_version = $1
343
- end
344
-
345
338
  # accessible so that we can delete patterns
346
339
  def compose_filename_from(project_name)
347
340
  "docker-compose-#{project_name}.yml"
@@ -1,7 +1,7 @@
1
1
  module Docker
2
2
  module Rails
3
3
  module CLI
4
- class GemsVolume < Thor
4
+ class GemsetVolume < Thor
5
5
 
6
6
  default_task :help
7
7
 
@@ -9,10 +9,10 @@ module Docker
9
9
  desc 'db_check <db>', 'Runs db_check e.g. bundle exec docker-rails db_check mysql'
10
10
  subcommand 'db_check', Docker::Rails::CLI::DbCheck
11
11
 
12
- desc 'gems_volume <command>', 'Gems volume management e.g. bundle exec docker-rails gems_volume create'
13
- subcommand 'gems_volume', Docker::Rails::CLI::GemsVolume
12
+ desc 'gemset_volume <command>', 'Gemset volume management e.g. docker-rails gemset_volume create'
13
+ subcommand 'gemset_volume', Docker::Rails::CLI::GemsetVolume
14
14
 
15
- desc 'ci <target>', 'Execute the works, everything with cleanup included e.g. bundle exec docker-rails ci --build=222 test'
15
+ desc 'ci <target>', 'Execute the works, everything with cleanup included e.g. docker-rails ci --build=222 test'
16
16
  long_desc <<-D
17
17
 
18
18
  `ci` will run the target with the given build (-b) number then cleanup everything upon completion.
@@ -26,7 +26,7 @@ module Docker
26
26
 
27
27
  invoke :before, [target], []
28
28
  invoke :compose, [target], []
29
- invoke CLI::GemsVolume, :create, [target], options
29
+ invoke CLI::GemsetVolume, :create, [target], options
30
30
  begin
31
31
  invoke :build # on CI - always build to ensure dockerfile hasn't been altered - small price to pay for consistent CI.
32
32
  invoke :up
@@ -45,7 +45,7 @@ module Docker
45
45
  app.extract
46
46
  end
47
47
 
48
- desc 'cleanup <target>', 'Runs container cleanup functions stop, rm_volumes, rm_compose, rm_dangling, ps_all e.g. bundle exec docker-rails cleanup --build=222 development'
48
+ desc 'cleanup <target>', 'Runs container cleanup functions stop, rm_volumes, rm_compose, rm_dangling, ps_all e.g. docker-rails cleanup --build=222 development'
49
49
  option :extract, aliases: ['-e'], type: :boolean, default: true, desc: 'Extract any directories defined in configuration.'
50
50
 
51
51
  def cleanup(target)
@@ -57,7 +57,7 @@ module Docker
57
57
  invoke :ps_all
58
58
  end
59
59
 
60
- desc 'up <target>', 'Up the docker-compose configuration for the given build/target. Use -d for detached mode. e.g. bundle exec docker-rails up -d --build=222 test'
60
+ desc 'up <target>', 'Up the docker-compose configuration for the given build/target. Use -d for detached mode. e.g. docker-rails up -d --build=222 test'
61
61
  option :detached, aliases: ['-d'], type: :boolean, desc: 'Detached mode: Run containers in the background'
62
62
 
63
63
  def up(target)
@@ -66,7 +66,7 @@ module Docker
66
66
  base_options = options.except(:detached)
67
67
 
68
68
  invoke :before, [target], base_options
69
- invoke CLI::GemsVolume, :create, [target], base_options
69
+ invoke CLI::GemsetVolume, :create, [target], base_options
70
70
 
71
71
  compose_options = ''
72
72
  compose_options = '-d' if options[:detached]
@@ -74,14 +74,14 @@ module Docker
74
74
  app.up(compose_options)
75
75
  end
76
76
 
77
- desc 'build <target>', 'Build for the given build/target e.g. bundle exec docker-rails build --build=222 development'
77
+ desc 'build <target>', 'Build for the given build/target e.g. docker-rails build --build=222 development'
78
78
 
79
79
  def build(target)
80
80
  invoke :compose
81
81
  App.configured(target, options).compose_build
82
82
  end
83
83
 
84
- desc 'compose <target>', 'Writes a resolved docker-compose.yml file e.g. bundle exec docker-rails compose --build=222 test'
84
+ desc 'compose <target>', 'Writes a resolved docker-compose.yml file e.g. docker-rails compose --build=222 test'
85
85
 
86
86
  def compose(target)
87
87
  App.configured(target, options).compose
@@ -95,46 +95,46 @@ module Docker
95
95
  app.before_command
96
96
  end
97
97
 
98
- desc 'stop <target>', 'Stop all running containers for the given build/target e.g. bundle exec docker-rails stop --build=222 development'
98
+ desc 'stop <target>', 'Stop all running containers for the given build/target e.g. docker-rails stop --build=222 development'
99
99
 
100
100
  def stop(target)
101
101
  invoke :compose
102
102
  App.configured(target, options).stop
103
103
  end
104
104
 
105
- desc 'rm_volumes <target>', 'Stop all running containers and remove corresponding volumes for the given build/target e.g. bundle exec docker-rails rm_volumes --build=222 development'
105
+ desc 'rm_volumes <target>', 'Stop all running containers and remove corresponding volumes for the given build/target e.g. docker-rails rm_volumes --build=222 development'
106
106
 
107
107
  def rm_volumes(target)
108
108
  invoke :stop
109
109
  App.configured(target, options).rm_volumes
110
110
  end
111
111
 
112
- desc 'rm_compose', 'Remove generated docker_compose file e.g. bundle exec docker-rails rm_compose --build=222 development', hide: true
112
+ desc 'rm_compose', 'Remove generated docker_compose file e.g. docker-rails rm_compose --build=222 development', hide: true
113
113
 
114
114
  def rm_compose(build = nil, target = nil)
115
115
  App.instance.rm_compose
116
116
  end
117
117
 
118
- desc 'rm_dangling', 'Remove danging images e.g. bundle exec docker-rails rm_dangling'
118
+ desc 'rm_dangling', 'Remove danging images e.g. docker-rails rm_dangling'
119
119
 
120
120
  def rm_dangling(build = nil, target = nil)
121
121
  App.instance.rm_dangling
122
122
  end
123
123
 
124
- desc 'ps <target>', 'List containers for the target compose configuration e.g. bundle exec docker-rails ps --build=222 development'
124
+ desc 'ps <target>', 'List containers for the target compose configuration e.g. docker-rails ps --build=222 development'
125
125
 
126
126
  def ps(target)
127
127
  invoke :compose
128
128
  App.configured(target, options).ps
129
129
  end
130
130
 
131
- desc 'ps_all', 'List all remaining containers regardless of state e.g. bundle exec docker-rails ps_all'
131
+ desc 'ps_all', 'List all remaining containers regardless of state e.g. docker-rails ps_all'
132
132
 
133
133
  def ps_all(build = nil, target = nil)
134
134
  App.instance.ps_all
135
135
  end
136
136
 
137
- desc 'bash_connect <target> <service_name>', 'Open a bash shell to a running container (with automatic cleanup) e.g. bundle exec docker-rails bash --build=222 development db'
137
+ desc 'bash_connect <target> <service_name>', 'Open a bash shell to a running container (with automatic cleanup) e.g. docker-rails bash --build=222 development db'
138
138
 
139
139
  def bash_connect(target, service_name)
140
140
  # init singleton with full options
@@ -150,7 +150,7 @@ module Docker
150
150
  container.remove(v: true, force: true)
151
151
  end
152
152
 
153
- desc 'exec <target> <service_name> <command>', 'Run an arbitrary command on a given service container e.g. bundle exec docker-rails exec --build=222 development db bash'
153
+ desc 'exec <target> <service_name> <command>', 'Run an arbitrary command on a given service container e.g. docker-rails exec --build=222 development db bash'
154
154
 
155
155
  def exec(target, service_name, command)
156
156
  # init singleton with full options
@@ -2,6 +2,20 @@ module Docker
2
2
  module Rails
3
3
  require 'dry/config'
4
4
  class Config < Dry::Config::Base
5
+
6
+ # environment:
7
+ # # make ssh keys available via ssh forwarding (see volume entry)
8
+ # - SSH_AUTH_SOCK=/ssh-agent/socket
9
+ #
10
+ # volumes_from:
11
+ # # Use configured whilp/ssh-agent long running container for keys
12
+ # - ssh-agent
13
+ SSH_AGENT_DEFAULT_CONFIG = {
14
+ environment: ['SSH_AUTH_SOCK=/ssh-agent/socket'],
15
+ volumes_from: ['ssh-agent']
16
+ }
17
+
18
+
5
19
  def initialize(options = {})
6
20
  super({
7
21
  default_configuration: {
@@ -27,6 +41,50 @@ module Docker
27
41
  config = load_unpruned(environment, *filenames)
28
42
  raise "Unknown target environment '#{environment.to_sym}'" if config[environment.to_sym].nil?
29
43
 
44
+
45
+ # -----------------------------------------------------
46
+ # Generate defaults for GEMSET_VOLUME and SSH_AGENT
47
+ generated_defaults = {compose: {}}
48
+ compose = generated_defaults[:compose]
49
+
50
+ # ----
51
+ # ssh-agent
52
+ ssh_agent = config[:'ssh-agent']
53
+ if !ssh_agent.nil?
54
+ ssh_agent[:containers].each do |container|
55
+ raise "Unknown container #{container}" if config[:compose][container.to_sym].nil?
56
+ compose[container.to_sym] ||= {}
57
+ compose[container.to_sym].deeper_merge! ({}.merge SSH_AGENT_DEFAULT_CONFIG)
58
+ end
59
+ end
60
+
61
+ # ----
62
+ # gemset volume
63
+ gemset = config[:gemset]
64
+ raise "Expected to find 'gemset:' in #{filenames}" if gemset.nil?
65
+
66
+ gemset_name = gemset[:name]
67
+ raise "Expected to find 'gemset: name' in #{filenames}" if gemset_name.nil?
68
+
69
+ ENV['DOCKER_RAILS_GEMSET_VOLUME_PATH'] = gemset_volume_path = "/gemset/#{gemset_name}"
70
+ ENV['DOCKER_RAILS_GEMSET_VOLUME_NAME'] = gemset_volume_name = "gemset-#{gemset_name}"
71
+
72
+ raise "Expected to find 'gemset: containers' with at least one entry" if gemset[:containers].nil? || gemset[:containers].length < 1
73
+ gemset[:containers].each do |container|
74
+ raise "Unknown container #{container}" if config[:compose][container.to_sym].nil?
75
+ compose[container.to_sym] ||= {}
76
+ compose[container.to_sym].deeper_merge! ({
77
+ environment: ["GEM_HOME=#{gemset_volume_path}"],
78
+ volumes_from: [gemset_volume_name]
79
+ })
80
+ end
81
+
82
+ # now add the generated to the seeded default configuration
83
+ @default_configuration.merge!(generated_defaults)
84
+
85
+ # reset the base @configuration by loading the new default configuration
86
+ clear
87
+
30
88
  # finally, load the config as internal state
31
89
  super(environment, *filenames)
32
90
  end
@@ -1,5 +1,5 @@
1
1
  module Docker
2
2
  module Rails
3
- VERSION = '0.5.6'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -23,7 +23,7 @@ describe Docker::Rails::Config do
23
23
  expect {
24
24
  Dir.chdir(File.dirname(__FILE__)) do
25
25
  config.clear
26
- config.load!(:foo)
26
+ config.load!(:foobar)
27
27
  end
28
28
  }.to raise_error /Unknown target environment/
29
29
  end
@@ -39,11 +39,11 @@ describe Docker::Rails::Config do
39
39
 
40
40
 
41
41
  context ':development' do
42
-
42
+ let(:target_env){ :development}
43
43
  before(:each) {
44
44
  Dir.chdir(File.dirname(__FILE__)) do
45
45
  config.clear
46
- config.load!(:development)
46
+ config.load!(target_env)
47
47
  end
48
48
  }
49
49
 
@@ -62,16 +62,30 @@ describe Docker::Rails::Config do
62
62
  expect(config.production).to be_nil
63
63
  end
64
64
 
65
- it 'should write a docker-compose file' do
66
- file = tmp_file
67
- config.write_docker_compose_file(file)
68
- end
69
-
70
65
  it 'should manipulate command to yaml single line' do
71
66
  yaml = config.to_yaml
72
67
  expect(yaml).to include 'command: >'
73
68
  expect(yaml).not_to include 'command: |'
74
69
  end
70
+
71
+ context 'compose' do
72
+ let(:compose_config) {
73
+ file = tmp_file('compose')
74
+ config.write_docker_compose_file(file)
75
+ compose_config =Docker::Rails::ComposeConfig.new
76
+ compose_config.load!(nil, file)
77
+ compose_config
78
+ }
79
+
80
+ it 'web should have ssh-agent' do
81
+ expect(compose_config[:web][:environment]).to include('SSH_AUTH_SOCK=/ssh-agent/socket')
82
+ expect(compose_config[:web][:volumes_from]).to include('ssh-agent')
83
+ end
84
+ it 'web should have gemset' do
85
+ expect(compose_config[:web][:environment]).to include('GEM_HOME=/gemset/2.2.2')
86
+ expect(compose_config[:web][:volumes_from]).to include('gemset-2.2.2')
87
+ end
88
+ end
75
89
  end
76
90
 
77
91
  # it 'should read specific file' do
@@ -90,7 +104,7 @@ describe Docker::Rails::Config do
90
104
  end
91
105
 
92
106
  def tmp_file(name = 'foo')
93
- file = File.expand_path("../../../../tmp/#{name}-docker-rails.yml", __FILE__)
107
+ file = File.expand_path("../../../../tmp/#{name}-docker-rails-config_spec.yml", __FILE__)
94
108
  FileUtils.mkdir_p File.dirname file
95
109
  file
96
110
  end
@@ -1,4 +1,53 @@
1
1
  verbose: true
2
+ before_command: bash -c "rm -Rf target && rm -Rf log"
3
+ exit_code: web
4
+
5
+ # create a global gemset to be shared amongst all ruby 2.2.2 containers.
6
+ gemset:
7
+ name: 2.2.2
8
+ # setup GEM_HOME environment variable and `volumes_from` to mount the global gemset container
9
+ containers:
10
+ - web
11
+
12
+ # Generated:
13
+ #compose:
14
+ # web:
15
+ # environment:
16
+ # # Tell bundler where to get the files
17
+ # - GEM_HOME=/gemset/2.2.2
18
+ #
19
+ # volumes_from:
20
+ # # Mount the gems data volume container for cached bundler gem files
21
+ # - gemset-2.2.2
22
+
23
+
24
+ # Make the host user's id_rsa key available to the web container e.g. for cloning from github
25
+ ssh-agent:
26
+ containers:
27
+ - web
28
+ keys:
29
+ - id_rsa
30
+
31
+ # Generated:
32
+ #compose:
33
+ # web:
34
+ # environment:
35
+ # # make ssh keys available via ssh forwarding (see volume entry)
36
+ # - SSH_AUTH_SOCK=/ssh-agent/socket
37
+ #
38
+ # volumes_from:
39
+ # # Use configured whilp/ssh-agent long running container for keys
40
+ # - ssh-agent
41
+
42
+
43
+ extractions: &extractions
44
+ web:
45
+ extract:
46
+ - '/project/target'
47
+ - '/project/vcr'
48
+ - '/project/tmp/parallel_runtime_cucumber.log:./tmp'
49
+ - '/project/tmp/parallel_runtime_rspec.log:./tmp'
50
+ - '/project/log'
2
51
 
3
52
  # local environments need elasticsearch, staging/production connects to existing running instance.
4
53
  elasticsearch: &elasticsearch
@@ -7,6 +56,16 @@ elasticsearch: &elasticsearch
7
56
  ports:
8
57
  - "9200"
9
58
 
59
+ foo:
60
+ compose:
61
+ web:
62
+ command: bash -c "sleep 10 && echo 'foo' && exit 187"
63
+
64
+ bundle_only:
65
+ compose:
66
+ web:
67
+ command: bash -c "bundle install --jobs 4 --retry 3"
68
+
10
69
  development:
11
70
  compose:
12
71
  <<: *elasticsearch
@@ -24,25 +83,25 @@ development:
24
83
  && echo 'Generating Spring binstubs'
25
84
  && bundle exec spring binstub --all
26
85
 
27
- && echo 'Clearing logs and tmp dirs'
28
- && bundle exec rake log:clear tmp:clear
86
+ && echo 'Clearing logs'
87
+ && bundle exec rake log:clear
29
88
 
30
89
  && echo 'Check and wait for database connection'
31
90
  && bundle exec docker-rails db_check mysql
32
91
 
33
- && echo 'Setting up new db if one doesn't exist'
34
- && bundle exec rake db:version || { bundle exec rake db:setup; }
92
+ && echo 'DB rebuild'
93
+ && bundle exec rake db:rebuild_dev
35
94
 
36
95
  && echo "Starting app server"
37
96
  && bundle exec rails s -p 3000
38
-
39
- && echo 'Setup and start foreman'
40
- && gem install foreman
41
- && foreman start
42
97
  "
43
98
 
99
+ # && echo 'Setup and start foreman'
100
+ # && gem install foreman
101
+ # && foreman start
102
+
44
103
  test:
45
- before_command: rm -Rf target
104
+ <<: *extractions
46
105
  compose:
47
106
  <<: *elasticsearch
48
107
  web:
@@ -55,22 +114,28 @@ test:
55
114
  echo 'Bundling gems'
56
115
  && bundle install --jobs 4 --retry 3
57
116
 
58
- && echo 'Clearing logs and tmp dirs'
59
- && bundle exec rake log:clear tmp:clear
60
-
61
117
  && echo 'Check and wait for database connection'
62
118
  && bundle exec docker-rails db_check mysql
63
119
 
64
- && echo 'Setting up new db if one doesn't exist'
65
- && bundle exec rake db:version || { bundle exec rake db:setup; }
120
+ && echo 'DB rebuild'
121
+ && bundle exec rake db:rebuild_test
66
122
 
67
123
  && echo 'Tests'
68
124
  && cd ../..
69
- && xvfb-run -a bundle exec rake spec cucumber
125
+ && xvfb-run -a bundle exec rake \
126
+ spec SPEC=spec/app/models/batch/csv_spec.rb \
127
+ cucumber FEATURE=features/activation/4_admin_import_members.feature
70
128
  "
71
129
 
130
+ # && xvfb-run -a bundle exec rake spec
131
+ # && xvfb-run -a bundle exec rake spec SPEC=spec/app/models/plan_spec.rb
132
+ # && xvfb-run -a bundle exec rake spec SPEC=spec/app/models/plan_spec.rb cucumber FEATURE=features/public_pages.feature
133
+
134
+ # cucumber
135
+ # rake FEATURE=features/adding_products.feature cucumber
136
+
72
137
  parallel_tests:
73
- before_command: rm -Rf target
138
+ <<: *extractions
74
139
  compose:
75
140
  <<: *elasticsearch
76
141
  web:
@@ -82,20 +147,17 @@ parallel_tests:
82
147
  bash -c "
83
148
 
84
149
  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
150
+ && time bundle install --jobs 4 --retry 3
89
151
 
90
152
  && echo 'Check and wait for database connection'
91
- && bundle exec docker-rails db_check mysql
153
+ && time bundle exec docker-rails db_check mysql
92
154
 
93
- && echo 'Setting up new db if one doesn't exist'
94
- && bundle exec rake parallel:drop parallel:create parallel:migrate parallel:seed
155
+ && echo 'DB rebuild'
156
+ && time bundle exec rake db:rebuild_test[true]
95
157
 
96
- && echo 'Tests'
97
158
  && cd ../..
98
- && xvfb-run -a bundle exec rake parallel:spec parallel:features
159
+ && echo 'Tests'
160
+ && time xvfb-run -a bundle exec rake parallel:spec parallel:features
99
161
  "
100
162
 
101
163
  staging:
@@ -109,13 +171,13 @@ staging:
109
171
  echo 'Bundling gems'
110
172
  && bundle install --jobs 4 --retry 3
111
173
 
112
- && echo 'Clearing logs and tmp dirs'
113
- && bundle exec rake log:clear tmp:clear
174
+ && echo 'Clearing logs'
175
+ && bundle exec rake log:clear
114
176
 
115
177
  && echo 'Check and wait for database connection'
116
178
  && bundle exec docker-rails db_check mysql
117
179
 
118
- && echo 'Setting up new db if one doesn't exist'
180
+ && echo 'DB rebuild'
119
181
  && bundle exec rake db:migrate
120
182
 
121
183
  && echo "Starting app server"
@@ -125,35 +187,27 @@ staging:
125
187
  && gem install foreman
126
188
  && foreman start
127
189
  "
128
-
129
190
  compose:
191
+
130
192
  web:
131
193
  build: .
132
- working_dir: /project/spec/dummy
194
+ working_dir: /project
133
195
  ports:
134
196
  - "3000"
135
197
 
136
198
  links:
137
199
  - db
138
200
 
139
- volumes:
140
- - .:/project
141
-
142
- volumes_from:
143
- # Mount the gems data volume container for cached bundler gem files
144
- - #{DOCKER_RAILS_GEMS_VOLUME_NAME}
145
-
146
- # https://docs.docker.com/v1.6/compose/cli/#environment-variables
147
- environment:
148
- # Tell bundler where to get the files
149
- - GEM_HOME=#{DOCKER_RAILS_GEMS_VOLUME_PATH}
150
-
151
201
  db:
152
202
  # https://github.com/docker-library/docs/tree/master/mysql
153
- image: library/mysql:5.7.6
203
+ image: library/mysql:5.7
154
204
  ports:
155
205
  - "3306"
156
206
 
207
+ volumes:
208
+ - ./db/mysql:/etc/mysql/conf.d
209
+ # - ./target/mysql/data:/var/lib/mysql
210
+
157
211
  # https://github.com/docker-library/docs/tree/master/mysql#environment-variables
158
212
  environment:
159
213
  - MYSQL_ALLOW_EMPTY_PASSWORD=true
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.5.6
4
+ version: 0.6.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-10-01 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,7 +158,7 @@ files:
158
158
  - lib/docker/rails.rb
159
159
  - lib/docker/rails/app.rb
160
160
  - lib/docker/rails/cli/db_check.rb
161
- - lib/docker/rails/cli/gems_volume.rb
161
+ - lib/docker/rails/cli/gemset_volume.rb
162
162
  - lib/docker/rails/cli/main.rb
163
163
  - lib/docker/rails/compose_config.rb
164
164
  - lib/docker/rails/config.rb