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
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
120
121
122
123
124
|
# File 'lib/mason/cli.rb', line 31
def build(app)
app = File.expand_path(app)
raise "no such directory: #{app}" unless File.exists?(app)
type = options[:type]
output = options[:output]
type = File.extname(output)[1..-1] if !type && output
output = "#{app}.#{type}" if !output && type
type ||= "dir"
output ||= "/tmp/mason.out"
output = File.expand_path(output)
raise "no such output format: #{type}" unless %w( dir img tgz ).include?(type)
if stack = options[:stack]
if Mason::Stacks.state(stack) == :up
puts "* using stack #{stack}"
else
print "* booting stack #{stack} (this may take a while)... "
Mason::Stacks.up(stack)
puts "done"
end
buildpacks_dir = File.expand_path("~/.mason/share/#{stack}/buildpacks")
compile_dir = File.expand_path("~/.mason/share/#{stack}/app")
mason_dir = File.expand_path("~/.mason/share/#{stack}/mason")
FileUtils.rm_rf buildpacks_dir
FileUtils.rm_rf compile_dir
FileUtils.rm_rf mason_dir
Mason.cp_R(File.expand_path("~/.mason/buildpacks"), buildpacks_dir,
:preserve => true)
Mason.cp_R(File.expand_path("../../../", __FILE__), mason_dir,
:preserve => true)
Mason.cp_R(app, compile_dir, :preserve => true)
mason_args = %{ /share/app -q -o /share/output -t #{type} }
mason_args += %{ -b "#{options[:buildpack]}" } if options[:buildpack]
Mason::Stacks.run(stack, " gem spec thor 2>&1 >/dev/null || sudo gem install thor\n /usr/bin/env ruby -rubygems /share/mason/bin/mason build \#{mason_args}\n COMMAND\n\n FileUtils.rm_rf output\n Mason.cp_R(File.expand_path(\"~/.mason/share/\#{stack}/output\"), output,\n :preserve => true)\n\n puts \"* packaging\"\n puts \" = type: \#{type}\"\n puts \" = location: \#{output}\"\n else\n print \"* detecting buildpack... \"\n\n buildpack_url = ENV[\"BUILDPACK_URL\"] || options[:buildpack]\n buildpack, ret = Mason::Buildpacks.detect(app, buildpack_url)\n raise \"no valid buildpack detected\" unless buildpack\n\n puts \"done\"\n puts \" = name: \#{buildpack.name}\"\n puts \" = url: \#{buildpack.url}\"\n puts \" = display: \#{ret}\"\n\n puts \"* compiling...\"\n compile_dir = buildpack.compile(app, options[:env_file], options[:cache])\n\n print \"* packaging... \" unless options[:quiet]\n case type.to_sym\n when :tgz then\n Dir.chdir(compile_dir) do\n system %{ tar czf \"\#{output}\" . }\n end\n when :img then\n raise \"img not supported yet\"\n when :dir then\n FileUtils.rm_rf output\n Mason.cp_R compile_dir, output, :preserve => true\n else\n raise \"no such output type: \#{type}\"\n end\n\n unless options[:quiet]\n puts \"done\"\n puts \" = type: \#{type}\"\n puts \" = location: \#{output}\"\n end\n end\n\nend\n")
|