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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0069666cba4ec1d2706115b25f5f646d6b93634c
4
- data.tar.gz: 2cc357b064f9e16eebac8be04bfc2293eb8344b6
3
+ metadata.gz: 32347a333091e175f833aa94bef6f598a8beaa0f
4
+ data.tar.gz: 7f6bda93c61f6890038ef79e8f36c72df450a6a1
5
5
  SHA512:
6
- metadata.gz: 72fcc8518ffae90f7249243478f3a87655782905109897061f2579e85ce3ad4c349ff66633e4fb045fc9f7f8d59f45c5e34e5e938af08516eaaf32ed67413c7b
7
- data.tar.gz: b5779dc9a8d0018987d245c05124e9405871bae981fe77c18d23ab9f0fe4d8092fd2462ff95aca86408867b570311fb5bf1b51336968a6a026a2b475b8301488
6
+ metadata.gz: feb6129132248b8ab3ad25cf8c0565e73116c679afd612188712cacb4fa685e04a6fa615a34df2d328a73c4d31b7c444bdc401ac73dbfff537e8f1bf4b9b9aa7
7
+ data.tar.gz: 9fa65550447fe171f868757bb6113f1d880e32b0098e3782ac96f9a57d754b346cabe5d0ff060ed00e2975b7dda7c2ce308bf914881022462e02cb4077a7dc59
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
- # DockerBuilder
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 'docker_builder'
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 docker_builder
15
+ $ gem install docker_maker
18
16
 
19
17
  ## Usage
20
18
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "docker_maker"
5
- spec.version = '0.0.1'
5
+ spec.version = '0.0.2'
6
6
  spec.authors = ["Brian McCallister"]
7
7
  spec.email = ["brianm@skife.org"]
8
8
  spec.description = "Library for building docker images"
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
- class Docker
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
- _, s = _exec [docker, "images", "|", "grep", base]
16
- unless s
17
- msg, s = _exec [docker, "pull", base]
18
- raise msg unless s
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
- @img, s = _exec [docker, "run", "-d", base, "/bin/bash", "-c", "ls"]
21
- raise out unless s
22
- _commit
23
- end
24
-
25
- def _exec args, input=nil
26
- puts "#{args.join(" ")}"
27
- Open3.popen3(*args) do |sin, sout, serr, wait|
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
- sin.close
34
- status = wait.value
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
- out, s = _exec [docker, "commit", "-run", JSON.dump(run), @img, @name]
52
- raise "commit failed: #{out}" unless s
53
- end
54
-
55
- def _wait
56
- out, s = _exec [docker, "wait", @img]
57
- raise "commit failed: #{out}" unless s
58
- end
59
-
60
- def _bash cmd, input=nil
61
- cmd = [docker, "run", "-d", @name, "/bin/bash", "-c", cmd]
62
- @img, s = _exec cmd, input
63
- raise @img unless s
64
- s
65
- end
66
-
67
- def bash cmd
68
- _bash cmd
69
- _wait
70
- _commit
71
- end
72
-
73
- def cmd c
74
- @cmd = Array(c)
75
- _commit
76
- end
77
-
78
- def maintainer mnt
79
- @maint = mnt
80
- _commit
81
- end
82
-
83
- def expose port
84
- puts "exposing #{port}"
85
- @ports << port
86
- _commit
87
- end
88
-
89
- def user usr
90
- @user = usr
91
- end
92
-
93
- def env hash
94
- @env = @env + hash.inject([]) {|a, (k, v)| a << "#{k}=#{v}"}
95
- _commit
96
- end
97
-
98
- # IMG=$(docker run -i -a stdin brianm/ruby /bin/bash -c "/bin/cat >
99
- # /echo.rb" < ./echo.rb)
100
- def put vals
101
- vals.each do |k, v|
102
- if File.directory? k
103
- # mkdir foo; bsdtar -cf - -C adir . | (bsdtar xpf - -C foo )
104
- open("|tar -cf - -C #{k} .") do |input|
105
- bash "mkdir -p #{v}"
106
- cmd = [docker, "run", "-i","-a", "stdin", @name,
107
- "/bin/bash", "-c", "tar xpf - -C #{v}"]
108
- @img, s = _exec cmd, input
109
- raise @img unless s
110
- _wait
111
- _commit
112
- end
113
- else
114
- File.open(k, "r") do |input|
115
- cmd = [docker, "run", "-i","-a", "stdin", @name,
116
- "/bin/bash", "-c", "/bin/cat > #{v}"]
117
- @img, s = _exec cmd, input
118
- raise @img unless s
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 = Docker.new(from, to)
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.1
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-09 00:00:00.000000000 Z
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: