docker-rails 0.5.2 → 0.5.3

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: ec5c1185350ab97e62cf01109148ddf3423d1610
4
- data.tar.gz: d0e552e9dba679b392c90ec2bc567332d0b79bcb
3
+ metadata.gz: 676f2ab08aa5bab4eaa12cd439e73e5b24d05203
4
+ data.tar.gz: 725d25ce15b195dd2cce0d487198754ab507da5c
5
5
  SHA512:
6
- metadata.gz: 1da0e5553d88912677d1e7108a3804a014d68ff6d6958c181e18490465323b6bb74ad5cac06754c093972446c52cf9c554a56f372877c4bedaf10fea4e52e8b5
7
- data.tar.gz: d9288310748ee68a9477aa009cba469f808bb1d27cd181bb7177574219a71b48d7630d786268d5e1396a73fd835ef5c15f74402191cae8e76769a452861a6b43
6
+ metadata.gz: dfd7b13048590fd015a9a1bfc2dd574a449007ebc2159f2af15628b04172a29684d418bf728454c40385eb35da1db491c7877328793bbe9209437ff5279a4462
7
+ data.tar.gz: 22fbca62f1a72eca0cef0fe1aaa64e0de97e46de1b49ad518f0600c2a38815288f95fd0780dbbb19557de7249788c4dd595c4077d369aeda41d2b8a70d55436d
data/README.md CHANGED
@@ -40,7 +40,7 @@ CI, the reason this is built. Do it all, do it consistently, do it concurrently,
40
40
 
41
41
  #### CI execution options
42
42
 
43
- **NOTE:** If using `bundle exec`, you'll need to do a `bundle` on both the host and container. These examples avoid `bundle exec` on the host for that reason (ran inside rvm).
43
+ **NOTE:** If using `bundle exec`, you'll need to do a `bundle` on both the host and container. These examples avoid `bundle exec` on the host to avoid the time taken to bundle (it should happen inside your container).
44
44
 
45
45
  In your environment, ensure that `docker-rails` is present:
46
46
 
@@ -93,13 +93,6 @@ Options:
93
93
  # Default: 1
94
94
  ```
95
95
 
96
- ## Work in progress - contributions welcome
97
- Open to pull requests. Open to refactoring. It can be expanded to suit many different configurations.
98
-
99
- TODO:
100
- - **DB versatility** - expand to different db status detection as-needed e.g. postgres. CLI is now modularized to allow for this.
101
-
102
-
103
96
  ## Installation
104
97
 
105
98
  Add this line to your application's Gemfile:
@@ -114,7 +107,7 @@ Or install it yourself as:
114
107
 
115
108
  $ gem install docker-rails
116
109
 
117
- ## Usage
110
+ ## Setup and Configuration
118
111
 
119
112
  ### 1. Add a Dockerfile
120
113
 
@@ -148,7 +141,7 @@ COPY . /project
148
141
  ### 2. Add a docker-rails.yml
149
142
 
150
143
  Environment variables will be interpolated, so feel free to use them.
151
- The rails engine example below shows an example with all of the environments `development | test | parallel_tests | staging` to show reuse of the primary `compose` configuration.
144
+ The _rails engine_ example below shows an example with all of the environments `development | test | parallel_tests | staging` to show reuse of the primary `compose` configuration.
152
145
 
153
146
  ```yaml
154
147
  verbose: true
@@ -320,15 +313,57 @@ compose:
320
313
  - MYSQL_ALLOW_EMPTY_PASSWORD=true
