homebrew-core/Formula/influxdb.rb

122 lines
4.6 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.4.0",
revision: "de247bab083df4685b2dab80ae46deea011d5898"
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_monterey: "db22b105ab998ff364051eacc776adc4d49de0db6f52dc85e7f28880c8222321"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "c372a548c2b6ce6a7a13afaa973822ee98eb28d197ae8f54348fc68ee922730f"
sha256 cellar: :any_skip_relocation, monterey: "10307a760946f0892ccf0331672c7db3b9aea9a072e7fac81a112c3bc435f38c"
sha256 cellar: :any_skip_relocation, big_sur: "4bd629ca097cbbf05e8e130cea8942fc85920ada57b45a1bf0ab142786343dfe"
sha256 cellar: :any_skip_relocation, catalina: "c3d3e4cd0aad3b2f65f435daf06be46b23425dbda901b7f05e438aa1967c1daf"
sha256 cellar: :any_skip_relocation, x86_64_linux: "77eceb1881244c0e4231c6ab73937278bde4b2706bee9e7d37a3ddf03a3d3b7f"
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-Master/build.tar.gz"
sha256 "60a0e9d632f2a389fe61378c69697c7613782ebdc7f055d5eecb49de9df315ef"
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