homebrew-core/Formula/grafana.rb

115 lines
3.5 KiB
Ruby

class Grafana < Formula
desc "Gorgeous metric visualizations and dashboards for timeseries databases"
homepage "https://grafana.com"
url "https://github.com/grafana/grafana/archive/v8.3.4.tar.gz"
sha256 "5cbbb7dd8a7a7717e8d4aa2b3a9a3ed27825e8a11d68f00da0eb36ab8002ff09"
license "AGPL-3.0-only"
head "https://github.com/grafana/grafana.git", branch: "main"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "714f8b948fd98b01264304287b90b3cd1f0b6930debc0ea025a1c69d1c3eba08"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "6a2c395ea63685a7f22fcd5e781ac43c8bc2a9c7178647c79ebce1411a4483a7"
sha256 cellar: :any_skip_relocation, monterey: "5bc850531bca43178b31bc28284ce1b400b4ae10a4c4375d9f8421a18bead986"
sha256 cellar: :any_skip_relocation, big_sur: "b79a2571ff6aa78d5cece16489f3dd95416750ef65edb067d8217d9f55d166dc"
sha256 cellar: :any_skip_relocation, catalina: "c65dea8f526db0befff0f15a0ded433060ad3996c5feaa72d029db418dc45850"
sha256 cellar: :any_skip_relocation, x86_64_linux: "e1c555a72c7e19f8c4859b469ab6350cf11ed1b7699944df5d766fa8e2e78d36"
end
depends_on "go" => :build
depends_on "node" => :build
depends_on "yarn" => :build
uses_from_macos "zlib"
on_linux do
depends_on "fontconfig"
depends_on "freetype"
end
def install
ENV["NODE_OPTIONS"] = "--max-old-space-size=4096"
system "make", "gen-go"
system "go", "run", "build.go", "build"
system "yarn", "install"
system "yarn", "build"
if OS.mac?
bin.install Dir["bin/darwin-*/grafana-cli"]
bin.install Dir["bin/darwin-*/grafana-server"]
else
bin.install "bin/linux-amd64/grafana-cli"
bin.install "bin/linux-amd64/grafana-server"
end
(etc/"grafana").mkpath
cp("conf/sample.ini", "conf/grafana.ini.example")
etc.install "conf/sample.ini" => "grafana/grafana.ini"
etc.install "conf/grafana.ini.example" => "grafana/grafana.ini.example"
pkgshare.install "conf", "public", "tools"
end
def post_install
(var/"log/grafana").mkpath
(var/"lib/grafana/plugins").mkpath
end
service do
run [opt_bin/"grafana-server",
"--config", etc/"grafana/grafana.ini",
"--homepath", opt_pkgshare,
"--packaging=brew",
"cfg:default.paths.logs=#{var}/log/grafana",
"cfg:default.paths.data=#{var}/lib/grafana",
"cfg:default.paths.plugins=#{var}/lib/grafana/plugins"]
keep_alive true
error_log_path var/"log/grafana-stderr.log"
log_path var/"log/grafana-stdout.log"
working_dir var/"lib/grafana"
end
test do
require "pty"
require "timeout"
# first test
system bin/"grafana-server", "-v"
# avoid stepping on anything that may be present in this directory
tdir = File.join(Dir.pwd, "grafana-test")
Dir.mkdir(tdir)
logdir = File.join(tdir, "log")
datadir = File.join(tdir, "data")
plugdir = File.join(tdir, "plugins")
[logdir, datadir, plugdir].each do |d|
Dir.mkdir(d)
end
Dir.chdir(pkgshare)
res = PTY.spawn(bin/"grafana-server",
"cfg:default.paths.logs=#{logdir}",
"cfg:default.paths.data=#{datadir}",
"cfg:default.paths.plugins=#{plugdir}",
"cfg:default.server.http_port=50100")
r = res[0]
w = res[1]
pid = res[2]
listening = Timeout.timeout(10) do
li = false
r.each do |l|
if /HTTP Server Listen/.match?(l)
li = true
break
end
end
li
end
Process.kill("TERM", pid)
w.close
r.close
listening
end
end