docker_maker 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/docker_builder.gemspec +1 -1
- data/example/Procfile +1 -0
- data/example/make.rb +21 -0
- data/lib/docker/maker.rb +128 -112
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32347a333091e175f833aa94bef6f598a8beaa0f
|
4
|
+
data.tar.gz: 7f6bda93c61f6890038ef79e8f36c72df450a6a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feb6129132248b8ab3ad25cf8c0565e73116c679afd612188712cacb4fa685e04a6fa615a34df2d328a73c4d31b7c444bdc401ac73dbfff537e8f1bf4b9b9aa7
|
7
|
+
data.tar.gz: 9fa65550447fe171f868757bb6113f1d880e32b0098e3782ac96f9a57d754b346cabe5d0ff060ed00e2975b7dda7c2ce308bf914881022462e02cb4077a7dc59
|
data/README.md
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
1
|
+
# Docker Maker
|
4
2
|
|
5
3
|
## Installation
|
6
4
|
|
7
5
|
Add this line to your application's Gemfile:
|
8
6
|
|
9
|
-
gem '
|
7
|
+
gem 'docker_maker'
|
10
8
|
|
11
9
|
And then execute:
|
12
10
|
|
@@ -14,7 +12,7 @@ And then execute:
|
|
14
12
|
|
15
13
|
Or install it yourself as:
|
16
14
|
|
17
|
-
$ gem install
|
15
|
+
$ gem install docker_maker
|
18
16
|
|
19
17
|
## Usage
|
20
18
|
|
data/docker_builder.gemspec
CHANGED
data/example/Procfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
web: python -m SimpleHTTPServer $PORT
|
data/example/make.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "docker/maker"
|
4
|
+
|
5
|
+
Docker.make(from: "ubuntu:12.10", to: "brianm/buildy") do |b|
|
6
|
+
b.maintainer "Brian McCallister <brianm@skife.org>"
|
7
|
+
b.env "DEBIAN_FRONTEND" => "noninteractive",
|
8
|
+
"USER" => "xncore",
|
9
|
+
"PORT" => "8000"
|
10
|
+
|
11
|
+
b.bash <<-EOS
|
12
|
+
apt-get update
|
13
|
+
apt-get install -y python python-pip
|
14
|
+
pip install honcho
|
15
|
+
EOS
|
16
|
+
|
17
|
+
b.put "Procfile" => "/Procfile"
|
18
|
+
b.cmd ["/bin/bash", "-c", "honcho start"]
|
19
|
+
b.expose "8000"
|
20
|
+
end
|
21
|
+
|
data/lib/docker/maker.rb
CHANGED
@@ -3,130 +3,146 @@
|
|
3
3
|
require "open3"
|
4
4
|
require "json"
|
5
5
|
|
6
|
-
|
7
|
-
attr_reader :docker, :name
|
8
|
-
|
9
|
-
def initialize base, name, path="/usr/bin/docker"
|
10
|
-
@docker = path
|
11
|
-
@name = name
|
12
|
-
@ports = []
|
13
|
-
@env = []
|
6
|
+
module Docker
|
14
7
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
class Maker
|
9
|
+
attr_reader :docker, :name
|
10
|
+
|
11
|
+
def initialize base, name, path="/usr/bin/docker"
|
12
|
+
@docker = path
|
13
|
+
@name = name
|
14
|
+
@ports = []
|
15
|
+
@env = []
|
16
|
+
|
17
|
+
_, s = _exec [docker, "images", "|", "grep", base]
|
18
|
+
unless s
|
19
|
+
msg, s = _exec [docker, "pull", base]
|
20
|
+
raise msg unless s
|
21
|
+
end
|
22
|
+
@img, s = _exec [docker, "run", "-d", base, "/bin/bash", "-c", "ls"]
|
23
|
+
raise out unless s
|
24
|
+
_commit
|
19
25
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
if input
|
29
|
-
while buff = input.read(4096)
|
30
|
-
sin.write buff
|
26
|
+
|
27
|
+
def _exec args, input=nil
|
28
|
+
puts "#{args.join(" ")}"
|
29
|
+
Open3.popen3(*args) do |sin, sout, serr, wait|
|
30
|
+
if input
|
31
|
+
while buff = input.read(4096)
|
32
|
+
sin.write buff
|
33
|
+
end
|
31
34
|
end
|
35
|
+
sin.close
|
36
|
+
status = wait.value
|
37
|
+
m = sout.read.strip
|
38
|
+
[m, status.success?]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def _commit
|
43
|
+
c = [docker, "commit"]
|
44
|
+
run = {"PortSpecs" => @ports,
|
45
|
+
"Env" => @env}
|
46
|
+
|
47
|
+
run['Cmd'] = @cmd if @cmd
|
48
|
+
run['User'] = @user if @user
|
49
|
+
if @maint
|
50
|
+
c << "-m"
|
51
|
+
c << @maint
|
32
52
|
end
|
33
|
-
|
34
|
-
|
35
|
-
m = sout.read.strip
|
36
|
-
[m, status.success?]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def _commit
|
41
|
-
c = [docker, "commit"]
|
42
|
-
run = {"PortSpecs" => @ports,
|
43
|
-
"Env" => @env}
|
44
|
-
|
45
|
-
run['Cmd'] = @cmd if @cmd
|
46
|
-
run['User'] = @user if @user
|
47
|
-
if @maint
|
48
|
-
c << "-m"
|
49
|
-
c << @maint
|
53
|
+
out, s = _exec [docker, "commit", "-run", JSON.dump(run), @img, @name]
|
54
|
+
raise "commit failed: #{out}" unless s
|
50
55
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
_wait
|
120
|
-
_commit
|
56
|
+
|
57
|
+
def _wait
|
58
|
+
out, s = _exec [docker, "wait", @img]
|
59
|
+
raise "commit failed: #{out}" unless s
|
60
|
+
end
|
61
|
+
|
62
|
+
def _bash cmd, input=nil
|
63
|
+
cmd = [docker, "run", "-d", @name, "/bin/bash", "-c", cmd]
|
64
|
+
@img, s = _exec cmd, input
|
65
|
+
raise @img unless s
|
66
|
+
s
|
67
|
+
end
|
68
|
+
|
69
|
+
def bash cmd
|
70
|
+
_bash cmd
|
71
|
+
_wait
|
72
|
+
_commit
|
73
|
+
end
|
74
|
+
|
75
|
+
def cmd c
|
76
|
+
@cmd = Array(c)
|
77
|
+
_commit
|
78
|
+
end
|
79
|
+
|
80
|
+
def maintainer mnt
|
81
|
+
@maint = mnt
|
82
|
+
_commit
|
83
|
+
end
|
84
|
+
|
85
|
+
def expose port
|
86
|
+
puts "exposing #{port}"
|
87
|
+
@ports << port
|
88
|
+
_commit
|
89
|
+
end
|
90
|
+
|
91
|
+
def user usr
|
92
|
+
@user = usr
|
93
|
+
end
|
94
|
+
|
95
|
+
def env hash
|
96
|
+
@env = @env + hash.inject([]) {|a, (k, v)| a << "#{k}=#{v}"}
|
97
|
+
_commit
|
98
|
+
end
|
99
|
+
|
100
|
+
# IMG=$(docker run -i -a stdin brianm/ruby /bin/bash -c "/bin/cat >
|
101
|
+
# /echo.rb" < ./echo.rb)
|
102
|
+
def put vals
|
103
|
+
vals.each do |k, v|
|
104
|
+
if File.directory? k
|
105
|
+
# mkdir foo; bsdtar -cf - -C adir . | (bsdtar xpf - -C foo )
|
106
|
+
open("|tar -cf - -C #{k} .") do |input|
|
107
|
+
bash "mkdir -p #{v}"
|
108
|
+
cmd = [docker, "run", "-i","-a", "stdin", @name,
|
109
|
+
"/bin/bash", "-c", "tar xpf - -C #{v}"]
|
110
|
+
@img, s = _exec cmd, input
|
111
|
+
raise @img unless s
|
112
|
+
_wait
|
113
|
+
_commit
|
114
|
+
end
|
115
|
+
else
|
116
|
+
File.open(k, "r") do |input|
|
117
|
+
cmd = [docker, "run", "-i","-a", "stdin", @name,
|
118
|
+
"/bin/bash", "-c", "/bin/cat > #{v}"]
|
119
|
+
@img, s = _exec cmd, input
|
120
|
+
raise @img unless s
|
121
|
+
_wait
|
122
|
+
_commit
|
123
|
+
end
|
121
124
|
end
|
122
125
|
end
|
123
126
|
end
|
124
|
-
end
|
127
|
+
end
|
125
128
|
|
129
|
+
|
126
130
|
def self.make(args)
|
127
131
|
from = args[:from]
|
128
132
|
to = args[:to]
|
129
|
-
d =
|
133
|
+
d = Maker.new(from, to)
|
130
134
|
yield d
|
131
135
|
end
|
136
|
+
|
137
|
+
Image = Struct.new :repo, :tag, :id, :created
|
138
|
+
|
139
|
+
def self.images path="/usr/bin/docker"
|
140
|
+
`#{path} images | tail -n +2`.split(/\n/).inject([]) do |a, line|
|
141
|
+
repo, tag, id, created = line.split(/\s\s+/)
|
142
|
+
repo = nil if repo == '<none>'
|
143
|
+
tag = nil if tag == '<none>'
|
144
|
+
a << Image.new(repo, tag, id, created)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
132
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian McCallister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,8 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- docker_builder.gemspec
|
54
|
+
- example/Procfile
|
55
|
+
- example/make.rb
|
54
56
|
- lib/docker/maker.rb
|
55
57
|
homepage: http://github.com/brianm/docker_builder/
|
56
58
|
licenses:
|