docker-rails 0.9.0 → 0.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a5253c80fa206c480db1e56b738ef2fbfe46733
4
- data.tar.gz: 0c33db371899c5ec86ef344867ec5e5316f1116c
3
+ metadata.gz: e0366030b589abebd5315e8fbf308739ed751ab0
4
+ data.tar.gz: 13156b0a24820cfe5a5be649c6ae00e64a419983
5
5
  SHA512:
6
- metadata.gz: 5fad7285f5e03e731e3fc382edc7b4ace5da6de9b65de221de1902f7969291509a85b9849fa328df43641f1a493166f9b2641e0137004ca60a09d06f0db6bfbe
7
- data.tar.gz: 461bc62fac672e235fc63a2de848b11d2f6a2010f9a4549e160338e7df175e3eec318049fc9099531dced3683da074ee3f278e9d54275790b52e812c4d186187
6
+ metadata.gz: b6a2232fc2f1574603a87dc42a635a38bd9124b0c4749ad12060210ca499c6192b0d7106949f813963b7073002a345501f392358a5e2aacdedfa0792e751c458
7
+ data.tar.gz: c97c362d3a8bd2d67157375484902fcedf03e49913bede0d45a8fe7e56c459907103e276a89763c18df14d9ef15379781e4b886fc1ad0229cb1fb6f4e796b81d
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
3
  - 2.2.2
4
+ - 2.2.3
5
5
  - ruby-head
6
6
  - jruby-head
7
7
 
data/README.md CHANGED
@@ -9,7 +9,6 @@ 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 gemset data volume (sets up GEM_HOME and `volumes_from` in all targeted containers)
13
12
  - Interpolates variables `docker-compose.yml` making CI builds much easier
14
13
  - DB check CLI function provided for docker-compose `command` to check if db is ready
15
14
  - Configurable exit_code for `ci` - determine which container's exit code will be the result of the process (useful for CI tests)
@@ -28,7 +27,6 @@ CI, the reason this is built. Do it all, do it consistently, do it concurrently,
28
27
 
29
28
  1. `before_command` - run anything on the host prior to building the docker image e.g. `rm -Rf target`
30
29
  1. `compose` - create the resolved `docker-compose.yml`
31
- 1. `gemset_volume create` - find or create the shared global gems volume for this ruby version
32
30
  1. `build` - `docker-compose build` the configuration
33
31
  1. `up` - `docker-compose up` the configuration
34
32
  1. `cleanup`
@@ -79,7 +77,6 @@ Commands:
79
77
  docker-rails compose <target> # Writes a resolved docker-compose.yml file e.g. docker-rails compose --build=222 test
80
78
  docker-rails db_check <db> # Runs db_check e.g. bundle exec docker-rails db_check mysql
81
79
  docker-rails exec <target> <service_name> <command> # Run an arbitrary command on a given service container e.g. docker-rails exec --build=222 development db bash
82
- docker-rails gemset_volume <command> # Gemset volume management e.g. docker-rails gemset_volume create
83
80
  docker-rails help [COMMAND] # Describe available commands or one specific command
84
81
  docker-rails ps <target> # List containers for the target compose configuration e.g. docker-rails ps --build=222 development
85
82
  docker-rails ps_all # List all remaining containers regardless of state e.g. docker-rails ps_all
@@ -112,30 +109,7 @@ Or install it yourself as:
112
109
  ### 1. Add a Dockerfile
113
110
 
114
111
  ```bash
115
- FROM atlashealth/ruby:2.2.2
116
-
117
- ENV DEBIAN_FRONTEND noninteractive
118
-
119
- # For building, nokogiri support, capybara-webkit, mysql client
120
- # Clean up APT when done.
121
- RUN apt-get update -qq && \
122
- apt-get install -qy build-essential libxml2-dev libxslt1-dev g++ qt5-default libqt5webkit5-dev xvfb libmysqlclient-dev && \
123
-
124
- # cleanup
125
- apt-get clean && \
126
- cd /var/lib/apt/lists && rm -fr *Release* *Sources* *Packages* && \
127
- truncate -s 0 /var/log/*log
128
-
129
- COPY . /project # figure out/automate this as a volume instead https://github.com/alienfast/docker-rails/issues/14
130
-
131
- # https://github.com/docker/docker/issues/4032
132
- ENV DEBIAN_FRONTEND newt
133
-
134
- # Bypass the union file system for better performance https://docs.docker.com/userguide/dockervolumes/
135
- VOLUME /project
136
-
137
- # Copy the project files into the container (again, better performance). Use `extract` in the docker-rails.yml to obtain files such as test results.
138
- COPY . /project
112
+ FIXME
139
113
  ```
