homebrew-core/Formula/caddy.rb

87 lines
2.6 KiB
Ruby

class Caddy < Formula
desc "Powerful, enterprise-ready, open source web server with automatic HTTPS"
homepage "https://caddyserver.com/"
url "https://github.com/caddyserver/caddy/archive/v2.2.1.tar.gz"
sha256 "dd1f313968a54c3e6be9b5d007b8b2ed88c46fbefc1eed49dcac35c08fbef1e2"
license "Apache-2.0"
head "https://github.com/caddyserver/caddy.git"
bottle do
cellar :any_skip_relocation
sha256 "6fe2b49e1ed11f60247932bae0f56db205844174eb5e7f9733bcabcd2a8656a5" => :catalina
sha256 "1249e2364e8464f955f5bc444aafa7546e9db601d5cdeeaa8f6cc738dbb94acc" => :mojave
sha256 "5322bd55245c5ba434837edea091008d696a1042f332dbd68b0244899d7d1011" => :high_sierra
end
depends_on "go" => :build
resource "xcaddy" do
url "https://github.com/caddyserver/xcaddy/archive/v0.1.5.tar.gz"
sha256 "eb84bf79f5cb5b64d6929a88d2082d3fdafabd928c862c122a385b0d4c68284c"
end
def install
revision = build.head? ? version.commit : "v#{version}"
resource("xcaddy").stage do
system "go", "run", "cmd/xcaddy/main.go", "build", revision, "--output", bin/"caddy"
end
end
plist_options manual: "caddy run --config #{HOMEBREW_PREFIX}/etc/Caddyfile"
def plist
<<~EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/caddy</string>
<string>run</string>
<string>--config</string>
<string>#{etc}/Caddyfile</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>#{var}/log/caddy.log</string>
<key>StandardErrorPath</key>
<string>#{var}/log/caddy.log</string>
</dict>
</plist>
EOS
end
test do
port1 = free_port
port2 = free_port
(testpath/"Caddyfile").write <<~EOS
{
admin 127.0.0.1:#{port1}
}
http://127.0.0.1:#{port2} {
respond "Hello, Caddy!"
}
EOS
fork do
exec bin/"caddy", "run", "--config", testpath/"Caddyfile"
end
sleep 2
assert_match "\":#{port2}\"",
shell_output("curl -s http://127.0.0.1:#{port1}/config/apps/http/servers/srv0/listen/0")
assert_match "Hello, Caddy!", shell_output("curl -s http://127.0.0.1:#{port2}")
assert_match version.to_s, shell_output("#{bin}/caddy version")
end
end