homebrew-core/Formula/influxdb.rb

119 lines
4.5 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.1.1",
revision: "657e1839de9e8a734abad1207ca28e7d02444207"
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: "7de2e0f730864bf4db5f3af35533d5b8d462def4013cebc1dd9991fab1b59d83"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "42c89aa4f7c843b8f99ac406d42d822505ec9cf6d0ecb38d7ce4217f000ee165"
sha256 cellar: :any_skip_relocation, monterey: "371081fed5b98ae9fbb03fee57ce016cb29d39796a35dc9b57bfe0fb8030681b"
sha256 cellar: :any_skip_relocation, big_sur: "2ffa689372e99aff4f2366eded763e59d2f1fb9c09f14cfe37ab6fc2cccbcc72"
sha256 cellar: :any_skip_relocation, catalina: "23711126f0cb3c7b89bf68a9f933aec3be44d86cd88ebdd80079bc841c9b5728"
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.9.tar.gz"
sha256 "25843e58a3e6994bdafffbc0ef0844978a3d1f999915d6770cb73505fcf87e44"
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
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