homebrew-core/Formula/traefik.rb

93 lines
2.8 KiB
Ruby

class Traefik < Formula
desc "Modern reverse proxy"
homepage "https://traefik.io/"
url "https://github.com/containous/traefik/releases/download/v2.2.1/traefik-v2.2.1.src.tar.gz"
version "2.2.1"
sha256 "71f7ec0b957c48fc6c5612cdd942879c2759af3a3a9c1b3b45f852d8b3835821"
head "https://github.com/containous/traefik.git"
bottle do
cellar :any_skip_relocation
sha256 "87ce6a068e0b31a5bf9ff83e8a2872547c1cf0eda8ee6c4e083d84a74fe55f6b" => :catalina
sha256 "696befdb36b4836bd100742dda7054beb99ab2f3b7a39a5567fdbded3832645d" => :mojave
sha256 "05cb35de1482b5407f9c78684127c13557444042d4017ca8b5115338c1035959" => :high_sierra
end
depends_on "go" => :build
depends_on "go-bindata" => :build
def install
system "go", "generate"
system "go", "build",
"-ldflags", "-s -w -X github.com/containous/traefik/v2/pkg/version.Version=#{version}",
"-trimpath", "-o", bin/"traefik", "./cmd/traefik"
prefix.install_metafiles
end
plist_options :manual => "traefik"
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>
<false/>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/traefik</string>
<string>--configfile=#{etc/"traefik/traefik.toml"}</string>
</array>
<key>EnvironmentVariables</key>
<dict>
</dict>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/traefik.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/traefik.log</string>
</dict>
</plist>
EOS
end
test do
ui_port = free_port
http_port = free_port
(testpath/"traefik.toml").write <<~EOS
[entryPoints]
[entryPoints.http]
address = ":#{http_port}"
[entryPoints.traefik]
address = ":#{ui_port}"
[api]
insecure = true
dashboard = true
EOS
begin
pid = fork do
exec bin/"traefik", "--configfile=#{testpath}/traefik.toml"
end
sleep 5
cmd_ui = "curl -sIm3 -XGET http://127.0.0.1:#{http_port}/"
assert_match /404 Not Found/m, shell_output(cmd_ui)
sleep 1
cmd_ui = "curl -sIm3 -XGET http://127.0.0.1:#{ui_port}/dashboard/"
assert_match /200 OK/m, shell_output(cmd_ui)
ensure
Process.kill(9, pid)
Process.wait(pid)
end
assert_match version.to_s, shell_output("#{bin}/traefik version 2>&1")
end
end