140
114
 
141
115
  ### 2. Add a docker-rails.yml
@@ -148,24 +122,16 @@ verbose: true
148
122
  exit_code: web
149
123
  before_command: bash -c "rm -Rf target && rm -Rf spec/dummy/log"
150
124
 
151
- # ---
152
- # create a global gemset to be shared amongst all ruby 2.2.2 containers.
153
- gemset:
154
- name: 2.2.2
155
- # setup GEM_HOME environment variable and `volumes_from` to mount the global gemset container
156
- containers:
157
- - web
158
-
159
125
  # ---
160
126
  # Declare a reusable extract set
161
127
  extractions: &extractions
162
128
  web:
163
129
  extract:
164
- - '/project/target'
165
- - '/project/vcr'
166
- - '/project/spec/dummy/log:spec/dummy'
167
- - '/project/tmp/parallel_runtime_cucumber.log:./tmp'
168
- - '/project/tmp/parallel_runtime_rspec.log:./tmp'
130
+ - '/app/target'
131
+ - '/app/vcr'
132
+ - '/app/spec/dummy/log:spec/dummy'
133
+ - '/app/tmp/parallel_runtime_cucumber.log:./tmp'
134
+ - '/app/tmp/parallel_runtime_rspec.log:./tmp'
169
135
 
170
136
 
171
137
  # ---
@@ -181,7 +147,7 @@ elasticsearch: &elasticsearch
181
147
  compose:
182
148
  web:
183
149
  build: .
184
- working_dir: /project/spec/dummy
150
+ working_dir: /app/spec/dummy
185
151
  ports:
186
152
  - "3000"
187
153
  links:
@@ -17,6 +17,5 @@ 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/gemset_volume'
21
20
 
22
21
  require 'docker/rails/cli/main'
@@ -37,6 +37,39 @@ module Docker
37
37
  @is_configured = true
38
38
  end
39
39
 
40
+ # Create a dockito vault container for serving private keys
41
+ # https://github.com/dockito/vault
42
+ def create_dockito_vault
43
+ begin
44
+ Docker::Container.get(dockito_vault_name)
45
+ puts "Dockito vault container #{dockito_vault_name} already exists."
46
+ rescue Docker::Error::NotFoundError => e
47
+
48
+ # docker run --detach --name vault -p 14242:3000 -v ~/.ssh:/vault/.ssh dockito/vault:latest
49
+ exec "docker run --detach --name #{dockito_vault_name} -p 14242:3000 -v ~/.ssh:/vault/.ssh dockito/vault:latest"
50
+ puts "Dockito vault container #{dockito_vault_name} created."
51
+ end
52
+ end
53
+
54
+ def rm_dockito_vault
55
+ begin
56
+ container = Docker::Container.get(dockito_vault_name)
57
+ rm_v(container)
58
+ rescue Docker::Error::NotFoundError => e
59
+ puts "Dockito vault container #{dockito_vault_name} does not exist."
60
+ end
61
+ end
62
+
63
+ # FIXME this needs to by dynamic to this run?
64
+ def dockito_vault_name
65
+ 'vault' #@config[:dockito][:vault][:name]
66
+ end
67
+
68
+ def dockito_vault_enabled?
69
+ @config[:dockito][:vault] || false
70
+ end
71
+
72
+
40
73
  def compose
41
74
  # Write a docker-compose.yml with interpolated variables
42
75
  @compose_filename = compose_filename_from project_name
