mason 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -7
- data/lib/mason/buildpack.rb +50 -19
- data/lib/mason/buildpacks.rb +36 -12
- data/lib/mason/cli.rb +13 -7
- data/lib/mason/version.rb +1 -1
- metadata +51 -32
data/README.md
CHANGED
@@ -52,16 +52,16 @@ You will need [VirtualBox](https://www.virtualbox.org/wiki/Downloads) for Vagran
|
|
52
52
|
|
53
53
|
$ gem install vagrant
|
54
54
|
|
55
|
-
$ vagrant box add
|
55
|
+
$ vagrant box add lucid64 http://files.vagrantup.com/lucid64.box
|
56
56
|
|
57
|
-
$ mason stacks:create
|
58
|
-
* creating stack
|
57
|
+
$ mason stacks:create lucid64
|
58
|
+
* creating stack lucid64... done
|
59
59
|
|
60
|
-
$ mason stacks:up
|
61
|
-
* booting stack
|
60
|
+
$ mason stacks:up lucid64
|
61
|
+
* booting stack lucid64 (this may take a while)... done
|
62
62
|
|
63
|
-
$ mason:build /tmp/app -t tgz -o /tmp/compiled.tgz -s
|
64
|
-
* booting stack
|
63
|
+
$ mason:build /tmp/app -t tgz -o /tmp/compiled.tgz -s lucid64
|
64
|
+
* booting stack lucid64 (this may take a while)... done
|
65
65
|
* detecting buildpack... done
|
66
66
|
= name: Baz
|
67
67
|
= url: https://github.com/ddollar/buildpack-baz.git
|
data/lib/mason/buildpack.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "mason"
|
2
2
|
require "tmpdir"
|
3
|
+
require "yaml"
|
4
|
+
require "foreman/engine"
|
3
5
|
|
4
6
|
class Mason::Buildpack
|
5
7
|
|
@@ -24,31 +26,61 @@ class Mason::Buildpack
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
|
-
def compile(app)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
29
|
+
def compile(app, env_file=nil, cache=nil)
|
30
|
+
cache_dir = cache || "#{app}/.git/cache"
|
31
|
+
puts " caching in #{cache_dir}"
|
32
|
+
compile_dir = Dir.mktmpdir
|
33
|
+
FileUtils.rm_rf compile_dir
|
34
|
+
FileUtils.cp_r app, compile_dir, :preserve => true
|
35
|
+
FileUtils.mkdir_p cache_dir
|
36
|
+
Dir.chdir(compile_dir) do
|
37
|
+
IO.popen(%{ #{script("compile")} "#{compile_dir}" "#{cache_dir}" }) do |io|
|
38
|
+
until io.eof?
|
39
|
+
data = io.gets
|
40
|
+
data.gsub!(/^-----> /, " + ")
|
41
|
+
data.gsub!(/^ /, " ")
|
42
|
+
data.gsub!(/^\s+\!\s+$/, "")
|
43
|
+
data.gsub!(/^\s+\!\s+/, " ! ")
|
44
|
+
data.gsub!(/^\s+$/, "")
|
45
|
+
print data
|
43
46
|
end
|
44
|
-
raise "compile failed" unless $?.exitstatus.zero?
|
45
47
|
end
|
46
|
-
|
48
|
+
raise "compile failed" unless $?.exitstatus.zero?
|
47
49
|
end
|
50
|
+
release = YAML.load(`#{script('release')}`)
|
51
|
+
write_env(compile_dir, release, env_file)
|
52
|
+
write_procfile(compile_dir, release)
|
53
|
+
compile_dir
|
48
54
|
end
|
49
55
|
|
50
56
|
private
|
51
57
|
|
58
|
+
def write_env(compile_dir, release, env_file)
|
59
|
+
env = env_file ? Foreman::Engine.read_environment(env_file) : {}
|
60
|
+
config = release["config_vars"].merge(env)
|
61
|
+
|
62
|
+
File.open(File.join(compile_dir, ".env"), "w") do |f|
|
63
|
+
f.puts config.map{|k, v| "#{k}=#{v}"}.join("\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def write_procfile(compile_dir, release)
|
68
|
+
filename = File.join(compile_dir, "Procfile")
|
69
|
+
process_types = release["default_process_types"] || {}
|
70
|
+
|
71
|
+
if File.exists? filename
|
72
|
+
Foreman::Procfile.new(filename).entries.each do |e|
|
73
|
+
process_types[e.name] = e.command
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
File.open(filename, "w") do |f|
|
78
|
+
process_types.each do |name, command|
|
79
|
+
f.puts "#{name}: #{command}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
52
84
|
def mkchtmpdir
|
53
85
|
ret = nil
|
54
86
|
Dir.mktmpdir do |dir|
|
@@ -62,6 +94,5 @@ private
|
|
62
94
|
def script(name)
|
63
95
|
File.join(dir, "bin", name)
|
64
96
|
end
|
65
|
-
|
66
97
|
end
|
67
98
|
|
data/lib/mason/buildpacks.rb
CHANGED
@@ -2,18 +2,31 @@ require "fileutils"
|
|
2
2
|
require "mason"
|
3
3
|
require "mason/buildpack"
|
4
4
|
require "uri"
|
5
|
+
require "digest/sha1"
|
5
6
|
|
6
7
|
class Mason::Buildpacks
|
7
8
|
|
8
|
-
def self.install(url)
|
9
|
-
|
9
|
+
def self.install(url, ad_hoc=false)
|
10
|
+
root_dir = ad_hoc ? ad_hoc_root : root
|
11
|
+
FileUtils.mkdir_p root_dir
|
10
12
|
|
11
|
-
Dir.chdir(
|
12
|
-
|
13
|
+
Dir.chdir(root_dir) do
|
14
|
+
uri = URI.parse(url)
|
15
|
+
if uri.path =~ /buildpack-(\w+)/
|
13
16
|
name = $1
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
name += "-#{Digest::SHA1.hexdigest(url).to_s[0 .. 8]}" if ad_hoc
|
18
|
+
branch = uri.fragment || "master"
|
19
|
+
if File.exists?(name)
|
20
|
+
# Can't do a fetch here as it won't update local branches
|
21
|
+
system "cd #{name} && git checkout master && git pull"
|
22
|
+
raise "failed to update buildpack checkout" unless $?.exitstatus.zero?
|
23
|
+
else
|
24
|
+
system "git clone #{url.split('#').first} #{name} >/dev/null 2>&1"
|
25
|
+
raise "failed to clone buildpack" unless $?.exitstatus.zero?
|
26
|
+
end
|
27
|
+
system "cd #{name} && git checkout #{branch} 2> /dev/null"
|
28
|
+
raise "failed to check out branch #{branch}" unless $?.exitstatus.zero?
|
29
|
+
File.expand_path(root_dir + "/" + name)
|
17
30
|
else
|
18
31
|
raise "BUILDPACK should be a url containing buildpack-NAME.git"
|
19
32
|
end
|
@@ -27,11 +40,16 @@ class Mason::Buildpacks
|
|
27
40
|
end
|
28
41
|
end
|
29
42
|
|
30
|
-
def self.root(expand=true)
|
43
|
+
def self.root(ad_hoc=false, expand=true)
|
31
44
|
dir = "~/.mason/buildpacks"
|
32
45
|
expand ? File.expand_path(dir) : dir
|
33
46
|
end
|
34
47
|
|
48
|
+
def self.ad_hoc_root(expand=true)
|
49
|
+
dir = "~/.mason/buildpacks-ad-hoc"
|
50
|
+
expand ? File.expand_path(dir) : dir
|
51
|
+
end
|
52
|
+
|
35
53
|
def self.buildpacks
|
36
54
|
@buildpacks ||= begin
|
37
55
|
Dir[File.join(root, "*")].map do |buildpack_dir|
|
@@ -40,10 +58,16 @@ class Mason::Buildpacks
|
|
40
58
|
end
|
41
59
|
end
|
42
60
|
|
43
|
-
def self.detect(app)
|
44
|
-
|
45
|
-
|
46
|
-
|
61
|
+
def self.detect(app, buildpack_url)
|
62
|
+
if buildpack_url
|
63
|
+
puts "Using $BUILDPACK_URL: #{buildpack_url}"
|
64
|
+
buildpack_dir = install(buildpack_url, true)
|
65
|
+
return Mason::Buildpack.new(buildpack_dir)
|
66
|
+
else
|
67
|
+
buildpacks.each do |buildpack|
|
68
|
+
ret = buildpack.detect(app)
|
69
|
+
return [buildpack, ret] if ret
|
70
|
+
end
|
47
71
|
end
|
48
72
|
nil
|
49
73
|
end
|
data/lib/mason/cli.rb
CHANGED
@@ -25,6 +25,8 @@ class Mason::CLI < Thor
|
|
25
25
|
method_option :quiet, :type => :boolean, :aliases => "-q", :desc => "quiet packaging output"
|
26
26
|
method_option :stack, :type => :string, :aliases => "-s", :desc => "use a stack for building"
|
27
27
|
method_option :type, :type => :string, :aliases => "-t", :desc => "output type (dir, img, tgz)"
|
28
|
+
method_option :env_file, :type => :string, :aliases => "-e", :desc => "config environment file"
|
29
|
+
method_option :cache, :type => :string, :aliases => "-c", :desc => "cache directory"
|
28
30
|
|
29
31
|
def build(app)
|
30
32
|
app = File.expand_path(app)
|
@@ -57,9 +59,11 @@ class Mason::CLI < Thor
|
|
57
59
|
FileUtils.rm_rf compile_dir
|
58
60
|
FileUtils.rm_rf mason_dir
|
59
61
|
|
60
|
-
FileUtils.cp_r
|
61
|
-
|
62
|
-
FileUtils.cp_r
|
62
|
+
FileUtils.cp_r(File.expand_path("~/.mason/buildpacks"), buildpacks_dir,
|
63
|
+
:preserve => true)
|
64
|
+
FileUtils.cp_r(File.expand_path("../../../", __FILE__), mason_dir,
|
65
|
+
:preserve => true)
|
66
|
+
FileUtils.cp_r(app, compile_dir, :preserve => true)
|
63
67
|
|
64
68
|
mason_args = %{ /share/app -q -o /share/output -t #{type} }
|
65
69
|
mason_args += %{ -b "#{options[:buildpack]}" } if options[:buildpack]
|
@@ -70,7 +74,8 @@ class Mason::CLI < Thor
|
|
70
74
|
COMMAND
|
71
75
|
|
72
76
|
FileUrils.rm_rf output
|
73
|
-
FileUtils.cp_r
|
77
|
+
FileUtils.cp_r(File.expand_path("~/.mason/share/#{stack}/output"), output,
|
78
|
+
:preserve => true)
|
74
79
|
|
75
80
|
puts "* packaging"
|
76
81
|
puts " = type: #{type}"
|
@@ -78,7 +83,8 @@ class Mason::CLI < Thor
|
|
78
83
|
else
|
79
84
|
print "* detecting buildpack... "
|
80
85
|
|
81
|
-
|
86
|
+
buildpack_url = ENV["BUILDPACK_URL"] || options[:buildpack]
|
87
|
+
buildpack, ret = Mason::Buildpacks.detect(app, buildpack_url)
|
82
88
|
raise "no valid buildpack detected" unless buildpack
|
83
89
|
|
84
90
|
puts "done"
|
@@ -87,7 +93,7 @@ class Mason::CLI < Thor
|
|
87
93
|
puts " = display: #{ret}"
|
88
94
|
|
89
95
|
puts "* compiling..."
|
90
|
-
compile_dir = buildpack.compile(app)
|
96
|
+
compile_dir = buildpack.compile(app, options[:env_file], options[:cache])
|
91
97
|
|
92
98
|
print "* packaging... " unless options[:quiet]
|
93
99
|
case type.to_sym
|
@@ -99,7 +105,7 @@ class Mason::CLI < Thor
|
|
99
105
|
raise "img not supported yet"
|
100
106
|
when :dir then
|
101
107
|
FileUtils.rm_rf output
|
102
|
-
FileUtils.cp_r compile_dir, output
|
108
|
+
FileUtils.cp_r compile_dir, output, :preserve => true
|
103
109
|
else
|
104
110
|
raise "no such output type: #{type}"
|
105
111
|
end
|
data/lib/mason/version.rb
CHANGED
metadata
CHANGED
@@ -1,65 +1,84 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mason
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 12
|
9
|
+
version: 0.0.12
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- David Dollar
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2012-04-25 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: thor
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
22
31
|
type: :runtime
|
23
|
-
|
24
|
-
version_requirements: *70257394090020
|
32
|
+
version_requirements: *id001
|
25
33
|
description: Build things
|
26
34
|
email: ddollar@gmail.com
|
27
|
-
executables:
|
35
|
+
executables:
|
28
36
|
- mason
|
29
37
|
extensions: []
|
38
|
+
|
30
39
|
extra_rdoc_files: []
|
31
|
-
|
40
|
+
|
41
|
+
files:
|
42
|
+
- README.md
|
32
43
|
- bin/mason
|
33
44
|
- data/Vagrantfile.template
|
34
|
-
- lib/mason/buildpack.rb
|
35
45
|
- lib/mason/buildpacks.rb
|
46
|
+
- lib/mason/version.rb
|
36
47
|
- lib/mason/cli.rb
|
48
|
+
- lib/mason/buildpack.rb
|
37
49
|
- lib/mason/stacks.rb
|
38
|
-
- lib/mason/version.rb
|
39
50
|
- lib/mason.rb
|
40
|
-
|
51
|
+
has_rdoc: true
|
41
52
|
homepage: http://github.com/ddollar/mason
|
42
53
|
licenses: []
|
54
|
+
|
43
55
|
post_install_message:
|
44
56
|
rdoc_options: []
|
45
|
-
|
57
|
+
|
58
|
+
require_paths:
|
46
59
|
- lib
|
47
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
61
|
none: false
|
49
|
-
requirements:
|
50
|
-
- -
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
|
53
|
-
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
69
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
59
76
|
requirements: []
|
77
|
+
|
60
78
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.3.7
|
62
80
|
signing_key:
|
63
81
|
specification_version: 3
|
64
82
|
summary: Build things
|
65
83
|
test_files: []
|
84
|
+
|