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.2.0",
revision: "a2f85388377fe454257b6da6ad1e723e52b5438b"
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: "413f77a266d349110b0f3dd6d31b3b8d504aca072e42700a786f78409ee0c29d"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "fc3011b138388f8fc7b3c7a26ffcb69b0984c76ae887b2a9aaa96df2d48ffc63"
sha256 cellar: :any_skip_relocation, monterey: "5a9344498c796383d0ac7f99ab7b23daa6b215f71275734d52459abe98831ebd"
sha256 cellar: :any_skip_relocation, big_sur: "fac54d7d0332e8c8a7dc457f1ad2696ab1af0afbf807da07639448a61475fa48"
sha256 cellar: :any_skip_relocation, catalina: "dee85db3544e4ab2dbd8ae022d8dfe8318e355d8ffa180cd54adcceda16624fd"
sha256 cellar: :any_skip_relocation, x86_64_linux: "0de0b0c00c70d8edf7add72aee60cd05fda3201f808810a5001bdf2a9a9ecde8"
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-2.1.2/build.tar.gz"
sha256 "7d78d284d25f28dfd940d407a17f7f3aee1706b5dabc237eadc3bef0031ce548"
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