@@ -118,7 +151,12 @@ module Docker
118
151
 
119
152
  def before_command
120
153
  before_command = @config['before_command']
121
- (exec before_command unless before_command.nil?) #unless skip? :before_command
154
+ (exec before_command unless before_command.nil?)
155
+ end
156
+
157
+ def after_build_command
158
+ after_build_command = @config['after_build_command']
159
+ (exec after_build_command unless after_build_command.nil?)
122
160
  end
123
161
 
124
162
  def up(options = '')
@@ -191,6 +229,14 @@ module Docker
191
229
  puts 'Done.'
192
230
  end
193
231
 
232
+ def rm_exited
233
+ puts "\n\nCleaning up exited containers..."
234
+ puts '-----------------------------'
235
+
236
+ exec('docker rm -v $(docker ps -a -q -f status=exited)', false, true)
237
+ puts 'Done.'
238
+ end
239
+
194
240
  def run_service_command(service_name, command)
195
241
  # Run the compose configuration
196
242
  exec_compose("run #{service_name} #{command}", false, '', true)
@@ -208,28 +254,6 @@ module Docker
208
254
  container
209
255
  end
210
256
 
211
- # Create global gems data volume to cache gems for this version of ruby
212
- # https://docs.docker.com/userguide/dockervolumes/
213
- def create_gemset_volume
214
- begin
215
- Docker::Container.get(gemset_volume_name)
216
- puts "Gem data volume container #{gemset_volume_name} already exists."
217
- rescue Docker::Error::NotFoundError => e
218
-
219
- exec "docker create -v #{gemset_volume_path} --name #{gemset_volume_name} busybox"
220
- puts "Gem data volume container #{gemset_volume_name} created."
221
- end
222
- end
223
-
224
- def rm_gemset_volume
225
- begin
226
- container = Docker::Container.get(gemset_volume_name)
227
- rm_v(container)
228
- rescue Docker::Error::NotFoundError => e
229
- puts "Gem data volume container #{gemset_volume_name} does not exist."
230
- end
231
- end
232
-
233
257
  protected
234
258
 
235
259
  def exec(cmd, capture = false, ignore_errors = false)
@@ -244,7 +268,7 @@ module Docker
244
268
  output
245
269
  end
246
270
 
247
- # convenience to execute docker-compose with file and project params
271
+ # convenience to execute docker-compose with file and project params
248
272
  def exec_compose(cmd, capture = false, options = '', ignore_errors = false)
249
273
  # in the case of running a bash session, this file may dissappear, just make sure it is there.
250
274
  compose unless File.exists?(@compose_filename)
@@ -276,7 +300,7 @@ module Docker
276
300
  @verbose ||= (@config['verbose'] unless @config.nil?) || false
277
301
  end
278
302
 
279
- # accessible so that we can delete patterns
303
+ # accessible so that we can delete patterns
280
304
  def compose_filename_from(project_name)
281
305
  "docker-compose-#{project_name}.yml"
282
306
  end
@@ -323,7 +347,7 @@ module Docker
323
347
  kill(container)
324
348
  end
325
349
 
326
- # kill container, progressively more forceful from -1, -9, then full Chuck Norris.
350
+ # kill container, progressively more forceful from -1, -9, then full Chuck Norris.
327
351
  def kill(container)
328
352
  %w(SIGHUP SIGKILL SIGSTOP).each do |signal|
329
353
  if container.up?
@@ -345,14 +369,6 @@ module Docker
345
369
  container.remove(v: true, force: true)
346
370
  end
347
371
 
348
- def gemset_volume_name
349
- @config[:gemset][:volume][:name]
350
- end
351
-
352
- def gemset_volume_path
353
- @config[:gemset][:volume][:path]
354
- end
355
-
356
372
  def project_name
357
373
  @config[:project_name]
358
374
  end
@@ -9,9 +9,6 @@ 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 'gemset_volume <command>', 'Gemset volume management e.g. docker-rails gemset_volume create'
13
- subcommand 'gemset_volume', Docker::Rails::CLI::GemsetVolume
14
-
15
12
  desc 'ci <target>', 'Execute the works, everything with cleanup included e.g. docker-rails ci --build=222 test'
