-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake_dockerfile.rb
executable file
·59 lines (51 loc) · 1.67 KB
/
make_dockerfile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/ruby
require 'optparse'
require 'erb'
SHARE_DIR = "/usr/share/whalebuilder"
class Templater
def write (filename)
b = binding
result = ERB.new(File.read(File.join(SHARE_DIR, self.class::TEMPLATE_FILE)), nil, "-").result b
File.open(filename, "w") do |file|
file.write result
end
end
end
class Dockerfile < Templater
TEMPLATE_FILE = "Dockerfile.base.erb"
def initialize (options)
@distribution = options[:distribution]
@tag = options[:release]
@maintainer = options[:maintainer]
@repository = options[:repository]
@hooks = []
end
end
options = {}
options[:distribution] = "debian"
options[:release] = "stable"
options[:repository] = nil
options[:maintainer] = "Nobody <[email protected]>"
opt_parser = OptionParser.new do |opts|
opts.banner = "Create a Dockerfile for whalebuilder
Usage: #{opts.program_name} [options] <outputdir>"
opts.separator ""
opts.separator "Options:"
opts.on "-d", "--distribution NAME", "distribution name. This should match a Docker image name (default: debian)" do |v|
options[:distribution] = v
end
opts.on "-r", "--release NAME", "release name. This should match a tag for the base Docker image (default: stable)" do |v|
options[:release] = v
end
opts.on "--repository URL", "apt repository to use (default: http://httpredir.debian.org/debian)" do |v|
options[:repository] = v
end
opts.on "--maintainer NAME", "maintainer (default: Nobody <[email protected]>)" do |v|
options[:maintainer] = v
end
end
opt_parser.parse! ARGV
if ARGV.length == 0
opt_parser.abort "Error: no output directory specified"
end
Dockerfile.new(options).write(File.join(ARGV.shift, "Dockerfile"))