homebrew-core/Formula/grafana.rb

115 lines
3.6 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/v9.2.1.tar.gz"
sha256 "1f220daf3ba97ae00ef17d1ab1a4397eb70b8cb67425d4d42db0bada91cd9233"
license "AGPL-3.0-only"
head "https://github.com/grafana/grafana.git", branch: "main"
bottle do
sha256 cellar: :any_skip_relocation, arm64_ventura: "44a144161f0e07b2ace0f47cb0383aa68d82784e101e3835dae13f0073c5e9e1"
sha256 cellar: :any_skip_relocation, arm64_monterey: "14dd3c7d452008c922f9a4d626d5c569c51f38cd17ce3d316e477a9433cecdf3"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "81b0690aac19beb815ddf1679818fc170dcae27e06182daaf3711c119f7cdf87"
sha256 cellar: :any_skip_relocation, monterey: "dbf70c40104c5574520257d4aca780794b7f1241aff67d6e0e4afe79276bd217"
sha256 cellar: :any_skip_relocation, big_sur: "70a518e5606670df460d4f1be0eb71075a99f6b1a7d7b222e3518cbaefa03d5a"
sha256 cellar: :any_skip_relocation, catalina: "b1ceabf5c81b5a42814912b1cdf47393928187364be879c87e970244a686d5f5"
sha256 cellar: :any_skip_relocation, x86_64_linux: "8e2d83851c502d109e84d4f22672f5a28564f14cf4f0f03eae713e062d17e530"
end
depends_on "go" => :build
depends_on "node@16" => :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=8000"
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