homebrew-core/Formula/influxdb.rb

124 lines
4.9 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.5.1",
revision: "5b6fdbf05dbd196471801927c19d66d071cc1775"
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_ventura: "fa8ec30e24ac9791a912870092ca5fa7c55e6c6a5396680085009d7b29434306"
sha256 cellar: :any_skip_relocation, arm64_monterey: "b520c3e4b34e493e5eed283883a4cada2bea1c65ae9bd5495f5df7cda154a684"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "e912e334f0883c403aa636f010779d36d3c85d045f05a659a30a6012096b8607"
sha256 cellar: :any_skip_relocation, ventura: "50b4344e4b7d62fe5fda2fc917b752b0c820f6de49bb69a43defc8bd099c0bfb"
sha256 cellar: :any_skip_relocation, monterey: "503e38fe42235fd4c1e4fa4e30faae4b5d5b7eac5f36c8bab563bf0a0e4ce960"
sha256 cellar: :any_skip_relocation, big_sur: "da8626163a57bb579c2d07bcd1f9787a748f63cbe28beca1659d30bb417b788b"
sha256 cellar: :any_skip_relocation, catalina: "3bb91162e3de58ce23d0b07b9179d3d60ab0bc339316be94560837a163585205"
sha256 cellar: :any_skip_relocation, x86_64_linux: "c049abe021d340753e9a4d6690138d83a721064762b8617349e02748c251024c"
end
depends_on "breezy" => :build
depends_on "go" => :build
depends_on "pkg-config" => :build
depends_on "protobuf" => :build
depends_on "rust" => :build
# 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.11.tar.gz"
sha256 "52b22c151163dfb051fd44e7d103fc4cde6ae8ff852ffc13adeef19d21c36682"
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-2022-09-16/build.tar.gz"
sha256 "3dd9da2a12a5644febff519d5d5a45eaf54dea476613aa20e79596aab31fe715"
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(output: 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}
]
system "go", "build", *std_go_args(output: bin/"influxd", ldflags: ldflags),
"-tags", "assets,sqlite_foreign_keys,sqlite_json", "./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
def caveats
<<~EOS
This formula does not contain command-line interface; to install it, run:
brew install influxdb-cli
EOS
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 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