16
13
  long_desc <<-D
17
14
 
@@ -26,7 +23,6 @@ module Docker
26
23
 
27
24
  invoke :before, [target], []
28
25
  invoke :compose, [target], []
29
- invoke CLI::GemsetVolume, :create, [target], options
30
26
  begin
31
27
  invoke :build # on CI - always build to ensure dockerfile hasn't been altered - small price to pay for consistent CI.
32
28
  invoke :up
@@ -53,7 +49,7 @@ module Docker
53
49
  invoke :extract if options[:extract]
54
50
  invoke :rm_volumes
55
51
  invoke :rm_compose
56
- invoke :rm_dangling
52
+ # invoke :rm_dangling # causes a brand new dockerfile build - don't do that. See https://github.com/alienfast/docker-rails/issues/26
57
53
  invoke :ps_all
58
54
  end
59
55
 
@@ -66,7 +62,6 @@ module Docker
66
62
  base_options = options.except(:detached)
67
63
 
68
64
  invoke :before, [target], base_options
69
- invoke CLI::GemsetVolume, :create, [target], base_options
70
65
 
71
66
  if options[:detached]
72
67
  compose_options = '-d'
@@ -81,7 +76,14 @@ module Docker
81
76
 
82
77
  def build(target)
83
78
  invoke :compose
84
- App.configured(target, options).compose_build
79
+ app = App.configured(target, options)
80
+ app.create_dockito_vault
81
+ begin
82
+ app.compose_build
83
+ ensure
84
+ app.rm_dockito_vault
85
+ app.after_build_command
86
+ end
85
87
  end
86
88
 
87
89
  desc 'compose <target>', 'Writes a resolved docker-compose.yml file e.g. docker-rails compose --build=222 test'
@@ -124,6 +126,12 @@ module Docker
124
126
  App.instance.rm_dangling
125
127
  end
126
128
 
129
+ desc 'rm_exited', 'Remove exited containers e.g. docker-rails rm_exited'
130
+
131
+ def rm_exited(build = nil, target = nil)
132
+ App.instance.rm_exited
133
+ end
134
+
127
135
  desc 'ps <target>', 'List containers for the target compose configuration e.g. docker-rails ps --build=222 development'
128
136
 
129
137
  def ps(target)
@@ -137,7 +145,7 @@ module Docker
137
145
  App.instance.ps_all
138
146
  end
139
147
 
140
- 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'
148
+ desc 'bash_connect <target> <service_name>', 'Open a bash shell to a running container (with automatic cleanup) e.g. docker-rails bash_connect --build=222 development db'
141
149
 
142
150
  def bash_connect(target, service_name)
143
151
  # init singleton with full options
@@ -160,7 +168,6 @@ module Docker
160
168
  app = App.configured(target, options)
161
169
 
162
170
  invoke :compose, [target], []
163
- invoke CLI::GemsetVolume, :create, [target], []
164
171
 
165
172
  app.run_service_command(service_name, command)
166
173
  end
@@ -60,10 +60,6 @@ module Docker
60
60
  generated_defaults = {compose: {}}
61
61
  compose = generated_defaults[:compose]
62
62
 
63
- # ----
64
- # gemset volume
65
- generate_gemset(compose, unpruned_config, generated_defaults, filenames)
66
-
67
63
  # now add the generated to the seeded default configuration
68
64
  @default_configuration.merge!(generated_defaults)
69
65
 
@@ -73,42 +69,6 @@ module Docker
73
69
  # finally, load the config as internal state
74
70
  super(environment, *filenames)
75
71
  end
