homebrew-core/Formula/influxdb.rb

118 lines
4.4 KiB
Ruby

class Influxdb < Formula
desc "Time series, events, and metrics database"
homepage "https://influxdata.com/time-series-platform/influxdb/"
url "https://github.com/influxdata/influxdb.git",
tag: "v2.0.9",
revision: "d1233b7951ddf06a3f201c84f4b0915692c22ba5"
license "MIT"
head "https://github.com/influxdata/influxdb.git", branch: "master"
# The regex below omits a rogue `v9.9.9` tag that breaks version comparison.
livecheck do
url :stable
regex(/^v?((?!9\.9\.9)\d+(?:\.\d+)+)$/i)
end
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "ccfa24843aad6447e354fe0aa8d912fcce1ac756176c71112acf9870bda2846a"
sha256 cellar: :any_skip_relocation, big_sur: "8c1ad0349a2b4d7b0943bca30fd68e8f1effb2c97d968b7c765ed47198f8bac2"
sha256 cellar: :any_skip_relocation, catalina: "b2f81367128aa3f5a6c433837e55bbe7d3680cebe6f476207b25a6d309571ad3"
sha256 cellar: :any_skip_relocation, mojave: "79a485ca7cdf37b3c11ae7405501857fcfda1df0c2c9945350384dc766344ea2"
end
depends_on "breezy" => :build
depends_on "go" => :build
depends_on "pkg-config" => :build
depends_on "protobuf" => :build
depends_on "rust" => :build
depends_on "influxdb-cli"
# NOTE: The version here is specified in the go.mod of influxdb.
# If you're upgrading to a newer influxdb version, check to see if this needs upgraded too.
resource "pkg-config-wrapper" do
url "https://github.com/influxdata/pkg-config/archive/refs/tags/v0.2.8.tar.gz"
sha256 "9d3f3bbcac7c787f6e8846e70172d06bd4d7394b4bcd0b8572fe2f1d03edc11b"
end
# NOTE: The version/URL here is specified in scripts/fetch-ui-assets.sh in influxdb.
# If you're upgrading to a newer influxdb version, check to see if this needs upgraded too.
resource "ui-assets" do
url "https://github.com/influxdata/ui/releases/download/OSS-v2.0.9/build.tar.gz"
sha256 "ace380b5bd6abef9aa0ca16e95900052b9520399a7b3311a0c366a5d98ad400d"
end
def install
# Set up the influxdata pkg-config wrapper to enable just-in-time compilation & linking
# of the Rust components in the server.
resource("pkg-config-wrapper").stage do
system "go", "build", *std_go_args, "-o", buildpath/"bootstrap/pkg-config"
end
ENV.prepend_path "PATH", buildpath/"bootstrap"
# Extract pre-build UI resources to the location expected by go-bindata.
resource("ui-assets").stage(buildpath/"static/data/build")
# Embed UI files into the Go source code.
system "make", "generate-web-assets"
# Build the server.
ldflags = %W[
-s
-w
-X main.version=#{version}
-X main.commit=#{Utils.git_short_head(length: 10)}
-X main.date=#{time.iso8601}
].join(" ")
system "go", "build", *std_go_args(ldflags: ldflags),
"-tags", "assets", "-o", bin/"influxd", "./cmd/influxd"
data = var/"lib/influxdb2"
data.mkpath
# Generate default config file.
config = buildpath/"config.yml"
config.write Utils.safe_popen_read(bin/"influxd", "print-config",
"--bolt-path=#{data}/influxdb.bolt",
"--engine-path=#{data}/engine")
(etc/"influxdb2").install config
# Create directory for DB stdout+stderr logs.
(var/"log/influxdb2").mkpath
end
service do
run bin/"influxd"
keep_alive true
working_dir HOMEBREW_PREFIX
log_path var/"log/influxdb2/influxd_output.log"
error_log_path var/"log/influxdb2/influxd_output.log"
environment_variables INFLUXD_CONFIG_PATH: etc/"influxdb2/config.yml"
end
test do
influxd_port = free_port
influx_host = "http://localhost:#{influxd_port}"
ENV["INFLUX_HOST"] = influx_host
influxd = fork do
exec "#{bin}/influxd", "--bolt-path=#{testpath}/influxd.bolt",
"--engine-path=#{testpath}/engine",
"--http-bind-address=:#{influxd_port}",
"--log-level=error"
end
sleep 30
# Check that the CLI works and can talk to the server.
assert_match "OK", shell_output("influx ping")
# Check that the server has properly bundled UI assets and serves them as HTML.
curl_output = shell_output("curl --silent --head #{influx_host}")
assert_match "200 OK", curl_output
assert_match "text/html", curl_output
ensure
Process.kill("TERM", influxd)
Process.wait influxd
end
end