docker_maker 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/docker_builder.gemspec +20 -0
- data/lib/docker/maker.rb +132 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0069666cba4ec1d2706115b25f5f646d6b93634c
|
4
|
+
data.tar.gz: 2cc357b064f9e16eebac8be04bfc2293eb8344b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72fcc8518ffae90f7249243478f3a87655782905109897061f2579e85ce3ad4c349ff66633e4fb045fc9f7f8d59f45c5e34e5e938af08516eaaf32ed67413c7b
|
7
|
+
data.tar.gz: b5779dc9a8d0018987d245c05124e9405871bae981fe77c18d23ab9f0fe4d8092fd2462ff95aca86408867b570311fb5bf1b51336968a6a026a2b475b8301488
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian McCallister
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# DockerBuilder
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'docker_builder'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install docker_builder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
#!/usr/bin/env ruby
|
23
|
+
require "docker/maker"
|
24
|
+
|
25
|
+
Docker.make(from: "ubuntu:12.10", to: "brianm/buildy") do |b|
|
26
|
+
b.maintainer "Brian McCallister <brianm@skife.org>"
|
27
|
+
b.env "DEBIAN_FRONTEND" => "noninteractive",
|
28
|
+
"USER" => "xncore"
|
29
|
+
|
30
|
+
b.bash <<-EOS
|
31
|
+
apt-get update
|
32
|
+
apt-get install -y netcat python python-pip
|
33
|
+
pip install honcho
|
34
|
+
EOS
|
35
|
+
|
36
|
+
b.put "./Procfile" => "/Procfile",
|
37
|
+
"./app/" => "/var/app"
|
38
|
+
b.cmd ["/bin/bash", "-c", "honcho start"]
|
39
|
+
b.expose "8000"
|
40
|
+
|
41
|
+
end
|
42
|
+
```
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "docker_maker"
|
5
|
+
spec.version = '0.0.1'
|
6
|
+
spec.authors = ["Brian McCallister"]
|
7
|
+
spec.email = ["brianm@skife.org"]
|
8
|
+
spec.description = "Library for building docker images"
|
9
|
+
spec.summary = "Library to make it easyto build docker images"
|
10
|
+
spec.homepage = "http://github.com/brianm/docker_builder/"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
end
|
data/lib/docker/maker.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
require "json"
|
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 = []
|
14
|
+
|
15
|
+
_, s = _exec [docker, "images", "|", "grep", base]
|
16
|
+
unless s
|
17
|
+
msg, s = _exec [docker, "pull", base]
|
18
|
+
raise msg unless s
|
19
|
+
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
|
31
|
+
end
|
32
|
+
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
|
50
|
+
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
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.make(args)
|
127
|
+
from = args[:from]
|
128
|
+
to = args[:to]
|
129
|
+
d = Docker.new(from, to)
|
130
|
+
yield d
|
131
|
+
end
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docker_maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian McCallister
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Library for building docker images
|
42
|
+
email:
|
43
|
+
- brianm@skife.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- docker_builder.gemspec
|
54
|
+
- lib/docker/maker.rb
|
55
|
+
homepage: http://github.com/brianm/docker_builder/
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.0.0
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Library to make it easyto build docker images
|
79
|
+
test_files: []
|