homebrew-core/Formula/packer.rb

95 lines
2.8 KiB
Ruby

require "language/go"
class Packer < Formula
desc "Tool for creating identical machine images for multiple platforms"
homepage "https://packer.io"
url "https://github.com/mitchellh/packer.git",
:tag => "v0.10.2",
:revision => "fb1c968d573f2a6b65af1d0b14a892d730dd7778"
bottle do
cellar :any_skip_relocation
sha256 "ba6e462887a2a2caa26450e71eb59bcb64280a87dd866485c024dc861d8c60b8" => :sierra
sha256 "b7ce3f2f0e15e6564f49a57267d2f476cd78cc4d19f857c2a4750104525f3a86" => :el_capitan
sha256 "8c9ba1723e40fa621f06358fa0dd90e5fa3ff07fbe801126e214db15c5dac611" => :yosemite
end
depends_on :hg => :build
depends_on "go" => :build
go_resource "github.com/mitchellh/gox" do
url "https://github.com/mitchellh/gox.git",
:revision => "c9740af9c6574448fd48eb30a71f964014c7a837"
end
go_resource "github.com/mitchellh/iochan" do
url "https://github.com/mitchellh/iochan.git",
:revision => "87b45ffd0e9581375c491fef3d32130bb15c5bd7"
end
go_resource "golang.org/x/tools" do
url "https://go.googlesource.com/tools.git",
:revision => "3f4088edb48e8a4e3c66a5f8e7b2a78615fcb83f"
end
def install
ENV["XC_OS"] = "darwin"
ENV["XC_ARCH"] = MacOS.prefer_64_bit? ? "amd64" : "386"
ENV["GOPATH"] = buildpath
# For the gox buildtool used by packer, which
# doesn't need to be installed permanently.
ENV.append_path "PATH", buildpath
packerpath = buildpath/"src/github.com/mitchellh/packer"
packerpath.install Dir["{*,.git}"]
Language::Go.stage_deps resources, buildpath/"src"
(buildpath/"bin").mkpath
cd "src/github.com/mitchellh/gox" do
system "go", "build"
buildpath.install "gox"
end
cd "src/golang.org/x/tools/cmd/stringer" do
system "go", "build"
buildpath.install "stringer"
end
cd "src/github.com/mitchellh/packer" do
# We handle this step above. Don't repeat it.
inreplace "Makefile" do |s|
s.gsub! "go get github.com/mitchellh/gox", ""
s.gsub! "go get golang.org/x/tools/cmd/stringer", ""
end
system "make", "bin"
bin.install Dir["bin/*"]
zsh_completion.install "contrib/zsh-completion/_packer"
end
end
test do
minimal = testpath/"minimal.json"
minimal.write <<-EOS.undent
{
"builders": [{
"type": "amazon-ebs",
"region": "us-east-1",
"source_ami": "ami-59a4a230",
"instance_type": "m3.medium",
"ssh_username": "ubuntu",
"ami_name": "homebrew packer test {{timestamp}}"
}],
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"sudo apt-get update"
]
}]
}
EOS
system "#{bin}/packer", "validate", minimal
end
end