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 +4 -4
- data/README.md +50 -15
- data/lib/docker/rails/app.rb +65 -12
- data/lib/docker/rails/ext/container.rb +4 -1
- data/lib/docker/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 676f2ab08aa5bab4eaa12cd439e73e5b24d05203
|
4
|
+
data.tar.gz: 725d25ce15b195dd2cce0d487198754ab507da5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
##
|
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
|
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
|
-
|
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
|
-
`
|
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
|
-
|
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
|
-
|
330
|
-
|
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
|
|
data/lib/docker/rails/app.rb
CHANGED
@@ -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
|
-
|
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 @
|
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 '*'
|
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
|
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
|
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
|
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
|
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 @
|
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(
|
289
|
-
"docker-compose-#{
|
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)
|
data/lib/docker/rails/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|