76
-
77
- protected
78
-
79
- def generate_gemset(compose, unpruned_config, generated_defaults, filenames)
80
- gemset = unpruned_config[:gemset]
81
- raise "Expected to find 'gemset:' in #{filenames}" if gemset.nil?
82
-
83
- gemset_name = gemset[:name]
84
- raise "Expected to find 'gemset: name' in #{filenames}" if gemset_name.nil?
85
-
86
- # add the generated gemset name/path to the generated defaults
87
- gemset_volume_path = "/gemset/#{gemset_name}"
88
- gemset_volume_name = "gemset-#{gemset_name}"
89
-
90
- generated_defaults.deeper_merge!(gemset: gemset)
91
- generated_defaults[:gemset].deeper_merge!({
92
- volume: {
93
- name: gemset_volume_name,
94
- path: gemset_volume_path
95
- }
96
-
97
- })
98
-
99
- raise "Expected to find 'gemset: containers' with at least one entry" if gemset[:containers].nil? || gemset[:containers].length < 1
100
- gemset[:containers].each do |container|
101
- raise "Unknown container #{container}" if unpruned_config[:compose][container.to_sym].nil?
102
- compose[container.to_sym] ||= {}
103
- compose[container.to_sym].deeper_merge! ({
104
- environment: [
105
- "GEM_HOME=#{gemset_volume_path}",
106
- "BUNDLE_PATH=#{gemset_volume_path}",
107
- ],
108
- volumes_from: [gemset_volume_name]
109
- })
110
- end
111
- end
112
72
  end
113
73
  end
114
74
  end
@@ -1,5 +1,5 @@
1
1
  module Docker
2
2
  module Rails
3
- VERSION = '0.9.0'
3
+ VERSION = '0.10.0'
4
4
  end
5
5
  end
@@ -81,9 +81,9 @@ describe Docker::Rails::Config do
81
81
  compose_config
82
82
  }
83
83
 
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')
84
+ it 'web should have env and wd' do
85
+ expect(compose_config[:web][:environment]).to include('RAILS_ENV=development')
86
+ expect(compose_config[:web][:working_dir]).to include('/app')
87
87
  end
88
88
  end
89
89
  end
@@ -2,53 +2,15 @@ verbose: true
2
2
  before_command: bash -c "rm -Rf target && rm -Rf log"
3
3
  exit_code: web
4
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
5
  # shared extractions
44
6
  extractions: &extractions
45
7
  web:
46
8
  extract:
47
- - '/project/target'
48
- - '/project/vcr'
49
- - '/project/tmp/parallel_runtime_cucumber.log:./tmp'
50
- - '/project/tmp/parallel_runtime_rspec.log:./tmp'
51
- - '/project/log'
9
+ - '/app/target'
10
+ - '/app/vcr'
11
+ - '/app/tmp/parallel_runtime_cucumber.log:./tmp'
12
+ - '/app/tmp/parallel_runtime_rspec.log:./tmp'
13
+ - '/app/log'
52
14
 
53
15
  # local environments need elasticsearch, staging/production connects to existing running instance.
54
16
  elasticsearch: &elasticsearch
@@ -192,7 +154,7 @@ compose:
192
154
 
193
155
  web:
194
156
  build: .
195
- working_dir: /project
157
+ working_dir: /app
196
158
  ports:
197
159
  - "3000"
198
160
 
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.9.0
4
+ version: 0.10.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: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,7 +158,6 @@ 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/gemset_volume.rb
162
161
  - lib/docker/rails/cli/main.rb
163
162
  - lib/docker/rails/compose_config.rb
164
163
  - lib/docker/rails/config.rb
@@ -188,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
187
  version: '0'
189
188
  requirements: []
190
189
  rubyforge_project:
191
- rubygems_version: 2.5.1
190
+ rubygems_version: 2.6.7
192
191
  signing_key:
193
192
  specification_version: 4
194
193
  summary: A simplified pattern to execute rails applications within Docker (with a
@@ -1,17 +0,0 @@
1
- module Docker
2
- module Rails
3
- module CLI
4
- class GemsetVolume < Thor
5
- desc 'create', 'Create a gemset volume'
6
- def create(target = nil)
7
- App.configured(target, options).create_gemset_volume
8
- end
9
-
10
- desc 'rm', 'Remove a gemset volume'
11
- def rm(target = nil)
12
- App.configured(target, options).rm_gemset_volume
13
- end
14
- end
15
- end
16
- end
17
- end