docker-rails 0.3.1 → 0.4.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 +4 -4
- data/README.md +15 -7
- data/bin/docker-rails +2 -2
- data/docker-rails.gemspec +1 -0
- data/lib/docker/rails.rb +1 -0
- data/lib/docker/rails/app.rb +64 -0
- data/lib/docker/rails/cli/main.rb +17 -6
- data/lib/docker/rails/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d26c8278640216cf598752f489b351eac1528b36
|
4
|
+
data.tar.gz: d6b8073a625aba9bf8a2e8363dc13f88e043b30e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 968f011b7447d44c7f9d300256092f16bccd3d1cb76a374a56fa96f9e94c8e56e6471b7f49dd6731a167401c4012c4023ed7c0a21a1ee00923a486c158815276
|
7
|
+
data.tar.gz: bb4a69f2f43f141989b8cbea4ba678ed088d14769b2ec7f96248103dc7e43a291cd44b6f9ccdec4a19afa6ad0a45d22bb6711ea784c82737bb70eb092ab6ad12
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ A simplified pattern to execute rails applications within Docker (with a CI buil
|
|
7
7
|
|
8
8
|
## Features
|
9
9
|
- DRY declarative `docker-rails.yml` allowing multiple environments to be defined with an inherited docker `compose` configuration
|
10
|
-
- Provides individual convenience functions `up | bash | stop | cleanup` to easily work with target environment (even in a concurrent situation)
|
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
12
|
- Automated cached global gems data volume based on ruby version
|
13
13
|
- Interpolates variables `docker-compose.yml` making CI builds much easier
|
@@ -103,6 +103,8 @@ RUN apt-get update -qq && \
|
|
103
103
|
cd /var/lib/apt/lists && rm -fr *Release* *Sources* *Packages* && \
|
104
104
|
truncate -s 0 /var/log/*log
|
105
105
|
|
106
|
+
COPY . /project # figure out/automate this as a volume instead https://github.com/alienfast/docker-rails/issues/14
|
107
|
+
|
106
108
|
# https://github.com/docker/docker/issues/4032
|
107
109
|
ENV DEBIAN_FRONTEND newt
|
108
110
|
```
|
@@ -110,11 +112,20 @@ ENV DEBIAN_FRONTEND newt
|
|
110
112
|
### 2. Add a docker-rails.yml
|
111
113
|
|
112
114
|
Environment variables will be interpolated, so feel free to use them.
|
113
|
-
|
115
|
+
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.
|
114
116
|
|
115
117
|
```yaml
|
116
118
|
verbose: true
|
119
|
+
before_command: bash -c "rm -Rf target && rm -Rf spec/dummy/log"
|
117
120
|
|
121
|
+
extractions: &extractions
|
122
|
+
web:
|
123
|
+
extract:
|
124
|
+
- '/project/target'
|
125
|
+
- '/project/vcr'
|
126
|
+
- '/project/tmp'
|
127
|
+
- '/project/spec/dummy/log:spec/dummy'
|
128
|
+
|
118
129
|
# local environments need elasticsearch, staging/production connects to existing running instance.
|
119
130
|
elasticsearch: &elasticsearch
|
120
131
|
elasticsearch:
|
@@ -157,7 +168,7 @@ development:
|
|
157
168
|
"
|
158
169
|
|
159
170
|
test:
|
160
|
-
|
171
|
+
<<: *extractions
|
161
172
|
compose:
|
162
173
|
<<: *elasticsearch
|
163
174
|
web:
|
@@ -185,7 +196,7 @@ test:
|
|
185
196
|
"
|
186
197
|
|
187
198
|
parallel_tests:
|
188
|
-
|
199
|
+
<<: *extractions
|
189
200
|
compose:
|
190
201
|
<<: *elasticsearch
|
191
202
|
web:
|
@@ -252,9 +263,6 @@ compose:
|
|
252
263
|
links:
|
253
264
|
- db
|
254
265
|
|
255
|
-
volumes:
|
256
|
-
- .:/project
|
257
|
-
|
258
266
|
volumes_from:
|
259
267
|
# Mount the gems data volume container for cached bundler gem files
|
260
268
|
- #{DOCKER_RAILS_GEMS_VOLUME_NAME}
|
data/bin/docker-rails
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# enable local usage from cloned repo
|
4
|
-
|
5
|
-
|
4
|
+
root = File.expand_path('../..', __FILE__)
|
5
|
+
$LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile")
|
6
6
|
|
7
7
|
require 'docker/rails'
|
8
8
|
|
data/docker-rails.gemspec
CHANGED
data/lib/docker/rails.rb
CHANGED
data/lib/docker/rails/app.rb
CHANGED
@@ -41,6 +41,66 @@ module Docker
|
|
41
41
|
@is_configured || false
|
42
42
|
end
|
43
43
|
|
44
|
+
def extract
|
45
|
+
|
46
|
+
# For each container, process extractions
|
47
|
+
# Containers are defined in compose, extractions are defined at root under container name e.g.:
|
48
|
+
# web:
|
49
|
+
# extract:
|
50
|
+
# - '<from_container>:<to_host>'
|
51
|
+
# - '/project/target:.'
|
52
|
+
# - '/project/vcr' # same as extract to '.'
|
53
|
+
# - '/project/tmp'
|
54
|
+
# - '/project/spec/dummy/log:spec/dummy'
|
55
|
+
@compose_config.each_key do |service_name|
|
56
|
+
service_config = @config[service_name]
|
57
|
+
extractions = service_config[:extract] unless service_config.nil?
|
58
|
+
next if extractions.nil?
|
59
|
+
|
60
|
+
puts "Processing extract for #{service_name}:"
|
61
|
+
puts '---------------------------------'
|
62
|
+
container = get_container(service_name)
|
63
|
+
extractions.each do |extraction|
|
64
|
+
if extraction =~ /:/
|
65
|
+
tokens = extraction.split(':')
|
66
|
+
from = tokens[0]
|
67
|
+
to = tokens[1]
|
68
|
+
else
|
69
|
+
from = extraction
|
70
|
+
to = '.'
|
71
|
+
end
|
72
|
+
|
73
|
+
puts "\nExtracting #{service_name} #{from} to #{to}"
|
74
|
+
extract_files(container, from, to)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def extract_files(container, from, to)
|
81
|
+
# or something like
|
82
|
+
tar_stringio = StringIO.new
|
83
|
+
container.copy(from) do |chunk|
|
84
|
+
tar_stringio.write(chunk)
|
85
|
+
end
|
86
|
+
|
87
|
+
tar_stringio.rewind
|
88
|
+
|
89
|
+
input = Archive::Tar::Minitar::Input.new(tar_stringio)
|
90
|
+
input.each { |entry|
|
91
|
+
|
92
|
+
# Need to check the file name length to prevent some very bad things from happening.
|
93
|
+
if entry.full_name.length > 255
|
94
|
+
puts "ERROR - file name length is > 255 characters: #{entry.full_name}"
|
95
|
+
elsif entry.full_name.length <= 0
|
96
|
+
puts "ERROR - file name length is too small: #{entry.full_name}"
|
97
|
+
else
|
98
|
+
puts "Extracting #{entry.full_name}"
|
99
|
+
input.extract_entry(to, entry)
|
100
|
+
end
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
44
104
|
def compose
|
45
105
|
# Write a docker-compose.yml with interpolated variables
|
46
106
|
@compose_filename = compose_filename_from @build, @target
|
@@ -162,6 +222,10 @@ module Docker
|
|
162
222
|
$1
|
163
223
|
end
|
164
224
|
|
225
|
+
def get_container(service_name)
|
226
|
+
Docker::Container.get(get_container_name(service_name))
|
227
|
+
end
|
228
|
+
|
165
229
|
# def up_service(service_name, options = '')
|
166
230
|
# exec_compose "up #{options} #{service_name}"
|
167
231
|
# container_name = get_container_name(service_name)
|
@@ -24,9 +24,9 @@ module Docker
|
|
24
24
|
# init singleton with full options
|
25
25
|
App.configured(target, options)
|
26
26
|
|
27
|
-
invoke :
|
27
|
+
invoke :before, [target], []
|
28
|
+
invoke :compose, [target], []
|
28
29
|
invoke CLI::GemsVolume, :create, [target], options
|
29
|
-
invoke :before
|
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
|
@@ -35,9 +35,20 @@ module Docker
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
desc 'extract <target>', 'Invoke extractions', hide: true
|
39
|
+
|
40
|
+
def extract(target)
|
41
|
+
app = App.configured(target, options)
|
42
|
+
invoke :compose, [target], []
|
43
|
+
app.extract
|
44
|
+
end
|
45
|
+
|
38
46
|
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'
|
47
|
+
option :extract, aliases: ['-e'], type: :boolean, default: true, desc: 'Extract any directories defined in configuration.'
|
48
|
+
|
39
49
|
def cleanup(target)
|
40
50
|
invoke :stop
|
51
|
+
invoke :extract if options[:extract]
|
41
52
|
invoke :rm_volumes
|
42
53
|
invoke :rm_compose
|
43
54
|
invoke :rm_dangling
|
@@ -45,7 +56,6 @@ module Docker
|
|
45
56
|
end
|
46
57
|
|
47
58
|
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'
|
48
|
-
|
49
59
|
option :detached, aliases: ['-d'], type: :boolean, desc: 'Detached mode: Run containers in the background'
|
50
60
|
|
51
61
|
def up(target)
|
@@ -53,8 +63,8 @@ module Docker
|
|
53
63
|
app = App.configured(target, options)
|
54
64
|
base_options = options.except(:detached)
|
55
65
|
|
56
|
-
invoke CLI::GemsVolume, :create, [target], base_options
|
57
66
|
invoke :before, [target], base_options
|
67
|
+
invoke CLI::GemsVolume, :create, [target], base_options
|
58
68
|
|
59
69
|
compose_options = ''
|
60
70
|
compose_options = '-d' if options[:detached]
|
@@ -79,8 +89,9 @@ module Docker
|
|
79
89
|
desc 'before <target>', 'Invoke before_command', hide: true
|
80
90
|
|
81
91
|
def before(target)
|
82
|
-
|
83
|
-
|
92
|
+
app = App.configured(target, options)
|
93
|
+
invoke :compose, [target], []
|
94
|
+
app.exec_before_command
|
84
95
|
end
|
85
96
|
|
86
97
|
|
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.
|
4
|
+
version: 0.4.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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: minitar
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: ''
|
126
140
|
email:
|
127
141
|
- kevin.ross@alienfast.com
|