321
314
  ```
322
315
 
323
- ### 3. Run it
316
+ ## CI setup
317
+
318
+ ### Bamboo
319
+
320
+ The following shows execution within Atlassian Bamboo using an script task and RVM on the host.
321
+
322
+ #### 1. Add an inline script task
323
+
324
+ This will run everything, including cleanup.
325
+
326
+ ```bash
327
+ #!/bin/bash
328
+
329
+ # force bash, not bin/sh
330
+ if [ "$(ps -p "$$" -o comm=)" != "bash" ]; then
331
+ # Taken from http://unix-linux.questionfor.info/q_unix-linux-programming_85038.html
332
+ bash "$0" "$@"
333
+ exit "$?"
334
+ fi
335
+
336
+ source ~/.bash_profile
337
+ rvm gemset list
338
+ echo "Build: $bamboo_buildNumber"
339
+ gem install --no-ri --no-rdoc docker-rails
340
+
341
+ docker-rails ci --build=$bamboo_buildNumber parallel_tests
342
+ ```
343
+
344
+ #### 2. Add an inline script final task
324
345
 
325
- `bundle exec docker-rails ci --build=111 test`
346
+ In the _Final tasks_ section, add another inline script task just to ensure cleanup. If all is well, this is duplicate work (that takes very little time), but we have seen cases where executing `stop` in Bamboo will kill off the process without a chance to cleanup. This will take care of that scenario.
326
347
 
327
- ### 4. Submit pull requests!
348
+ ```bash
349
+ #!/bin/bash
350
+
351
+ # force bash, not bin/sh
352
+ if [ "$(ps -p "$$" -o comm=)" != "bash" ]; then
353
+ # Taken from http://unix-linux.questionfor.info/q_unix-linux-programming_85038.html
354
+ bash "$0" "$@"
355
+ exit "$?"
356
+ fi
357
+
358
+ source ~/.bash_profile
359
+ docker-rails cleanup --build=$bamboo_buildNumber parallel_tests
360
+ ```
328
361
 
329
- The intent for this is to make rails with docker a snap. The code should be modular enough that adding a check for a different database etc should be quite simple.
330
- We are open to expanding functionality beyond what is already provided.
362
+ ## Work in progress - contributions welcome
363
+ Open to pull requests. Open to refactoring. It can be expanded to suit many different configurations.
331
364
 
365
+ TODO:
366
+ - **DB versatility** - expand to different db status detection as-needed e.g. postgres. CLI is now modularized to allow for this.
332
367
 
333
368
  ## Contributing
334
369
 
@@ -6,7 +6,8 @@ module Docker
6
6
  attr_reader :config,
7
7
  :compose_config,
8
8
  :ruby_version,
9
- :build,
9
+ :build, # given build, usually a number
10
+ :project_name, # resolved compose project name
10
11
  :target,
11
12
  :gems_volume_path,
12
13
  :gems_volume_name,
@@ -31,12 +32,20 @@ module Docker
31
32
  end
32
33
 
33
34
  def configure(options)
35
+ @target = options[:target]
36
+
34
37
  # Allow CLI option `build` to fallback to an env variable DOCKER_RAILS_BUILD. Note that CLI provides a default build value of 1, so check against the default and existence of the env var.
35
38
  build = options[:build]
36
39
  build = ENV['DOCKER_RAILS_BUILD'] if build.to_i == 1 && !ENV['DOCKER_RAILS_BUILD'].nil?
37
-
38
40
  ENV['DOCKER_RAILS_BUILD'] = @build = build
39
- @target = options[:target]
41
+
42
+ # determine project_name
43
+ dir_name = Dir.pwd.split('/').last
44
+ @project_name = "#{dir_name}_#{target}_#{build}"
45
+
46
+ # FIXME: temporarily sanitize project_name until they loosen restrictions see https://github.com/docker/compose/issues/2119
47
+ @project_name = @project_name.gsub(/[^a-z0-9]/, '')
48
+
40
49
 
41
50
  # load the docker-rails.yml
42
51
  @config = Docker::Rails::Config.new
@@ -95,7 +104,7 @@ module Docker
95
104
 
96
105
  def compose
97
106
  # Write a docker-compose.yml with interpolated variables
98
- @compose_filename = compose_filename_from @build, @target
107
+ @compose_filename = compose_filename_from @project_name
99
108
 
100
109
  rm_compose
101
110
 
@@ -114,7 +123,7 @@ module Docker
114
123
 
115
124
  def rm_compose
116
125
  # Delete old docker compose files
117
- exec "rm #{compose_filename_from '*', '*'}" rescue ''
126
+ exec "rm #{compose_filename_from '*'}" rescue ''
118
127
  end
119
128
 
120
129
  def before_command
@@ -148,8 +157,10 @@ module Docker
148
157
  puts '-----------------------------'
149
158
  containers = Docker::Container.all(all: true)
150
159
  containers.each do |container|
151
- if is_build_container?(container)
160
+ if is_project_container?(container)
152
161
  printf "#{container.name}.."
162
+
163
+ # Stop it
153
164
  container.stop
154
165
  60.times do |i|
155
166
  printf '.'
@@ -160,6 +171,48 @@ module Docker
160
171
  sleep 1
161
172
  end
162
173
 
174
+ # Kill it #1 - if still up, kill it softly? # http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_01.html
175
+ if container.up?
176
+ printf 'killing(-1)'
177
+ container.kill(signal: 'SIGHUP')
178
+ 10.times do |i|
179
+ printf '.'
180
+ if container.down?
181
+ printf "done.\n"
182
+ break
183
+ end
184
+ sleep 1
185
+ end
186
+ end
187
+
188
+ # Kill it #2 - if still up, kill it with a vengeance? # http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_01.html
189
+ if container.up?
190
+ printf 'killing(-9)'
191
+ container.kill(signal: 'SIGKILL')
192
+ 10.times do |i|
193
+ printf '.'
194
+ if container.down?
195
+ printf "done.\n"
196
+ break
197
+ end
198
+ sleep 1
199
+ end
200
+ end
201
+
202
+ # Kill it #3 - if still up, kill it with a chuck norris? # http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_01.html
203
+ if container.up?
204
+ printf 'killing(Chuck Norris)'
205
+ container.kill(signal: 'SIGSTOP')
206
+ 10.times do |i|
207
+ printf '.'
208
+ if container.down?
209
+ printf "done.\n"
210
+ break
211
+ end
212
+ sleep 1
213
+ end
214
+ end
215
+
163
216
  service_name = container.compose.service
164
217
  if @config['exit_code'].eql?(service_name)
165
218
  if container.up?
@@ -181,7 +234,7 @@ module Docker
181
234
  # http://docs.docker.com/v1.7/reference/api/docker_remote_api_v1.19/#remove-a-container
182
235
  containers = Docker::Container.all(all: true)
183
236
  containers.each do |container|
184
- if is_build_container?(container)
237
+ if is_project_container?(container)
185
238
  puts container.name
186
239
  container.remove(v: true, force: true)
187
240
  end
@@ -251,7 +304,7 @@ module Docker
251
304
  def get_container(service_name)
252
305
  containers = Docker::Container.all(all: true)
253
306
  containers.each do |container|
254
- if is_build_container?(container) && container.compose.service.eql?(service_name.to_s)
307
+ if is_project_container?(container) && container.compose.service.eql?(service_name.to_s)
255
308
  return container
256
309
  end
257
310
  end
@@ -259,12 +312,12 @@ module Docker
259
312
  nil
260
313
  end
261
314
 
262
- def is_build_container?(container)
315
+ def is_project_container?(container)
263
316
  # labels = container.info['Labels']
264
317
  # build = labels['com.docker.compose.project']
265
318
 
266
319
  return false if container.compose.nil?
267
- return true if @build.eql? container.compose.project
320
+ return true if @project_name.eql? container.compose.project
268
321
  false
269
322
  end
270
323
 
@@ -285,8 +338,8 @@ module Docker
285
338
  end
286
339
 
287
340
  # accessible so that we can delete patterns
288
- def compose_filename_from(build, target)
289
- "docker-compose-#{target}-#{build}.yml"
341
+ def compose_filename_from(project_name)
342
+ "docker-compose-#{project_name}.yml"
290
343
  end
291
344
 
292
345
  def extract_files(container, from, to)
@@ -9,7 +9,10 @@ class Docker::Container
9
9
  end
10
10
 
11
11
  def up?
12
- status =~ /^(up|Up)/
12
+ # Up 10 seconds
13
+ # Exited (0) 2 seconds ago
14
+ return true if status =~ /^(up|Up)/
15
+ false
13
16
  end
14
17
 
15
18
  def down?
@@ -1,5 +1,5 @@
1
1
  module Docker
2
2
  module Rails
3
- VERSION = '0.5.2'
3
+ VERSION = '0.5.3'
4
4
  end
5
5
  end
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.2
4
+ version: 0.5.3
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-29 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler