class Traefik < Formula desc "Modern reverse proxy" homepage "https://traefik.io/" url "https://github.com/containous/traefik/releases/download/v2.0.5/traefik-v2.0.5.src.tar.gz" version "2.0.5" sha256 "070a22f9c4e48e852499fc773b0b6a96a395a98b2d130bc6e1fbeb2949f79acc" head "https://github.com/containous/traefik.git" bottle do cellar :any_skip_relocation sha256 "bb5f734088ccc1f79c4e698b8ec4671a1882eb628800feefa00aa8ed30b0592b" => :catalina sha256 "242e2f82f04851382ab33a5d58ed2a9e9fc458955cf361570513b3b410748bf7" => :mojave sha256 "60d2307e5eaa7c12b485040537a71c8ba45585a1bfca9d56369d681616919695" => :high_sierra end depends_on "go" => :build depends_on "go-bindata" => :build def install ENV["GOPATH"] = buildpath (buildpath/"src/github.com/containous/traefik").install buildpath.children cd "src/github.com/containous/traefik" do system "go", "generate" system "go", "build", "-o", bin/"traefik", "./cmd/traefik" prefix.install_metafiles end end plist_options :manual => "traefik" def plist <<~EOS KeepAlive Label #{plist_name} ProgramArguments #{opt_bin}/traefik --configfile=#{etc/"traefik/traefik.toml"} EnvironmentVariables RunAtLoad WorkingDirectory #{var} StandardErrorPath #{var}/log/traefik.log StandardOutPath #{var}/log/traefik.log EOS end test do require "socket" ui_server = TCPServer.new(0) http_server = TCPServer.new(0) ui_port = ui_server.addr[1] http_port = http_server.addr[1] ui_server.close http_server.close (testpath/"traefik.toml").write <<~EOS [global] checkNewVersion = false sendAnonymousUsage = false [serversTransport] insecureSkipVerify = true [entryPoints] [entryPoints.http] address = ":#{http_port}" [entryPoints.traefik] address = ":#{ui_port}" [log] level = "ERROR" format = "common" [accessLog] format = "common" [api] insecure = true dashboard = true debug = true EOS begin pid = fork do exec bin/"traefik", "--configfile=#{testpath}/traefik.toml" end sleep 5 cmd_http = "curl -sIm3 -XGET http://localhost:#{http_port}/" assert_match /404 Not Found/m, shell_output(cmd_http) sleep 1 cmd_ui = "curl -sIm3 -XGET http://localhost:#{ui_port}/dashboard/" assert_match /200 OK/m, shell_output(cmd_ui) ensure Process.kill("HUP", pid) end end end