Skip to content

Instantly share code, notes, and snippets.

@ctdk ctdk/grafana.rb
Created Apr 22, 2016

Embed
What would you like to do?
grafana formula, in progress
require "language/go"
class Grafana < Formula
desc "Gorgeous metric viz, dashboards & editors for Graphite, InfluxDB & OpenTSDB."
homepage "https://grafana.org"
url "https://github.com/grafana/grafana/archive/v3.0-beta5.tar.gz"
version "3.0-beta5"
sha256 "db9fcc0f4d90236d0cdaba2ab1ddd06bc59264aff93ead5c3a1b680804c8f8cd"
head "https://github.com/grafana/grafana.git"
depends_on "go" => :build
depends_on "nodejs" => :build
def install
ENV.prepend_path "PATH", "#{Formula["node"].opt_libexec}/npm/bin"
ENV["GOPATH"] = buildpath
grafana_path = buildpath/"src/github.com/grafana/grafana"
grafana_path.install Dir["*"]
grafana_path.install ".jscs.json", ".jsfmtrc", ".jshintrc", ".bowerrc"
Language::Go.stage_deps resources, buildpath/"src"
cd grafana_path do
# Might do it differently for head vs. release
system "go", "run", "build.go", "setup"
system buildpath/"bin/godep", "restore"
#(buildpath/"src/github.com/grafana").mkpath
#FileUtils.ln_s buildpath, grafana_path
system "go", "run", "build.go", "build"
system "npm", "install"
system "npm", "install", "grunt-cli"
#system "node_modules/grunt-cli/bin/grunt"
end
bin.install grafana_path/"bin/grafana-cli"
bin.install grafana_path/"bin/grafana-server"
(etc/"grafana").mkpath
(var/"lib/grafana").mkpath
(share/"grafana").mkpath
(share/"grafana").install Dir["conf", "public", "vendor"]
etc.install grafana_path/"conf/sample.ini" => "grafana/grafana.ini"
end
test do
# `test do` will create, run in and delete a temporary directory.
#
# This test will fail and we won't accept that! It's enough to just replace
# "false" with the main program this formula installs, but it'd be nice if you
# were more thorough. Run the test with `brew test grafana`. Options passed
# to `brew install` such as `--HEAD` also need to be provided to `brew test`.
#
# The installed folder is not in the path, so use the entire path to any
# executables being tested: `system "#{bin}/program", "do", "something"`.
system "false"
end
end
@torkelo

This comment has been minimized.

Copy link

commented Apr 22, 2016

system buildpath/"bin/godep", "restore" should not be needed as go run build.go build will add the checked in godeps_workspace to the GOPATH

@torkelo

This comment has been minimized.

Copy link

commented Apr 22, 2016

system "node_modules/grunt-cli/bin/grunt" this should called with the argument "build" (that is grunt build) , so a an optimized build is generated ,

system "node_modules/grunt-cli/bin/grunt", "build"

we might need a grafana-server start script, similar to an initd script for linux, that sets the correct paths.
grafana-server
--config=${CONF_FILE}
--pidfile=${PID_FILE}
cfg:default.paths.logs=${LOG_DIR}
cfg:default.paths.data=${DATA_DIR}
cfg:default.paths.plugins=${PLUGINS_DIR}

@ctdk

This comment has been minimized.

Copy link
Owner Author

commented Apr 22, 2016

(Also grunt shouldn't be commented out, obviously; that was from when the grunt stuff was blowing up.)

I was cribbing from the README, so that's why those steps are that way. I'll adjust accordingly and see how it goes.

For the start script, I was going to try adding just a plist (like influxdb has at https://github.com/Homebrew/legacy-homebrew/blob/master/Library/Formula/influxdb.rb (scroll down)), but it may be necessary to have an additional wrapper to get the right working directory.

@torkelo

This comment has been minimized.

Copy link

commented Apr 22, 2016

not sure what a plist list, but as long as it starts grafana-server with some options for config file and
cfg:default.paths.logs=${LOG_DIR}
cfg:default.paths.data=${DATA_DIR}
cfg:default.paths.plugins=${PLUGINS_DIR}

it should work fine

@ctdk

This comment has been minimized.

Copy link
Owner Author

commented Apr 22, 2016

A plist is launchctl's init config, basically. It should be fine, assuming (which seems likely) that it can chdir to /usr/local/share/grafana.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.